Skip to content

feat: PoC httpx to httpx2 migration - #159

Closed
yamaceay wants to merge 12 commits into
mainfrom
httpx
Closed

yamaceay wants to merge 12 commits into
mainfrom
httpx

Conversation

@yamaceay

@yamaceay yamaceay commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Context

Closes SAP/ai-sdk-python-backlog#10.

What this PR does and why it is needed

This PR introduces two bash scripts which do rule-based HTTPX to HTTPX2 migration.

The question whether we support a breaking change or not may depend on some aspects, e.g., some foundational dependencies might need to be fixed to the versions where httpx is essential.

Definition of Done

  • Code is tested (Unit, Integration, E2E)
  • Error handling created / updated & covered by the tests above
  • Documentation updated
    • Only Public APIs are allowed to be used in documentation/tutorials/sample code
  • (Optional) Aligned changes with the JS/TS and Java SDK
  • (Optional) Release notes updated -->

@yamaceay yamaceay changed the title Httpx feat: httpx to httpx2 migration Sep 21, 2026
@yamaceay yamaceay added python:uv Pull requests that update python:uv code don't merge labels Sep 21, 2026
@yamaceay

yamaceay commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Currently, both PRs are stuck at openai related timeout errors, which needs to be further investigated

Edit 1: Before the fix, the openai mockers registered a bare URL, e.g., <base>/completions, but the real request always arrived with ?api-version=2025-03-01-preview appended, because the proxy client injects that query param on every call. pytest_httpx2 does exact query-param matching (unlike the old respx which just ignored extra params), so the URL never matched and the mock raised a timeout. So, the fix consists of making each openai/cohere mocker build its registered URL conditionally. (1) If a URL is provided it appends ?api-version=2025-03-01-preview to match exactly what the client sends. (2) If it is none (wildcard), it remains None and continues to match anything, so that the previous behavior for all other 960 tests was already preserved. The next question is also if we can get rid of this exact search and just remove the dependency to the hard-coded api version.

Edit 2: Just found out about this: https://github.com/colin-b/pytest_httpx#matching-on-query-parameters

Edit 3: Regex can be used in URL match queries, so I could easily add a regex which (optionally) accepts the extra api-version URL param

@yamaceay yamaceay added the dependencies Pull requests that update a dependency file label Sep 21, 2026
@yamaceay

yamaceay commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

FYI now both PRs (#157 and #158) seem to pass CI ✅

Edit: Both failed at this time point due to unfinalized migration of google-genai-related code snippets to httpx2. Meanwhile, since there are a large overlap between those two, I believe it is better to maintain just one version (namely major) rather than the minor, so I closed the minor PR for now in favor of the major release.

@mwien

mwien commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Nice! Can you add a summary comment (links to PRs etc) to the investigation ticket?

@alpkom

alpkom commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

If this is a POC, could you please change the PR to a draft?

@yamaceay
yamaceay marked this pull request as draft September 23, 2026 08:23
@yamaceay yamaceay changed the title feat: httpx to httpx2 migration feat: PoC httpx to httpx2 migration Sep 23, 2026
@yamaceay yamaceay closed this Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file don't merge python:uv Pull requests that update python:uv code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants