Overview
TheHttpOptions class allows you to customize HTTP client behavior for both synchronous and asynchronous requests. You can configure API versions, custom endpoints, headers, timeouts, and choose between httpx and aiohttp clients.
API Version Selection
By default, the SDK uses the beta API endpoints to support preview features. You can switch to stable API endpoints by setting the API version tov1.
Vertex AI with v1 API
Gemini Developer API with v1alpha
Custom Base URL
Use a custom base URL when working with API gateway proxy servers or custom endpoints. This bypasses standard authentication checks for project, location, or API key.Custom Headers
Add custom HTTP headers to all requests:Timeout Configuration
Set request timeout in milliseconds:Extra Body Parameters
Add extra parameters to the request body. The structure must match the backend API’s request structure.Aiohttp for Async Performance
By default, the SDK uses httpx for both sync and async clients. For better async performance, install the aiohttp extra:trust_env=True to match httpx’s default behavior. Pass additional arguments to aiohttp.ClientSession.request() using async_client_args:
Available Aiohttp Arguments
Commonasync_client_args options include:
cookies: HTTP cookiesssl: SSL context for HTTPS connectionsconnector: Custom aiohttp connectortrust_env: Use environment variables for proxy configuration (default:True)timeout: aiohttp-specific timeout settings