Skip to content

feat(agent): identify Python SDK traffic in user agent - #26

Merged
LukasParke merged 2 commits into
mainfrom
feat/user-agent-python-agent
Aug 26, 2026
Merged

feat(agent): identify Python SDK traffic in user agent#26
LukasParke merged 2 commits into
mainfrom
feat/user-agent-python-agent

Conversation

@LukasParke

Copy link
Copy Markdown
Contributor

Appends 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.

speakeasy-sdk/python 1.1.22 2.914.0 1.0.0 openrouter openrouter-agent-sdk/0.8.0

Behavior

  • The token is appended only when sdk_configuration.user_agent is still the generated default (openrouter._version.__user_agent__). An explicit user_agent= kwarg, or a hook that rewrites the value during sdk_init, keeps its value untouched.
  • importlib.metadata.PackageNotFoundError falls back to the bare distribution name rather than emitting a wrong or empty version.
  • Appending is idempotent.

Language-specific identity

.upstreamer/upstreamer.md gains 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, explicit user_agent= override (alongside hooks), hook-set user agent preserved, PackageNotFoundError fallback, and a wire-level httpx.MockTransport assertion that the header reaches the transport through call_model together with the existing x-openrouter-callmodel marker.

Verification

.upstreamer/scripts/verify.shPASS: 0 failures

uv sync --frozen --all-extras     pass
uv lock --check                   pass
ruff check / ruff format --check  pass
mypy src tests                    pass
pytest tests/unit --cov-fail-under=83   pass
required public API (31 symbols)  pass

LukasParke and others added 2 commits August 25, 2026 17:08
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>
@LukasParke
LukasParke merged commit a5251c4 into main Aug 26, 2026
7 checks passed
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.

1 participant