Skip to content

Conversation

@bledden
Copy link

@bledden bledden commented Dec 21, 2025

Summary

Fixes #300

Previously, when a user specified a custom user-agent header, the SDK would silently append its version string to it. For example:

const openrouter = createOpenRouter({
  headers: { 'user-agent': 'my-custom-app/1.0' }
});
// Actual header sent: "my-custom-app/1.0 ai-sdk/openrouter/1.5.4"

This unexpected modification could break header-based authentication or routing logic.

Changes

The new behavior respects user-provided headers:

  • If NO user-agent is provided: SDK sets user-agent: ai-sdk/openrouter/X.X.X (same as before)
  • If user-agent IS provided: User's header is preserved unchanged, and SDK version is sent via X-OpenRouter-SDK-Version header instead

Validation

Verified that OpenRouter's API works fine without the SDK version in user-agent:

curl -s "https://openrouter.ai/api/v1/chat/completions" \
  -H "User-Agent: my-custom-app/1.0" \
  ...
# Request succeeds - OpenRouter doesn't require SDK version in user-agent

Test Plan

  • Added unit tests for withUserAgentSuffix covering all scenarios
  • All 133 unit tests pass (node + edge)
  • E2E tests pass
  • Build succeeds

🤖 Generated with Claude Code

bledden and others added 2 commits December 20, 2025 23:25
Previously, when a user specified a custom `user-agent` header, the SDK
would silently append its version string to it (e.g., "my-agent" became
"my-agent ai-sdk/openrouter/1.5.4"). This could break header-based logic
and violates the principle of least surprise.

Now the behavior is:
- If NO user-agent is provided: SDK sets `user-agent: ai-sdk/openrouter/X.X.X`
- If user-agent IS provided: User's header is preserved unchanged, and
  SDK version is sent via `X-OpenRouter-SDK-Version` header instead

This ensures user-specified headers are never silently modified while
still providing SDK version information to OpenRouter.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add changeset for issue OpenRouterTeam#300 fix
- Fix formatting in test file per Biome style

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@subtleGradient subtleGradient self-assigned this Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Openrouter AI SDK provider overrides/silently rewrites user-specified headers

2 participants