Gemini - Google AI Studio
import Image from '@theme/IdealImage'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Overview
Gemini - Google AI Studio
| Property | Details |
|---|---|
| Description | Google AI Studio is a fully-managed AI development platform for building and using generative AI. |
| Provider Route on LiteLLM | gemini/ |
| Provider Doc | Google AI Studio ↗ |
| API Endpoint for Provider | https://generativelanguage.googleapis.com |
| Supported OpenAI Endpoints | /chat/completions, /embeddings, /completions, /videos, /images/edits |
| Lyria (music) | Cost map & notes |
| Pass-through Endpoint | Supported |
:::tip Gemini API vs Vertex AI
| Model Format | Provider | Auth Required |
|---|---|---|
gemini/gemini-2.0-flash | Gemini API | GEMINI_API_KEY (simple API key) |
vertex_ai/gemini-2.0-flash | Vertex AI | GCP credentials + project |
gemini-2.0-flash (no prefix) | Vertex AI | GCP credentials + project |
If you just want to use an API key (like OpenAI), use the gemini/ prefix.
Models without a prefix default to Vertex AI which requires full GCP authentication. :::
API Keys
os.environ["GEMINI_API_KEY"] = "your-api-key"
Sample Usage
from litellm import completion
os.environ['GEMINI_API_KEY'] = ""
response = completion(
model="gemini/gemini-pro",
messages=[{"role": "user", "content": "write code for saying hi from LiteLLM"}]
)
Supported OpenAI Params
- temperature
- top_p
- max_tokens
- max_completion_tokens
- stream
- tools
- tool_choice
- include_server_side_tool_invocations
- functions
- response_format
- n
- stop
- logprobs
- frequency_penalty
- modalities
- reasoning_content
- audio (for TTS models only)
- service_tier
Anthropic Params
- thinking (used to set max budget tokens across anthropic/gemini models)
Usage - Thinking / reasoning_content
LiteLLM translates OpenAI's reasoning_effort to Gemini's thinking parameter. Code
Cost Optimization: Use reasoning_effort="none" (OpenAI standard) for significant cost savings - up to 96% cheaper. Google's docs
:::info Note: Reasoning cannot be turned off on Gemini 2.5 Pro models. :::
:::tip Gemini 3 Models
For Gemini 3+ models (e.g., gemini-3-pro-preview), LiteLLM maps reasoning_effort to the thinking_level field instead of thinking_budget when you set it. Supported levels depend on the model (Flash-family models also support minimal and medium). If you omit reasoning_effort, LiteLLM does not send a default thinking_level — the request uses the Gemini API defaults (Gemini 3 Flash defaults to high on the API).
:::
:::warning Image Models
Gemini image models (e.g., gemini-3-pro-image-preview, gemini-2.0-flash-exp-image-generation) do not support the thinking_level parameter. LiteLLM automatically excludes image models from receiving thinking configuration to prevent API errors.
:::
Mapping for Gemini 2.5 and earlier models
| reasoning_effort | thinking | Notes |
|---|---|---|
| "none" | "budget_tokens": 0, "includeThoughts": false | 💰 Recommended for cost optimization - OpenAI-compatible, always 0 |
| "disable" | "budget_tokens": DEFAULT (0), "includeThoughts": false | LiteLLM-specific, configurable via env var |
| "low" | "budget_tokens": 1024 | |
| "medium" | "budget_tokens": 2048 | |
| "high" | "budget_tokens": 4096 |
Mapping for Gemini 3+ models
| reasoning_effort | thinking_level | Notes |
|---|---|---|
| "minimal" | "minimal" (Flash / some 3.1) or "low" | Flash-family IDs use minimal when supported |
| "low" | "low" | Best for simple instruction following or chat |
| "medium" | "medium" or "high" | "medium" where the API supports it; otherwise "high" |
| "high" | "high" | Maximizes reasoning depth |
| "disable" | "minimal" (Flash) or "low" | Cannot fully disable thinking in Gemini 3 |
| "none" | "minimal" (Flash) or "low" | Cannot fully disable thinking in Gemini 3 |
from litellm import completion
# Cost-optimized: Use reasoning_effort="none" for best pricing
resp = completion(
model="gemini/gemini-2.0-flash-thinking-exp-01-21",
messages=[{"role": "user", "content": "What is the capital of France?"}],
reasoning_effort="none", # Up to 96% cheaper!
)
# Or use other levels: "low", "medium", "high"
resp = completion(
model="gemini/gemini-2.5-flash-preview-04-17",
messages=[{"role": "user", "content": "What is the capital of France?"}],
reasoning_effort="low",
)
- Setup config.yaml
- model_name: gemini-2.5-flash
litellm_params:
model: gemini/gemini-2.5-flash-preview-04-17
api_key: os.environ/GEMINI_API_KEY
- Start proxy
litellm --config /path/to/config.yaml
- Test it!
curl http://0.0.0.0:4000/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer <YOUR-LITELLM-KEY>" \\
-d '{
"model": "gemini-2.5-flash",
"messages": [{"role": "user", "content": "What is the capital of France?"}],
"reasoning_effort": "low"
}'
Gemini 3+ Models - thinking_level Parameter
For Gemini 3+ models (e.g., gemini-3-pro-preview), you can use the new thinking_level parameter directly:
from litellm import completion
# Use thinking_level for Gemini 3 models
resp = completion(
model="gemini/gemini-3-pro-preview",
messages=[{"role": "user", "content": "Solve this complex math problem step by step."}],
reasoning_effort="high", # Options: "low" or "high"
)
# Low thinking level for faster, simpler tasks
resp = completion(
model="gemini/gemini-3-pro-preview",
messages=[{"role": "user", "content": "What is the weather today?"}],
reasoning_effort="low", # Minimizes latency and cost
)
curl http://0.0.0.0:4000/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer <YOUR-LITELLM-KEY>" \\
-d '{
"model": "gemini-3-pro-preview",
"messages": [{"role": "user", "content": "Solve this complex problem."}],
"reasoning_effort": "high"
}'
:::warning Temperature Recommendation for Gemini 3 Models
For Gemini 3 models, LiteLLM defaults temperature to 1.0 and strongly recommends keeping it at this default. Setting temperature < 1.0 can cause:
- Infinite loops
- Degraded reasoning performance
- Failure on complex tasks
LiteLLM will automatically set temperature=1.0 if not specified for Gemini 3+ models.
:::
Expected Response
ModelResponse(
id='chatcmpl-c542d76d-f675-4e87-8e5f-05855f5d0f5e',
created=1740470510,
model='claude-3-7-sonnet-20250219',
object='chat.completion',
system_fingerprint=None,
choices=[
Choices(
finish_reason='stop',
index=0,
message=Message(
content="The capital of France is Paris.",
role='assistant',
tool_calls=None,
function_call=None,
reasoning_content='The capital of France is Paris. This is a very straightforward factual question.'
),
)
],
usage=Usage(
completion_tokens=68,
prompt_tokens=42,
total_tokens=110,
completion_tokens_details=None,
prompt_tokens_details=PromptTokensDetailsWrapper(
audio_tokens=None,
cached_tokens=0,
text_tokens=None,
image_tokens=None
),
cache_creation_input_tokens=0,
cache_read_input_tokens=0
)
)
Pass thinking to Gemini models
You can also pass the thinking parameter to Gemini models.
This is translated to Gemini's thinkingConfig parameter.
response = litellm.completion(
model="gemini/gemini-2.5-flash-preview-04-17",
messages=[{"role": "user", "content": "What is the capital of France?"}],
thinking={"type": "enabled", "budget_tokens": 1024},
)
curl http://0.0.0.0:4000/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer $LITELLM_KEY" \\
-d '{
"model": "gemini/gemini-2.5-flash-preview-04-17",
"messages": [{"role": "user", "content": "What is the capital of France?"}],
"thinking": {"type": "enabled", "budget_tokens": 1024}
}'
Usage - service_tier
LiteLLM propagates OpenAI's service_tier parameter to Gemini, and also extracts it from the response headers (x-gemini-service-tier) into model_response.service_tier.
OpenAI service_tier | Gemini service_tier | Notes |
|---|---|---|
"auto" | "priority" | LiteLLM maps OpenAI's "auto" to Gemini's "priority" tier, as priority will fall back on Gemini. |
"flex" | "flex" | Direct mapping. |
"priority" | "priority" | Direct mapping. |
"default" | "standard" | LiteLLM maps "default" to "standard". |
| Any other value | Passed as-is (lowercased) | Values are case-insensitive and normalized to lowercase. |
On the response, LiteLLM maps "standard" back to "default" for the Gemini API.
Text-to-Speech (TTS) Audio Output
:::info
LiteLLM supports Gemini TTS models that can generate audio responses using the OpenAI-compatible audio parameter format.
:::
Supported Models
LiteLLM supports Gemini TTS models with audio capabilities (e.g. gemini-2.5-flash-preview-tts and gemini-2.5-pro-preview-tts). For the complete list of available TTS models and voices, see the official Gemini TTS documentation.
Limitations
:::warning
Important Limitations:
- Gemini TTS models only support the
pcm16audio format - Streaming support has not been added to TTS models yet
- The
modalitiesparameter must be set to['audio']for TTS requests
:::
Quick Start
from litellm import completion
os.environ['GEMINI_API_KEY'] = "your-api-key"
response = completion(
model="gemini/gemini-2.5-flash-preview-tts",
messages=[{"role": "user", "content": "Say hello in a friendly voice"}],
modalities=["audio"], # Required for TTS models
audio={
"voice": "Kore",
"format": "pcm16" # Required: must be "pcm16"
}
)
print(response)
- Setup config.yaml
model_list:
- model_name: gemini-tts-flash
litellm_params:
model: gemini/gemini-2.5-flash-preview-tts
api_key: os.environ/GEMINI_API_KEY
- model_name: gemini-tts-pro
litellm_params:
model: gemini/gemini-2.5-pro-preview-tts
api_key: os.environ/GEMINI_API_KEY
- Start proxy
litellm --config /path/to/config.yaml
- Make TTS request
curl http://0.0.0.0:4000/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer <YOUR-LITELLM-KEY>" \\
-d '{
"model": "gemini-tts-flash",
"messages": [{"role": "user", "content": "Say hello in a friendly voice"}],
"modalities": ["audio"],
"audio": {
"voice": "Kore",
"format": "pcm16"
}
}'
Advanced Usage
You can combine TTS with other Gemini features:
response = completion(
model="gemini/gemini-2.5-pro-preview-tts",
messages=[
{"role": "system", "content": "You are a helpful assistant that speaks clearly."},
{"role": "user", "content": "Explain quantum computing in simple terms"}
],
modalities=["audio"],
audio={
"voice": "Charon",
"format": "pcm16"
},
temperature=0.7,
max_tokens=150
)
For more information about Gemini's TTS capabilities and available voices, see the official Gemini TTS documentation.
Passing Gemini Specific Params
Response schema
LiteLLM supports sending response_schema as a param for Gemini-1.5-Pro on Google AI Studio.
Response Schema
from litellm import completion
os.environ['GEMINI_API_KEY'] = ""
messages = [
{
"role": "user",
"content": "List 5 popular cookie recipes."
}
]
response_schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"recipe_name": {
"type": "string",
},
},
"required": ["recipe_name"],
},
}
completion(
model="gemini/gemini-1.5-pro",
messages=messages,
response_format={"type": "json_object", "response_schema": response_schema} # 👈 KEY CHANGE
)
print(json.loads(completion.choices[0].message.content))
- Add model to config.yaml
model_list:
- model_name: gemini-pro
litellm_params:
model: gemini/gemini-1.5-pro
api_key: os.environ/GEMINI_API_KEY
- Start Proxy
$ litellm --config /path/to/config.yaml
- Make Request!
curl -X POST 'http://0.0.0.0:4000/chat/completions' \\
-H 'Content-Type: application/json' \\
-H 'Authorization: Bearer sk-1234' \\
-d '{
"model": "gemini-pro",
"messages": [
{"role": "user", "content": "List 5 popular cookie recipes."}
],
"response_format": {"type": "json_object", "response_schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"recipe_name": {
"type": "string",
},
},
"required": ["recipe_name"],
},
}}
}
'
Validate Schema
To validate the res