Skip to content

fix: Send the User-Agent header on every request - #112

Merged
wagnercosta merged 1 commit into
mainfrom
fix/user-agent-header
Oct 9, 2026
Merged

wagnercosta merged 1 commit into
mainfrom
fix/user-agent-header

Conversation

@wagnercosta

Copy link
Copy Markdown
Member

🔴 Review tier: HIGH — human review required

  • Release — every SDK request changes its headers; needs a PyPI release to reach customers.
  • Behavior — requests now carry User-Agent: asknews-sdk-python/<version> (or the user_agent passed to the SDK). Until now the SDK sent no User-Agent at all.
  • Verified — pytest 132 passed (4 new tests, sync and async, respx-mocked); ruff check clean. Live on dev: a search_news call from this branch is metered as channel=sdk, client=python on requests_v4; the same call from the published 1.0.0 is metered as a raw api call.

What

BaseAPIClient.build_api_request sets user-agent on the request it builds (unless the caller passed one). The SDK configures the httpx client with the User-Agent, but it sends hand-built httpx.Request objects through client.send(), which does not merge the client's default headers, so the header never left the process. self.user_agent is kept on the client for that.

Why

The API gateway now attributes usage to a channel from the User-Agent (asknews-sdk-python/ → SDK / Python). Without this fix every Python SDK customer shows up as a raw HTTP call. The TS, Go and PHP SDKs already send theirs.

@wagnercosta
wagnercosta merged commit e744469 into main Oct 9, 2026
10 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