Gemini 2.5 Pro Extended Thinking Mode
Setup and context
Gemini 2.5 Pro's Extended Thinking is a feature that deepens the AI's reasoning process, generating more accurate and well-founded answers to complex problems. Rather than providing instant responses, it takes time to analyze problems step-by-step, considers multiple approaches, and derives the final answer through comprehensive evaluation.
What is Extended Thinking?
Extended Thinking mode allows Gemini 2.5 Pro to perform an "invisible reasoning process" for a given problem. This process follows these steps:
- Problem Analysis: Break down the given problem into components
- Hypothesis Generation: Consider multiple approaches
- Reasoning: Verify the pros and cons of each approach
- Conclusion: Generate the optimal answer
This entire process is exposed to API users as "thinking" and can be referenced alongside the final answer.
Differences from Standard Mode
| Aspect | Standard Mode | Extended Thinking |
|---|---|---|
| Reasoning Time | Short (few seconds) | Long (10-60 seconds) |
| Accuracy | High (usually sufficient) | Higher (for complex problems) |
| Cost | Lower | Slightly higher |
| Use Cases | Text generation, Q&A | Math, code, logic problems |
Applicable Use Cases
Extended Thinking is particularly effective for complex problem-solving scenarios:
✓ Ideal Use Cases
- Mathematical & Physics Calculations: Multi-step computations and proofs
- Code Generation & Debugging: Complex algorithm implementation
- Logic Problems: Puzzles and constraint satisfaction problems
- Technical Design: Architecture decisions and best practice selection
- Data Analysis: Statistical analysis and trend prediction
✗ Not Suitable For
- Template or boilerplate generation
- Simple information retrieval
- Real-time chat responses
Basic API Usage
Step 1: Environment Setup
pip install google-genaiStep 2: Basic Extended Thinking Request
from google import genai
# Initialize client
client = genai.Client(api_key="YOUR_API_KEY")
# Solve a problem using Extended Thinking mode
response = client.models.generate_content(
model="gemini-2.5-pro",
contents="Solve this equation: 2x² + 5x - 3 = 0",
config=genai.types.GenerateContentConfig(
thinking={
"type": "enabled",
"budget_tokens": 5000, # Max tokens for thinking
}
),
)
# Display thinking process and final answer
for part in response.content.parts:
if part.thinking:
print("【Thinking Process】")
print(part.thinking)
elif part.text:
print("【Final Answer】")
print(part.text)Step 3: Solving More Complex Problems
# Generate efficient code for computing Fibonacci numbers
response = client.models.generate_content(
model="gemini-2.5-pro",
contents="""
Write Python code meeting these requirements:
1. Function to compute the nth Fibonacci number
2. Achieve O(log n) time complexity
3. Use matrix exponentiation
4. Include test cases
""",
config=genai.types.GenerateContentConfig(
thinking={
"type": "enabled",
"budget_tokens": 8000,
}
),
)
for part in response.content.parts:
if part.thinking:
print("🤔 Thinking Process:")
print(part.thinking[:500] + "..." if len(part.thinking) > 500 else part.thinking)
elif part.text:
print("\n💻 Generated Code:")
print(part.text)Practical Example: Complex Algorithm Problem
Solve the classic "3Sum" problem using Extended Thinking:
response = client.models.generate_content(
model="gemini-2.5-pro",
contents="""
Write efficient Python code to solve the 3Sum problem:
- Input: Integer array and target sum
- Output: All unique triplets that sum to target
- Time complexity: O(n²) or better
- Include test cases
Example: arr = [-1, 0, 1, 2, -1, -4], target = 0
Expected: [[-1, -1, 2], [-1, 0, 1]]
""",
config=genai.types.GenerateContentConfig(
thinking={
"type": "enabled",
"budget_tokens": 10000,
}
),
)
print("=== 3Sum Problem Solution ===\n")
for part in response.content.parts:
if part.thinking:
print("Thinking Process (Overview):")
lines = part.thinking.split('\n')
print('\n'.join(lines[:10]))
print(f"... ({len(lines)} lines total)")
elif part.text:
print("\nFinal Code:\n")
print(part.text)Parameter Details
thinking Object
| Parameter | Type | Description |
|---|---|---|
type | string | Set to "enabled" to activate Extended Thinking. Default is "disabled" |
budget_tokens | int | Maximum tokens allocated for reasoning (1,000–100,000) |
Larger budget_tokens values enable deeper thinking but increase response time and cost. Recommended range: 5,000–15,000.
Best Practices
- Enable only for complex problems: Use standard mode for simple questions
- Set
budget_tokensappropriately: Adjust within 5,000–15,000 based on problem complexity - Leverage thinking output: Review the reasoning to understand answer justification
- Implement error handling: Account for potential timeouts with retry logic
Conclusion
Gemini 2.5 Pro's Extended Thinking mode significantly improves AI accuracy and reliability for complex problem-solving. Whether you're tackling mathematical calculations, code generation, or logic problems, Extended Thinking delivers well-founded, high-precision answers. The API is straightforward—just configure the thinking parameter.
Try Extended Thinking in your projects today!