feat: Enable HTTP/2 by default in httpx client#3477
Open
KrisTHL181 wants to merge 2 commits into
Open
Conversation
Adds http2=True to both _DefaultHttpxClient and _DefaultAsyncHttpxClient, and provides an [http2] optional dependency extra for httpx[http2]. HTTP/2 offers meaningful performance benefits: connection reuse, multiplexing, HPACK header compression, and 1-RTT TLS handshake. All major LLM API providers (OpenAI, DeepSeek, Anthropic) already support HTTP/2 via ALPN negotiation. Falls back gracefully to HTTP/1.1 if the server doesn't support h2, or if the h2 package is not installed.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7db638f1b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Check if h2 is importable at module level and set _HTTP2_AVAILABLE accordingly. This lets pip install openai[http2] transparently enable HTTP/2 without breaking users who don't have h2 installed.
1 task
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.
Adds http2=True to both _DefaultHttpxClient and _DefaultAsyncHttpxClient, and provides an [http2] optional dependency extra for httpx[http2].
HTTP/2 offers meaningful performance benefits: connection reuse, multiplexing, HPACK header compression, and 1-RTT TLS handshake. All major LLM API providers (OpenAI, DeepSeek, Anthropic) already support HTTP/2 via ALPN negotiation.
Falls back gracefully to HTTP/1.1 if the server doesn't support h2, or if the h2 package is not installed.
Changes being requested
Enable HTTP/2 by default in the SDK's httpx client for both sync (
_DefaultHttpxClient) and async (_DefaultAsyncHttpxClient) clients.Additional context & links
#3476