Skip to content

fix(openrouter): use correct X-Title header for app attribution - #50743

Closed
Mhaizza wants to merge 3 commits into
openclaw:mainfrom
Mhaizza:fix/50738-openrouter-attribution-headers
Closed

Mhaizza wants to merge 3 commits into
openclaw:mainfrom
Mhaizza:fix/50738-openrouter-attribution-headers

Conversation

@Mhaizza

@Mhaizza Mhaizza commented Mar 20, 2026

Copy link
Copy Markdown

Summary

Fixes #50738 — OpenRouter free models being charged due to incorrect attribution headers.

Problem

OpenClaw was sending:

X-OpenRouter-Title: OpenClaw
X-OpenRouter-Categories: cli-agent

But OpenRouter requires (per docs):

X-Title: OpenClaw

This caused OpenRouter to not recognize requests as coming from OpenClaw:

  • app_id: null (should be 2725608)
  • origin: "" (should be https://openclaw.ai/)
  • Free models like xiaomi/mimo-v2-pro charged at full price (~/bin/bash.22 for 11 requests)

Changes

  • ✅ Replace X-OpenRouter-Title → X-Title
  • ✅ Remove unnecessary X-OpenRouter-Categories
  • ✅ Update tests to match corrected headers

Testing

Impact

  • ✅ Free models will be correctly recognized as free for OpenClaw users
  • ✅ OpenRouter analytics will properly attribute traffic to OpenClaw

OpenClaw added 2 commits March 20, 2026 08:31
Regression introduced in 91104ac broke local vLLM endpoints that rely
on openai-responses API compatibility.

The commit narrowed Azure detection from 'isAzure' to 'isAzureOpenAi'
(*.openai.azure.com only), causing non-Azure OpenAI-compatible endpoints
to route to /v1/chat/completions instead of /responses.

This resulted in 404 errors for local vLLM setups configured with
openai-responses mode.

Fix: Revert providerApi logic to use 'isAzure' (covers both
*.services.ai.azure.com and *.openai.azure.com) to preserve backward
compatibility.

Fixes openclaw#50719
OpenRouter requires 'X-Title' header for app attribution, not
'X-OpenRouter-Title'. The incorrect header name caused OpenRouter to not
recognize requests as coming from OpenClaw, resulting in free models
(e.g., xiaomi/mimo-v2-pro) being charged at full price.

Changes:
- Replace 'X-OpenRouter-Title' with 'X-Title' per OpenRouter docs
- Remove unnecessary 'X-OpenRouter-Categories' header
- Update tests to match corrected headers

Reference: https://openrouter.ai/docs/app-attribution
Fixes openclaw#50738
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling labels Mar 20, 2026
@greptile-apps

greptile-apps Bot commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two separate issues: (1) corrects the OpenRouter app attribution header from the non-standard X-OpenRouter-Title to the documented X-Title (removing X-OpenRouter-Categories as well), which should restore free-model recognition for OpenClaw users; and (2) expands the openai-responses API selection to all Azure URLs (including Azure AI Foundry .services.ai.azure.com), not only Azure OpenAI URLs.

  • The header fix in provider-attribution.ts is correct and aligns with the OpenRouter attribution docs.
  • The Azure AI Foundry openai-responses change in onboard-custom.ts is behaviorally sound, but the now-unused isAzureOpenAi variable (line 622) is left behind as dead code — this should be removed.
  • This second Azure fix is unrelated to the PR title/description and is not called out, which may make review harder.

Confidence Score: 4/5

  • Safe to merge with a minor cleanup — the dead isAzureOpenAi variable should be removed before merging.
  • The OpenRouter header fix is straightforward and correct. The Azure change is logically sound and covered by tests. The only issue is a dead variable left in applyCustomApiConfig that may cause a lint error.
  • src/commands/onboard-custom.ts — the unused isAzureOpenAi variable at line 622 should be cleaned up.

Comments Outside Diff (1)

  1. src/commands/onboard-custom.ts, line 622 (link)

    P2 Unused variable after refactor

    After switching from isAzureOpenAi to isAzure on line 689, the isAzureOpenAi variable declared here is no longer referenced anywhere within applyCustomApiConfig. It becomes dead code and may trigger a no-unused-vars lint error. It should be removed.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/commands/onboard-custom.ts
    Line: 622
    
    Comment:
    **Unused variable after refactor**
    
    After switching from `isAzureOpenAi` to `isAzure` on line 689, the `isAzureOpenAi` variable declared here is no longer referenced anywhere within `applyCustomApiConfig`. It becomes dead code and may trigger a `no-unused-vars` lint error. It should be removed.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/commands/onboard-custom.ts
Line: 622

Comment:
**Unused variable after refactor**

After switching from `isAzureOpenAi` to `isAzure` on line 689, the `isAzureOpenAi` variable declared here is no longer referenced anywhere within `applyCustomApiConfig`. It becomes dead code and may trigger a `no-unused-vars` lint error. It should be removed.

```suggestion
  const isAzure = isAzureUrl(baseUrl);
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "fix(openrouter): use..."

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ddecd5226b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

normalizeOptionalProviderApiKey(existingApiKey);

const providerApi = isAzureOpenAi
const providerApi = isAzure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor custom compatibility for Azure Foundry providers

Switching this condition from isAzureOpenAi to isAzure makes every *.services.ai.azure.com endpoint force api: "openai-responses", so applyCustomApiConfig now ignores params.compatibility for Azure Foundry URLs. In non-interactive onboarding (--custom-compatibility anthropic) this stores the wrong transport and routes traffic to OpenAI Responses semantics instead of the selected compatibility, which can break Foundry endpoints that require Anthropic-style /messages requests.

Useful? React with 👍 / 👎.

@Mhaizza
Mhaizza marked this pull request as draft March 24, 2026 15:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4139e064a5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +689 to 691
const providerApi = isAzure
? ("openai-responses" as const)
: resolveProviderApi(params.compatibility);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Respect compatibility selection for Azure Foundry URLs

This change makes providerApi depend on isAzure instead of isAzureOpenAi, so all *.services.ai.azure.com custom providers are now saved as openai-responses and no longer honor params.compatibility. That breaks flows where users select or detect Anthropic compatibility (for example --custom-compatibility anthropic), because runtime requests will be shaped for OpenAI Responses instead of Anthropic /messages, which can fail against Foundry deployments expecting Anthropic semantics; the updated Foundry test expectation in this commit is fresh evidence that this regression is now encoded.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Closing this as implemented after Codex automated review.

Close PR #50743. Current main already sends OpenRouter attribution headers through the provider stream path, the linked #50738 was closed as implemented with the broader missing-header/auth path covered, and OpenRouter’s current docs now document X-OpenRouter-Title plus X-OpenRouter-Categories rather than requiring the PR’s X-Title replacement. The PR also includes an unrelated Azure Foundry transport change that current main explicitly avoids and tests against.

Best possible solution:

Do not merge PR #50743. Keep the shipped OpenRouter attribution implementation that uses the current documented OpenRouter headers and forwards them through the provider-owned stream path. If any new billing issue appears, open a fresh issue with live OpenRouter request/dashboard evidence; the unrelated Azure Foundry transport change should remain out of this PR and continue to be handled by the current compatibility-preserving onboarding code.

What I checked:

  • Current OpenRouter vendor contract: OpenRouter's current app-attribution docs list HTTP-Referer as required, X-OpenRouter-Title as the display-name header, X-OpenRouter-Categories as supported, and state that X-Title is still supported for backwards compatibility. That makes the PR's core claim that X-OpenRouter-Title is the wrong header obsolete.
  • OpenRouter attribution policy on current main: The OpenRouter provider attribution policy is enabled by default and defines request headers HTTP-Referer, X-OpenRouter-Title, and X-OpenRouter-Categories, matching the current vendor docs instead of the PR's X-Title replacement. (src/agents/provider-attribution.ts:400, 76cf013df507)
  • Headers are merged into request options: createOpenRouterWrapper resolves provider request policy headers and forwards the merged headers into options.headers; the adjacent regression test asserts the OpenRouter attribution headers plus a caller header reach the base stream function. (src/agents/pi-embedded-runner/proxy-stream-wrappers.ts:80, 76cf013df507)
  • Bundled OpenRouter provider uses the wrapper: The bundled OpenRouter plugin registers wrapOpenRouterProviderStream, and that wrapper delegates through the shared OpenRouter thinking stream hook so normal OpenRouter LLM calls use the header-injecting wrapper path. (extensions/openrouter/index.ts:74, 76cf013df507)
  • Broader missing-auth/header path is covered: Provider-owned stream transports inject the resolved runtime apiKey into stream options, and the regression test verifies a provider-owned stream receives apiKey: "resolved-key"; this addresses the related OpenRouter app attribution headers not sent - free models charged #50738 discussion that headers/auth were defined but not reaching the actual request path. (src/agents/pi-embedded-runner/stream-resolution.ts:88, 76cf013df507)
  • Linked issue already closed as implemented: Issue OpenRouter app attribution headers not sent - free models charged #50738, which this PR says it fixes, was closed by ClawSweeper as implemented after reviewing the OpenRouter wrapper, attribution policy, and provider-owned auth/header forwarding path. The issue discussion was useful because it separated the old installed-version forwarding bug from the PR's header-name claim.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 76cf013df507; fix evidence: release v2026.4.24, commit cbcfdf62c729.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenRouter app attribution headers not sent - free models charged

1 participant