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
float
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
float
Nucleus sampling parameter. Range: 0.0 to 1.0.
Tokens are selected from smallest set whose cumulative probability exceeds top_p.
float
Number of highest probability tokens to consider at each step.
int
Maximum number of tokens in the response.
int
Number of response variations to generate.
list[str]
List of strings that stop generation when encountered.
int
Random seed for reproducible outputs.
Response Configuration
str
Output format for the response.
"text/plain": Plain text (default)"application/json": JSON response
SchemaUnion
Schema object defining expected response structure. Use with
response_mime_type="application/json".Any
JSON Schema for response validation. Alternative to
response_schema with full JSON Schema support.bool
Whether to return log probabilities of chosen tokens.
int
Number of top candidate tokens to return log probabilities for.
Instructions and Tools
ContentUnion
Instructions to steer model behavior (e.g., “Answer concisely”, “You are a helpful assistant”).
ToolListUnion
List of tools the model can use (functions, code execution, search).
ToolConfig
Configuration for tool usage and function calling.
AutomaticFunctionCallingConfig
Configuration for automatic function calling.
Safety and Filtering
list[SafetySetting]
Safety settings to block unsafe content.
ModelArmorConfig
Model Armor configuration for prompt/response sanitization. Cannot be used with
safety_settings.Media Configuration
MediaResolution
Default media resolution for all media in the request.
list[str]
Modalities the model can return (e.g., [“TEXT”, “IMAGE”, “AUDIO”]).
SpeechConfigUnion
Configuration for speech generation.
bool
Whether to include audio timestamps in the request.
ImageConfig
Configuration for image generation.
Advanced Options
float
Penalizes tokens that have appeared, encouraging diverse content.
float
Penalizes frequently repeated tokens.
ThinkingConfig
Configuration for model thinking/reasoning features.
GenerationConfigRoutingConfig
Configuration for model routing.
ModelSelectionConfig
Configuration for model selection.
str
Resource name of cached content to use.
dict[str, str]
User-defined metadata labels for billing breakdown.
HttpOptions
HTTP request options (see below).
bool
Whether to return raw HTTP response in
sdk_http_response field.Example
HttpOptions
HTTP request configuration.str
Base URL for the API endpoint.
ResourceScope
Resource scope for constructing resource names with custom base_url.
str
API version to use.
dict[str, str]
Additional HTTP headers.
int
Request timeout in milliseconds.
dict[str, Any]
Arguments passed to the HTTP client.
dict[str, Any]
Arguments passed to the async HTTP client.
dict[str, Any]
Extra parameters to add to the request body. Must match backend API structure.
HttpRetryOptions
HTTP retry configuration (see below).
httpx.Client
Custom httpx client for requests.
httpx.AsyncClient
Custom httpx async client.
aiohttp.ClientSession
Custom aiohttp client session.
Example
HttpRetryOptions
Retry configuration for HTTP requests.int
Maximum number of attempts including the original request. Default: 5.
Set to 0 or 1 for no retries.
float
Initial delay before first retry in seconds. Default: 1.0.
float
Maximum delay between retries in seconds. Default: 60.0.
float
Exponential backoff multiplier. Default: 2.0.
float
Randomness factor for delay. Default: 1.0.
list[int]
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