fix: respect user-specified User-Agent headers without modification#362
Merged
robert-j-y merged 2 commits intomainfrom Jan 27, 2026
Merged
Conversation
- Add case-insensitive lookup for User-Agent header - When user provides User-Agent (any case), use it verbatim without SDK suffix - Only add SDK identifier as default when no User-Agent is provided - Add comprehensive tests for withUserAgentSuffix function Fixes #300 Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
- Add normalizeHeaders() to properly handle Headers objects and array-of-tuples - Fix removeUndefinedEntries to filter both null and undefined values - Add tests for Headers object and array-of-tuples inputs - Update test to verify undefined keys are actually removed from result Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
Merged
4 tasks
kesavan-byte
pushed a commit
to osm-API/ai-sdk-provider
that referenced
this pull request
Feb 13, 2026
…penRouterTeam#362) * fix: respect user-specified User-Agent headers without modification - Add case-insensitive lookup for User-Agent header - When user provides User-Agent (any case), use it verbatim without SDK suffix - Only add SDK identifier as default when no User-Agent is provided - Add comprehensive tests for withUserAgentSuffix function Fixes OpenRouterTeam#300 Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> * fix: handle all HeadersInit variants and fix removeUndefinedEntries - Add normalizeHeaders() to properly handle Headers objects and array-of-tuples - Fix removeUndefinedEntries to filter both null and undefined values - Add tests for Headers object and array-of-tuples inputs - Update test to verify undefined keys are actually removed from result Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #300 - When users provided a custom
User-Agentheader, the SDK was appending its identifier to it, resulting in unexpected behavior likemy-app/1.0, ai-sdk/openrouter/x.x.x.Before:
After:
The fix also addresses a case-sensitivity bug where
User-Agent(capitalized) was not recognized as the same header asuser-agent(lowercase), causing duplicate headers to be sent.Key changes:
findHeaderKey()normalizeHeaders()to properly handle allHeadersInitvariants (Headers objects, array-of-tuples, plain objects)removeUndefinedEntriesto filter both null and undefined values (was only filtering null)withUserAgentSuffixUpdates since last revision:
normalizeHeaders()function to handleHeadersobjects and array-of-tuples inputs (previouslyObject.entries()on aHeadersobject returned empty array, silently losing all headers)removeUndefinedEntriesto usevalue != nullinstead ofvalue !== nullto properly filter undefined valuesHeadersInitvariants (Headers object, array-of-tuples)For reviewers:
normalizeHeaders()handling of Headers objects and arraysremoveUndefinedEntriesis only used bywithUserAgentSuffix, so the fix is isolatedChecklist
pnpm stylecheckandpnpm typecheckpnpm testand all tests passChangeset
pnpm changesetto create a changeset fileLink to Devin run: https://app.devin.ai/sessions/27723ec908ef4455be28e3c3c491b31e
Requested by: Robert Yeakel (@robert-j-y)