Consider enabling HTTP2 by default
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Bắt đầu với _DefaultHttpxClient trong src/openai/_base_client.py và các khai báo dependency trong pyproject.toml. Xác định việc bật HTTP/2 nên xử lý dependency h2 và hành vi hiện có của custom http_client như thế nào; công việc hoàn tất khi client mặc định sử dụng HTTP/2 mà không làm gián đoạn fallback về HTTP/1.1 hoặc các client do người dùng cung cấp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
- This is a feature request for the Python library
Describe the feature or improvement you're requesting
Motivation
The OpenAI Python SDK uses httpx as its HTTP client, but HTTP/2 is disabled by default (http2=False in httpx.Client.__init__). This means every SDK user is stuck with HTTP/1.1 unless they manually configure a custom httpx.Client(http2=True) — a detail most users never discover.
Checked against v2.44.0 (latest), the _DefaultHttpxClient (src/openai/_base_client.py:834) still doesn't pass http2=True, and pyproject.toml only declares httpx>=0.23.0, <1 with no [http2] extra:
class _DefaultHttpxClient(httpx.Client):
def __init__(self, **kwargs: Any) -> None:
kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
kwargs.setdefault("follow_redirects", True)
super().__init__(**kwargs) # http2 defaults to False
Proposed Change
class _DefaultHttpxClient(httpx.Client):
def __init__(self, **kwargs: Any) -> None:
kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
kwargs.setdefault("follow_redirects", True)
+ kwargs.setdefault("http2", True)
super().__init__(**kwargs)
And optionally add an [http2] extra in pyproject.toml:
[project.optional-dependencies]
http2 = ["httpx[http2]"]
Prior Art
- Anthropic Python SDK (v0.104.1) already passes
http2through to the httpx transport (_base_client.py:871) - httpx has supported HTTP/2 since v0.13 (current declared dep is
httpx>=0.23.0) - The
h2package is lightweight, pure-Python, and widely used - HTTP/2 is supported across all major LLM API providers
Compatibility
- If the user provides a custom
http_client, their configuration takes precedence — no breaking change - If the server doesn't support HTTP/2, httpx gracefully downgrades to HTTP/1.1 (this has been handled by httpx for years)
- Connection limits already set by the SDK are fully compatible with HTTP/2
- No API changes needed — purely internal client configuration
Why Not Just Document It
Users can already do this manually:
import httpx
from openai import OpenAI
client = OpenAI(http_client=httpx.Client(http2=True))
But most users never find this knob. Making it the default means everyone benefits, especially developers using the SDK for production workloads with high request volumes. The downside is negligible: users who don't have h2 installed would get an ImportError at client construction (easily debuggable), or we mitigate this by making h2 optional and wrapping the import.
Additional context
Many popular LLM API providers already support HTTP/2 (confirmed via ALPN h2):
- OpenAI (
api.openai.com) - DeepSeek (
api.deepseek.com) - Anthropic (
api.anthropic.com)
Performance Impact
HTTP/2 brings meaningful improvements, especially for chat completions (frequent, streaming requests):
| Metric | HTTP/1.1 | HTTP/2 |
|---|---|---|
| TLS handshake | ~100ms | ~67ms (1-RTT) |
| Single request | ~134ms | ~123ms |
| Header compression | ❌ | ✅ HPACK |
| Multiplexing | ❌ (6 conn/browser limit) | ✅ (1-2 connections) |
| Connections for 10 requests | 10 | 1-2 |
The biggest win is connection reuse + multiplexing. In HTTP/1.1, every concurrent or back-to-back request opens a new TCP+TLS handshake. With HTTP/2, a single persistent connection handles multiple concurrent requests — critical for streaming chat.completions.create(stream=True) where the SDK opens many chunks over the same connection. Real-world test on DeepSeek API showed TLS handshake dropping from ~100ms to ~67ms just from HTTP/2's 1-RTT TLS.
- Ngôn ngữ chính
- Python
- Star
- 31.8k
- Fork
- 7.3k
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 131
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openai/openai-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
openai/openai-python#4022 · 19 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersCó thể đã có người làm @mohmedmm đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
openai/openai-python#4017 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Querystring drops explicit empty-string scalar valuesCó thể đã có người làm @sylvesterkaczmarek đã nhận 31 ngày trước. Đang mởsdk-breaking-change v4
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
openai/openai-python#3837 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Define + export `ServiceTiers` string literalCó thể đã có người làm @SparshGarg999 đã nhận 58 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#3556 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointCó thể đã có người làm @Sehastrajit-S đã nhận 24 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#2927 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-python
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 60/100
521xueweihan/HelloGitHub#3924 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
wilbowes/EchoMuse#869 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Claiming namespace `jft63`Đang mởnamespace operations
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
EclipseFdn/open-vsx.org#14043 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
test: TestServeUntilStale races the server's close against the client's sendall (BrokenPipeError under load)Có thể đã có người làm @evoludigit đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 89/100
Maintainer thường phản hồi trong vòng 1 ngày