Consider migrating from httpx to httpx2
httpx has become effectively unmaintained — no releases since 2024, issues and discussions are being closed without resolution. The ecosystem is moving to httpx2, the successor maintained by Pydantic Services Inc. with the original author (Tom Christie). Starlette already migrated (#3291, merged May 2026), with the PR author noting:
"httpx has become somehow unmaintained (closing issues, discussions, and no release since 2024), and [httpx2] is the least annoying path forward for every consumer of that package."
The migration is straightforward — httpx2 is API-compatible and a drop-in for common HTTP client usage. For the openai-python SDK specifically, the main impact would be swapping the httpx dependency and updating any internal imports.
Tracking this so the SDK doesn't get stuck on an unmaintained transport layer.
Please support this.
httpx is now a supply chain risk.
We wanted to consider how to support this in production, so rather than just :+1:, I put together a canidate/reference implementation to make the discussion concrete.
#3479 is a draft PR adding an opt-in openai[httpx2] extra with the same ergonomics as openai[aiohttp] (http_client=DefaultHttpx2Client()), zero behaviour change unless opted in. See the PR for details including caveats (httpx2 is a separate library, not a transport swap, so this is inherently heavier than the aiohttp extra).
One structural note for whoever triages this: from the outside, the httpx coupling appears to sit in the runtime shared across Stainless-generated Python SDKs rather than in this SDK's spec-generated code. Notably anthropic-sdk-python looks identically exposed. If so, the durable fix may belong at the Stainless level.
Happy to see other approaches to solve the problem, adapt the PR to however the Stainless side would want it expressed or for someone else to take over or to just close the PR.
Also openai[aiohttp] should not pull in httpx if possible. Instead route it through httpx2
This comment was posted by Claude Code using claude-opus-4-8 on behalf of David. David directed and approved this; the wording is Claude's (light review).
Chiming in from the Pydantic side (we maintain httpx2 and Pydantic AI) to +1 this and to ask for a specific shape of fix.
@peterlundberg's diagnosis is right: the coupling is in the Stainless shared runtime, not this SDK's spec-generated code. The _base_client.py guard is a nominal check:
if http_client is not None and not isinstance(http_client, httpx.AsyncClient):
raise TypeError("Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` ...")
Because httpx2.AsyncClient is a distinct class with no shared MRO, this rejects it at construction time. We re-verified today across the latest releases:
| SDK | generator | accepts httpx2.AsyncClient? |
|---|---|---|
| openai 2.45.0 | Stainless | ❌ isinstance guard |
| anthropic 0.116.0 | Stainless | ❌ identical guard |
| groq 1.5.0 | Stainless | ❌ identical guard |
| cohere 7.0.5 | Fern | ✅ duck-typed, no nominal check |
| mistralai 2.6.0 | Speakeasy | ✅ @runtime_checkable Protocol |
So this is one Stainless-template change, not three SDK changes — and two other generators already ship the more permissive behavior.
The durable fix we'd advocate: relax the guard from a nominal isinstance to a structural check — a @runtime_checkable Protocol over the methods the runtime actually calls (send/request/stream/aclose), exactly like Speakeasy does. That keeps the friendly fail-fast error for genuinely wrong objects while accepting any httpx-compatible client (httpx, httpx2, and transports like RESPX/wrappers). This is a bit broader than #3479's opt-in openai[httpx2] extra + accepted-types tuple: a Protocol needs no per-backend enumeration and unblocks the whole ecosystem in one move.
Since Stainless has no public issue tracker, could an OpenAI maintainer relay this to the Stainless team? Happy to provide the minimal repros and the per-SDK source-line citations if useful.
#3524 leaves httpx a required base dependency, so openai[httpx2] installs both stacks, and httpx still parses every URL even with an httpx2 client (_prepare_url builds an httpx.URL; _build_request serializes it back to a string for httpx2 to re-parse). So the I/O layer moves to maintained code, but the unmaintained package stays in the tree and partly on the path — the "stuck on an unmaintained transport layer" concern this issue opens with isn't fully retired.
Is httpx becoming optional a direction you're weighing for a future major? If so, the nominal isinstance guards look like the first blocker (they need the httpx.Client class to exist), and the @runtime_checkable Protocol suggested above removes that coupling. Happy to put up a small PR, or leave it if this is settled for now.
Hi, I'd be interested in looking into this issue and potentially submitting a PR for it. Let me know if this is something maintainers still want. :)
seems like httpx2 is now supported in the latest release. probably doesn't fulfill all the requirements listed in this thread but just fyi for visitors
Fyi from https://github.com/openai/openai-python/releases/tag/v3.0.0 this seams adressed
Thanks for raising this and for the thoughtful discussion and implementation suggestions. The HTTPX2 migration was completed in https://github.com/openai/openai-python/pull/3594 and released in https://github.com/openai/openai-python/releases/tag/v3.0.0. HTTPX2 is now the default HTTP client, and httpx is no longer installed automatically. Closing this as resolved — thanks again for helping move this forward.