Consider enabling HTTP2 by default
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Inizia con _DefaultHttpxClient in src/openai/_base_client.py e con le dichiarazioni delle dipendenze in pyproject.toml. Determina come l’abilitazione di HTTP/2 dovrebbe gestire la dipendenza h2 e il comportamento esistente di custom http_client; il lavoro è completato quando il client predefinito usa HTTP/2 senza interrompere il fallback a HTTP/1.1 o i client forniti dall’utente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 31.8k
- Fork
- 7.3k
- Merge medio
- 1g 3h
- PR unite (30g)
- 131
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di openai/openai-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
openai/openai-python#4022 · 19 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersForse già presa @mohmedmm l’ha presa 9 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
openai/openai-python#4017 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Querystring drops explicit empty-string scalar valuesForse già presa @sylvesterkaczmarek l’ha presa 31 giorni fa. Apertasdk-breaking-change v4
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
openai/openai-python#3837 ·
I maintainer di solito rispondono entro 1 giorno
-
Define + export `ServiceTiers` string literalForse già presa @SparshGarg999 l’ha presa 58 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openai/openai-python#3556 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointForse già presa @Sehastrajit-S l’ha presa 24 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openai/openai-python#2927 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di openai/openai-python
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 83/100
PedestrianDynamics/pyFDS-Evac#766 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 91/100
alchaincyf/nuwa-skill#86 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 2 giorni
-
Docs Needs Triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
pandas-dev/pandas#71055 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: graphify reads files that git's global ignore file hidesForse già presa @smngvlkz l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Graphify-Labs/graphify#4335 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno