Google Gen AI Python SDK: Sync and Async Proxy Settings
Synchronous HTTPX, asynchronous HTTPX and optional aiohttp can require different supported inputs.
For an ordinary HTTP proxy, provide the documented shared startup environment before creating the client:
HTTPS_PROXY='http://proxy.example:8080' python app.pyKeep normal API-key/cloud credentials. The HTTP listener can carry HTTPS destinations.
For the documented HTTPX SOCKS path with its support present, configure both option sets:
from google import genai
from google.genai import types
options = types.HttpOptions(
client_args={'proxy': 'socks5://proxy.example:1080'},
async_client_args={'proxy': 'socks5://proxy.example:1080'},
)
client = genai.Client(api_key=api_key, http_options=options)When this HTTPX SOCKS path is allowed to use a public intermediary, the SOCKS5 proxy list offers candidates for both proxy URLs. Retain and close the client through its workload. client_args alone does not select the async route.
The optional aiohttp backend can own asynchronous calls instead. Its proxy protocols and request arguments differ; use the installed SDK's supported choice of compatible asynchronous transport/HTTPX client rather than assuming HTTPX options configure aiohttp.
Label the failed operation by sync/async, backend and proxy protocol. Success on one path only establishes that path.