Overview
Configuration types control various aspects of API requests, including generation parameters, HTTP options, and retry behavior.GenerateContentConfig
Main configuration for content generation requests.Generation Parameters
Controls randomness in token selection. Range: 0.0 to 2.0.
- Lower values (e.g., 0.2): More deterministic, focused responses
- Higher values (e.g., 1.5): More creative, diverse responses
Nucleus sampling parameter. Range: 0.0 to 1.0.
Tokens are selected from smallest set whose cumulative probability exceeds top_p.
Number of highest probability tokens to consider at each step.
Maximum number of tokens in the response.
Number of response variations to generate.
List of strings that stop generation when encountered.
Random seed for reproducible outputs.
Response Configuration
Output format for the response.
"text/plain": Plain text (default)"application/json": JSON response
Schema object defining expected response structure. Use with
response_mime_type="application/json".JSON Schema for response validation. Alternative to
response_schema with full JSON Schema support.Whether to return log probabilities of chosen tokens.
Number of top candidate tokens to return log probabilities for.
Instructions and Tools
Instructions to steer model behavior (e.g., “Answer concisely”, “You are a helpful assistant”).
List of tools the model can use (functions, code execution, search).
Configuration for tool usage and function calling.
Configuration for automatic function calling.
Safety and Filtering
Safety settings to block unsafe content.
Model Armor configuration for prompt/response sanitization. Cannot be used with
safety_settings.Media Configuration
Default media resolution for all media in the request.
Modalities the model can return (e.g., [“TEXT”, “IMAGE”, “AUDIO”]).
Configuration for speech generation.
Whether to include audio timestamps in the request.
Configuration for image generation.
Advanced Options
Penalizes tokens that have appeared, encouraging diverse content.
Penalizes frequently repeated tokens.
Configuration for model thinking/reasoning features.
Configuration for model routing.
Configuration for model selection.
Resource name of cached content to use.
User-defined metadata labels for billing breakdown.
HTTP request options (see below).
Whether to return raw HTTP response in
sdk_http_response field.Example
HttpOptions
HTTP request configuration.Base URL for the API endpoint.
Resource scope for constructing resource names with custom base_url.
API version to use.
Additional HTTP headers.
Request timeout in milliseconds.
Arguments passed to the HTTP client.
Arguments passed to the async HTTP client.
Extra parameters to add to the request body. Must match backend API structure.
HTTP retry configuration (see below).
Custom httpx client for requests.
Custom httpx async client.
Custom aiohttp client session.
Example
HttpRetryOptions
Retry configuration for HTTP requests.Maximum number of attempts including the original request. Default: 5.
Set to 0 or 1 for no retries.
Initial delay before first retry in seconds. Default: 1.0.
Maximum delay between retries in seconds. Default: 60.0.
Exponential backoff multiplier. Default: 2.0.
Randomness factor for delay. Default: 1.0.
HTTP status codes that trigger a retry.
Default: 408, 429, and 5xx errors.
Example
Common Configuration Patterns
Creative Writing
Deterministic Output
JSON Response
With System Instructions
With Safety Settings
With Custom Timeout
See Also
- Types Overview - Type system overview
- Client Reference - Using config with the client
- Content Types - Content and Part types