
Gemini Thought Summaries: Audit Deep Think Reasoning
Summary
Surface, stream, and log Gemini 2.5 Pro Deep Think's reasoning chain with thought summaries.
On June 22, 2026 Google switched on Deep Think for Gemini 2.5 Pro, and the reasoning leaderboard moved overnight: 82.4% on GPQA Diamond, 89.8% on MMLU-Pro, and a record 94.1% on HumanEval+. Deep Think is an extended-reasoning configuration that explores several lines of attack in parallel before it commits to an answer, which is exactly why it does so well on hard science, math, and multi-step coding.
The benchmark headline is fun, but the part that actually changes how you build is quieter: when a thinking model reasons, the Gemini API can hand you a thought summary — a readable trace of how the model got there — plus a thought signature that lets you carry that reasoning across turns. Most teams never turn either of these on, so they debug reasoning failures blind and pay for thinking tokens they never inspect.
This guide is the missing manual for that surface. You will turn on thought summaries, stream them token by token, read the same thing through the new Interactions API, account for thinking tokens on your bill, preserve thought signatures correctly across a multi-turn conversation, and wrap it all into a small reusable "reasoning auditor." Every code sample matches the official Gemini API docs as of the June 22, 2026 update.
What you'll build
A thin Python wrapper around generate_content that runs a reasoning-heavy prompt on a thinking model, captures the model's thought summary separately from its final answer, reports how many thinking tokens were spent, and keeps the reasoning state intact for follow-up questions. By the end you will know which knob to reach for — include_thoughts, thinking_budget, thinking_level, or the Interactions API's thinking_summaries — and what each one costs.
Prerequisites
- Python 3.9+ and a terminal.
- A Gemini API key from Google AI Studio (aistudio.google.com/apikey). The free tier returns thought summaries, so you can follow along at no cost.
- The official SDK:
pip install google-genai(this is thegoogle-genaipackage, not the oldergoogle-generativeai). - Set the key once in your shell:
export GEMINI_API_KEY="your_key_here". The client reads it automatically. - Basic familiarity with calling an LLM API. No machine-learning background needed.
Step 1 — A baseline thinking call
Any Gemini 3 or 2.5 series model thinks by default; you do not opt in. The only thing that makes a request a "thinking" request is choosing a thinking-capable model. Here is the plainest possible call. Notice there is no special config yet — the reasoning happens internally and you only see the answer.
from google import genai
# Reads GEMINI_API_KEY from the environment automatically.
client = genai.Client()
resp = client.models.generate_content(
model="gemini-2.5-pro", # Deep Think is the extended-reasoning config of 2.5 Pro
contents="What is the sum of the first 50 prime numbers?",
)
print(resp.text)
Example output:
The sum of the first 50 prime numbers is 5117.
Correct, but opaque. You have no idea whether the model actually summed the primes or pattern-matched a memorized figure. That is what Step 2 fixes.
Step 2 — Turn on thought summaries
Set include_thoughts=True inside a ThinkingConfig. The response now contains two kinds of parts: parts where part.thought is True (the summary of the model's reasoning) and normal answer parts where it is False. You separate them by iterating the parts and checking the flag.
from google import genai
from google.genai import types
client = genai.Client()
resp = client.models.generate_content(
model="gemini-2.5-pro",
contents="What is the sum of the first 50 prime numbers?",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(
include_thoughts=True
)
),
)
for part in resp.candidates[0].content.parts:
if not part.text:
continue
if part.thought:
print("--- Thought summary ---")
print(part.text)
else:
print("--- Answer ---")
print(part.text)
Example output (the summary is paraphrased by the model and will vary run to run):
--- Thought summary ---
**Listing the primes**
I need the first 50 primes, starting 2, 3, 5, 7, 11 ... up to 229.
**Summing in chunks**
I'll add them in groups of ten to avoid slips, then total the
five subtotals: 129 + 281 + 381 + 565 + ... and verify the count is 50.
--- Answer ---
The sum of the first 50 prime numbers is 5117.
One thing to internalize early: the summary is not the model's raw chain of thought. It is a compressed, human-readable digest of much longer internal reasoning. That distinction matters for both debugging and billing, and we come back to it.
Step 3 — Stream the reasoning live
For a long task, waiting for the whole response feels like staring at a spinner. Switch to generate_content_stream and you get rolling summary chunks while the model is still thinking, followed by the answer chunks. Same thought flag, just delivered incrementally.
from google import genai
from google.genai import types
client = genai.Client()
prompt = """
Alice, Bob, and Carol each live in a different house: red, green, or blue.
The person in the red house owns a cat. Bob is not in the green house.
Carol owns a dog. The green house is left of the red house.
Alice does not own a cat. Who lives where, and who owns what?
"""
thoughts, answer = "", ""
for chunk in client.models.generate_content_stream(
model="gemini-2.5-pro",
contents=prompt,
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(include_thoughts=True)
),
):
for part in chunk.candidates[0].content.parts:
if not part.text:
continue
if part.thought:
if not thoughts:
print("Thinking...\n")
print(part.text, end="")
thoughts += part.text
else:
if not answer:
print("\n\nAnswer:\n")
print(part.text, end="")
answer += part.text
You will see the "Thinking..." banner, then a stream of reasoning, then the final assignment. This is the same UX you see in the Gemini app's Deep Think mode — now under your control in code.
Step 4 — The same thing on the Interactions API
Google now recommends the newer Interactions API for fresh projects. Reasoning is a first-class citizen there: instead of parts with a thought flag, you get a steps array, and a step whose type is "thought" carries the summary. Turn summaries on with thinking_summaries: "auto".
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="What is the sum of the first 50 prime numbers?",
generation_config={"thinking_summaries": "auto"},
)
for step in interaction.steps:
if step.type == "thought":
print("--- Thought summary ---")
if step.summary: # may be empty; always guard
for block in step.summary:
if block.type == "text":
print(block.text)
elif step.type == "model_output":
for block in step.content:
if block.type == "text":
print("--- Answer ---")
print(block.text)
The shape differs but the idea is identical: thought steps for reasoning, model-output steps for the answer. Pick one API per project and stay consistent — mixing them mid-codebase is a common source of confusion.
Step 5 — Pay attention to thinking tokens
Here is the gotcha that surprises people at invoice time: you are billed for the full internal thinking, not the short summary you see. When thinking is on, output price = answer tokens + thinking tokens. The summary is a cheap window onto an expensive process. Read the real number from usage_metadata.
resp = client.models.generate_content(
model="gemini-2.5-pro",
contents="Prove there are infinitely many primes, then list the first 12.",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(include_thoughts=True)
),
)
u = resp.usage_metadata
print("Thinking tokens:", u.thoughts_token_count)
print("Answer tokens: ", u.candidates_token_count)
print("Prompt tokens: ", u.prompt_token_count)
Example output:
Thinking tokens: 612
Answer tokens: 188
Prompt tokens: 17
On the Interactions API the same figure lives at interaction.usage.total_thought_tokens. If a task is simple, paying for 600 thinking tokens is waste — which is what the depth controls in the next section are for.
Step 6 — Thought signatures and multi-turn continuity
Every thought also carries a thought signature: an encrypted token that captures the model's internal reasoning state. The Gemini API is stateless, so signatures are how reasoning survives from one turn to the next. Get this wrong and follow-up turns lose the thread.
The good news: with the google-genai SDK you mostly do not touch them. The SDK re-attaches signatures for you. You only handle them manually in three situations — you edit conversation history before resending it, you call the raw REST endpoint, or you use function calling (where resending the signed parts is required).
- generateContent, SDK, normal chat: signatures are automatic. Do nothing.
- generateContent, function calling: return the entire response (all parts, signatures included) on the next turn. Never merge a signed part with an unsigned one, and never concatenate signed parts.
- Interactions API, stateful mode (recommended): set
store=trueand passprevious_interaction_idon later turns. The server holds all thought blocks and signatures for you. - Interactions API, stateless mode: you resend the full history yourself, so you must resend every
thoughtblock exactly as received — including built-in tool result signatures like Google Search.
The stateful Interactions pattern is the lowest-effort correct option:
first = client.interactions.create(
model="gemini-3-flash-preview",
input="Plan a 3-step proof that sqrt(2) is irrational.",
generation_config={"thinking_summaries": "auto"},
store=True, # server keeps reasoning state
)
followup = client.interactions.create(
model="gemini-3-flash-preview",
input="Now write step 1 in full.",
previous_interaction_id=first.id, # reasoning continuity, no manual signatures
generation_config={"thinking_summaries": "auto"},
)
print(followup.output_text)
Worked example: a reusable reasoning auditor
Let's combine everything into one helper you can drop into a project. It runs a prompt on a thinking model, returns the answer, the captured reasoning summary, and the token accounting, so every reasoning-heavy call in your app is observable and cost-aware.
from google import genai
from google.genai import types
from dataclasses import dataclass
client = genai.Client()
@dataclass
class AuditedResult:
answer: str
reasoning: str
thinking_tokens: int
answer_tokens: int
def ask_with_audit(prompt: str, model: str = "gemini-2.5-pro") -> AuditedResult:
resp = client.models.generate_content(
model=model,
contents=prompt,
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(include_thoughts=True)
),
)
reasoning, answer = [], []
for part in resp.candidates[0].content.parts:
if not part.text:
continue
(reasoning if part.thought else answer).append(part.text)
u = resp.usage_metadata
return AuditedResult(
answer="".join(answer).strip(),
reasoning="".join(reasoning).strip(),
# thoughts_token_count can be None when the model barely thinks
thinking_tokens=u.thoughts_token_count or 0,
answer_tokens=u.candidates_token_count or 0,
)
r = ask_with_audit(
"A train leaves at 9:00 going 60 km/h. Another leaves the same "
"station at 9:40 going 90 km/h on the same track. When does the "
"second catch the first?"
)
print("ANSWER:", r.answer)
print("WHY :", r.reasoning[:240], "...")
print(f"COST : {r.thinking_tokens} thinking + {r.answer_tokens} answer tokens")
Example output:
ANSWER: The second train catches the first at 11:00, 120 km from the station.
WHY : **Setting up the gap** The first train has a 40-minute head start
at 60 km/h, so it is 40 km ahead when the second departs. **Closing speed**
The second gains 90 - 60 = 30 km/h, so it needs 40 / 30 hours = 80 minutes ...
COST : 437 thinking + 96 answer tokens
Now every call logs why the model answered the way it did and what that reasoning cost. When an answer is wrong, you read r.reasoning and usually see the exact bad assumption — far faster than re-prompting blindly.
Control how hard the model thinks
Auditing tells you how much reasoning happened. Two parameters let you cap it. They differ by model generation, and mixing them up is the single most common mistake.
Gemini 2.5 series uses thinking_budget (a token count). Gemini 3 series uses thinking_level (minimal, low, medium, high). Passing thinking_budget to a Gemini 3 Pro model is accepted for backwards compatibility but can produce unexpected behavior, so match the parameter to the model.
# Gemini 2.5: budget in tokens. -1 = dynamic, 0 = off (where allowed).
cfg_25 = types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_budget=1024)
)
# Gemini 3: discrete levels instead of a token count.
cfg_3 = types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_level="low")
)
| Model | Depth control | Range / values | Can turn off? |
|---|---|---|---|
| Gemini 2.5 Pro | thinking_budget | 128 to 32768 (default -1 dynamic) | No |
| Gemini 2.5 Flash | thinking_budget | 0 to 24576 (default -1 dynamic) | Yes (0) |
| Gemini 2.5 Flash-Lite | thinking_budget | 512 to 24576 | Yes (0) |
| Gemini 3 Flash | thinking_level | minimal / low / medium / high | No (use minimal) |
| Gemini 3.1 Pro | thinking_level | low / medium / high | No |
Common pitfalls
- Expecting raw chain of thought. Summaries are condensed digests, not the verbatim reasoning. Do not parse them as ground truth or build brittle logic that assumes a fixed format — the wording changes every run.
- Assuming a summary always exists. A thought block can contain only a signature and no summary — on simple prompts, with
thinking_summaries: "none", or for non-text thought content. Always guard for emptysummary/parts or your loop will crash. - Billing shock. You pay for full thinking tokens, not the short summary. A one-line answer can hide hundreds of thinking tokens. Log
thoughts_token_countand cap depth on easy tasks. - Dropping thought signatures in stateless mode. If you manage history yourself or hit raw REST, you must resend every thought block exactly as received. Stripping them breaks multi-turn reasoning and function calling.
- Merging or concatenating signed parts. Never glue a signed part to an unsigned one, and never concatenate two signed parts. Return whole response parts intact.
- Wrong knob for the model.
thinking_budgetis a 2.5 concept;thinking_levelis the 3.x concept. Using the wrong one is silently accepted but can degrade quality. - Trying to disable thinking on 2.5 Pro. You cannot set the budget to 0 on 2.5 Pro. If you need a no-think path, route those requests to 2.5 Flash (budget 0) or a Gemini 3 model at
minimal.
Quick reference
| Goal | generateContent API | Interactions API |
|---|---|---|
| See reasoning | ThinkingConfig(include_thoughts=True) | generation_config={'thinking_summaries':'auto'} |
| Read summary | part.thought == True -> part.text | step.type=='thought' -> step.summary[].text |
| Read answer | part.thought == False -> part.text | step.type=='model_output' -> step.content[].text |
| Thinking-token count | usage_metadata.thoughts_token_count | usage.total_thought_tokens |
| Cap depth (2.5) | ThinkingConfig(thinking_budget=N) | generation_config={'thinking_budget':N} |
| Cap depth (3.x) | ThinkingConfig(thinking_level='low') | generation_config={'thinking_level':'low'} |
| Multi-turn continuity | SDK auto; resend parts if editing history | store=True + previous_interaction_id |
Next steps
- Wire
ask_with_auditinto your logging so every reasoning call records its summary and token cost. - Combine thinking with function calling and watch how signatures flow through tool turns — this is where signature handling stops being optional.
- A/B two
thinking_budgetvalues on your hardest prompts and compare accuracy against thinking-token cost to find your sweet spot. - Move new projects to the Interactions API in stateful mode so reasoning state is server-managed.
- Read the official thinking guide at ai.google.dev/gemini-api/docs/thinking for the latest model support table.
Deep Think made Gemini's reasoning better. Thought summaries and signatures make that reasoning yours to inspect — debuggable, auditable, and budgetable. Turn them on once and you stop guessing why a model said what it said.
Comments
Be the first to comment
Found this useful?
Get new AI guides for builders by email. Free.
Join 3,605 newsletter subscribers.