Skip to main content

Overview

The HttpOptions 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 to v1.

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.
Refer to the backend API documentation for available parameters:

Aiohttp for Async Performance

By default, the SDK uses httpx for both sync and async clients. For better async performance, install the aiohttp extra:
The SDK configures trust_env=True to match httpx’s default behavior. Pass additional arguments to aiohttp.ClientSession.request() using async_client_args:

Available Aiohttp Arguments

Common async_client_args options include:
  • cookies: HTTP cookies
  • ssl: SSL context for HTTPS connections
  • connector: Custom aiohttp connector
  • trust_env: Use environment variables for proxy configuration (default: True)
  • timeout: aiohttp-specific timeout settings

Httpx Client Arguments

Pass custom arguments to the httpx client for both sync and async:

Custom Client Instances

Provide your own pre-configured client instances:

Complete Configuration Example

Per-Request HTTP Options

You can also override HTTP options for individual requests: