The OpenAI Python SDK now usesHTTPX2for its
synchronous and asynchronous HTTP clients. HTTPX2 is installed automatically
withopenai; the previoushttpxpackage is not. This guide explains what
changes for applications that interact with the SDK’s HTTP layer.
If you construct anOpenAIorAsyncOpenAIclient without providinghttp_client, your existing API calls,
parsed response models, streaming APIs, authentication, retries, and numeric
timeouts continue to work:
No HTTPX2 extra or separate installation is required:
If your application importedhttpxonly because an earlier SDK installed it
transitively, add your ownhttpxdependency or migrate those imports tohttpx2. Installing the SDK no longer installshttpxfor you.
HTTPX2 changes the default TLS trust store, including for applications that
use the SDK’s default HTTP client.HTTPX previously verified certificates
against the CA bundle provided bycertifi. HTTPX2 instead uses the
operating-system trust store, and the SDK no longer installscertifi.
This can break certificate verification in minimal container images without
system CA certificates, environments using corporate TLS-inspecting proxies,
and deployments that relied on a custom or modifiedcertifibundle. Install
the required CA certificates in the operating-system trust store, or configure
an explicit certificate bundle:
Alternatively, configure a directory of trusted CA certificates:
These environment variables are honored whentrust_env=True, which is the
default. To control trust explicitly on a custom client, pass anssl.SSLContextthroughverify:
UseDefaultAsyncHttpx2Client(verify=ssl_context)for the equivalent async
configuration. The SDK’s aiohttp transport uses the same HTTPX2 TLS settings.
Use HTTPX2 clients and HTTPX2 configuration objects. The SDK provides helpers
that preserve its recommended timeout, connection-pool, and redirect defaults:
Directly constructedhttpx2.Clientandhttpx2.AsyncClientinstances are
also supported. When you construct a client directly, its own HTTPX2 defaults
apply unless you configure them yourself.
The existingDefaultHttpxClientandDefaultAsyncHttpxClientnames continue
to work, but now construct HTTPX2 clients. PreferDefaultHttpx2ClientandDefaultAsyncHttpx2Clientwhen making the HTTP client family explicit.