UniterRouter
API ReferenceGoogle Compatible

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:

  1. Process your request internally with extended reasoning
  2. Optionally return the thinking process
  3. Provide a more accurate final answer

ThinkingConfig Parameters

ParameterTypeDescription
includeThoughtsbooleanWhether to include thinking in response
thinkingBudgetintegerToken budget for thinking process
thinkingLevelstringDepth: 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

LevelDescriptionUse Case
MINIMALQuick, surface-level reasoningSimple questions
LOWBasic reasoningStandard tasks
MEDIUMModerate depthComplex questions
HIGHDeep, thorough reasoningMath, 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

ModelThinking 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

  1. Use appropriate thinking level - Higher levels use more tokens but provide better reasoning
  2. Set thinking budget - Control token usage with thinkingBudget
  3. Review thinking - Enable includeThoughts during development to understand model reasoning
  4. Match to task complexity - Simple tasks don't need HIGH thinking level

Token Usage

Thinking tokens are counted separately in the usage metadata:

{
  "usageMetadata": {
    "promptTokenCount": 50,
    "candidatesTokenCount": 200,
    "thinkingTokenCount": 500,
    "totalTokenCount": 750
  }
}

How is this guide?