Overview
The Google Gen AI SDK supports HTTP and SOCKS5 proxies through both httpx and aiohttp libraries. You can configure proxies using environment variables or explicit client arguments.
HTTP Proxy with Environment Variables
Both httpx and aiohttp use urllib.request.getproxies() to read proxy settings from environment variables. This is the simplest method for configuring proxies.
Basic HTTP Proxy
HTTP Proxy with Authentication
Mixed HTTP and HTTPS Proxies
SOCKS5 Proxy
For SOCKS5 proxy support, you need to install httpx with the socks extra and explicitly pass proxy configuration through client arguments.
Install SOCKS5 Support
SOCKS5 with Authentication
SSL Certificates
Custom SSL Certificate File
Specify a custom SSL certificate file for proxy connections:
Custom SSL Context (Aiohttp)
For more control over SSL verification with aiohttp:
Custom SSL Context (Httpx)
Disable SSL Verification (Not Recommended)
Disabling SSL verification exposes your application to man-in-the-middle attacks. Only use this for testing in controlled environments.
Proxy Bypass
Bypass Proxy for Specific Hosts
Complete Proxy Configuration Examples
Corporate Proxy with SSL
SOCKS5 Proxy with Retry Configuration
Aiohttp with Custom SSL and Proxy
Troubleshooting
Verify Proxy Configuration
Test Proxy Connection
Common Issues
- Authentication Failures: Ensure username and password are properly URL-encoded
- SSL Certificate Errors: Verify that
SSL_CERT_FILE points to a valid certificate bundle
- SOCKS5 Not Working: Confirm that
httpx[socks] is installed
- Environment Variables Not Working: Check that variables are exported in the same shell session