Skip to main content
The OpenAI Python SDK uses httpx for HTTP requests, which provides comprehensive proxy support.

Basic Proxy Configuration

The simplest way to configure a proxy is by customizing the HTTP client:

Environment Variables

You can also use environment variables to configure proxies globally:
The httpx client will automatically use these environment variables:

Authenticated Proxies

For proxies requiring authentication, include credentials in the proxy URL:
Or via environment variables:

Custom Proxy Configuration

For more advanced proxy configurations, you can customize the httpx transport:

Different Proxies for HTTP and HTTPS

You can specify different proxies for HTTP and HTTPS:
Or with environment variables:

SOCKS Proxies

For SOCKS proxy support, install the httpx[socks] extra:
Then configure a SOCKS proxy:

Per-Request Proxy

You can configure proxies on a per-request basis using with_options():

Async Proxy Configuration

Proxy configuration works the same way with the async client:

Disabling Proxies

To disable environment variable proxies for specific requests:

Troubleshooting

Testing Proxy Connection

Verify your proxy configuration:

Common Issues

Increase the timeout for proxy connections:
For corporate proxies with custom certificates, you may need to configure SSL verification:
Ensure your credentials are properly URL-encoded:

Learn More