feat(agent): identify Python SDK traffic in user agent - #26
Merged
Conversation
Append the openrouter-agent-sdk distribution name and version to the generated SDK's User-Agent so agent traffic is distinguishable from plain openrouter-python traffic. Only appends when the SDK's user agent is still the generated default, so an explicit user_agent= or a hook that rewrites it during sdk_init keeps its value. Falls back to the bare distribution name when the package is not installed. 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.
Appends the
openrouter-agent-sdkdistribution name and version to the generated SDK'sUser-Agentso agent traffic is distinguishable from plainopenrouter-pythontraffic.Behavior
sdk_configuration.user_agentis still the generated default (openrouter._version.__user_agent__). An explicituser_agent=kwarg, or a hook that rewrites the value duringsdk_init, keeps its value untouched.importlib.metadata.PackageNotFoundErrorfalls back to the bare distribution name rather than emitting a wrong or empty version.Language-specific identity
.upstreamer/upstreamer.mdgains divergence #7: Python appends the PyPI distribution name (openrouter-agent-sdk), TypeScript the npm package name (@openrouter/agent), Go the module path (github.com/OpenRouterTeam/go-agent). The porting automation must not converge this token toward the TypeScript literal.Tests
tests/unit/test_user_agent.py— six cases: default append, idempotence, explicituser_agent=override (alongside hooks), hook-set user agent preserved,PackageNotFoundErrorfallback, and a wire-levelhttpx.MockTransportassertion that the header reaches the transport throughcall_modeltogether with the existingx-openrouter-callmodelmarker.Verification
.upstreamer/scripts/verify.sh— PASS: 0 failures