Extended Thinking
Gemini Thinking API - Advanced reasoning with Gemini 2.0 Flash Thinking. Chain-of-thought reasoning for complex math, coding, and analysis problems.
Extended Thinking
Gemini models support extended thinking, which allows the model to perform deeper reasoning before generating a response. This is particularly useful for complex problem-solving, math, coding, and analytical tasks.
Model Requirements: Extended thinking is available on Gemini 2.0 Flash Thinking and Gemini 3+ models.
How It Works
Enable thinking by adding thinkingConfig to your generationConfig. The model will:
- Process your request internally with extended reasoning
- Optionally return the thinking process
- Provide a more accurate final answer
ThinkingConfig Parameters
| Parameter | Type | Description |
|---|---|---|
includeThoughts | boolean | Whether to include thinking in response |
thinkingBudget | integer | Token budget for thinking process |
thinkingLevel | string | Depth: MINIMAL, LOW, MEDIUM, HIGH |
Example
curl -X POST "https://api.uniterouter.ai/v1beta/models/gemini-2.0-flash-thinking-exp:generateContent" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $UNITEROUTER_API_KEY" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "Solve: If a train travels at 60 km/h for 2.5 hours, then at 80 km/h for 1.5 hours, what is the average speed for the entire journey?"}]
}
],
"generationConfig": {
"thinkingConfig": {
"includeThoughts": true,
"thinkingBudget": 2048,
"thinkingLevel": "HIGH"
}
}
}'import google.generativeai as genai
genai.configure(
api_key="your_uniterouter_api_key",
transport="rest",
client_options={"api_endpoint": "api.uniterouter.ai"}
)
model = genai.GenerativeModel("gemini-2.0-flash-thinking-exp")
response = model.generate_content(
"Solve: If a train travels at 60 km/h for 2.5 hours, then at 80 km/h for 1.5 hours, what is the average speed for the entire journey?",
generation_config={
"thinkingConfig": {
"includeThoughts": True,
"thinkingBudget": 2048,
"thinkingLevel": "HIGH"
}
}
)
# Access thinking and response
for part in response.candidates[0].content.parts:
if hasattr(part, 'thought') and part.thought:
print("Thinking:", part.text)
else:
print("Answer:", part.text)import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI("your_uniterouter_api_key", {
baseUrl: "https://api.uniterouter.ai"
});
const model = genAI.getGenerativeModel({
model: "gemini-2.0-flash-thinking-exp",
generationConfig: {
thinkingConfig: {
includeThoughts: true,
thinkingBudget: 2048,
thinkingLevel: "HIGH"
}
}
});
const result = await model.generateContent(
"Solve: If a train travels at 60 km/h for 2.5 hours, then at 80 km/h for 1.5 hours, what is the average speed for the entire journey?"
);
console.log(result.response.text());Thinking Levels
| Level | Description | Use Case |
|---|---|---|
MINIMAL | Quick, surface-level reasoning | Simple questions |
LOW | Basic reasoning | Standard tasks |
MEDIUM | Moderate depth | Complex questions |
HIGH | Deep, thorough reasoning | Math, coding, analysis |
Response Format
When includeThoughts is true, the response includes thinking parts:
{
"candidates": [
{
"content": {
"parts": [
{
"thought": true,
"text": "Let me break this down step by step..."
},
{
"text": "The average speed for the entire journey is 67.5 km/h."
}
],
"role": "model"
}
}
]
}Supported Models
| Model | Thinking Support |
|---|---|
gemini-2.0-flash-thinking-exp | â Full support |
gemini-2.5-pro | â Full support |
gemini-2.5-flash | â Full support |
gemini-3-pro | â
Full support with thinkingLevel |
Best Practices
- Use appropriate thinking level - Higher levels use more tokens but provide better reasoning
- Set thinking budget - Control token usage with
thinkingBudget - Review thinking - Enable
includeThoughtsduring development to understand model reasoning - Match to task complexity - Simple tasks don't need
HIGHthinking level
Token Usage
Thinking tokens are counted separately in the usage metadata:
{
"usageMetadata": {
"promptTokenCount": 50,
"candidatesTokenCount": 200,
"thinkingTokenCount": 500,
"totalTokenCount": 750
}
}Related
- Generate Content - Basic generation
- Structured Output - JSON output
How is this guide?
Structured Output
Gemini JSON Mode API - Generate validated JSON with Gemini Pro. Schema-based structured output for reliable data extraction and type-safe AI responses.
Vision
Gemini Vision API - Analyze images and videos with Gemini Pro Vision, Gemini 1.5. Multimodal AI for image understanding, video analysis, and document processing.