Sub topic 8
Seeing the reasoning: summaries and thinking blocks
This chapter assumes you can call an LLM API from Python, know what tokens and max output tokens are, and have read the earlier chapters on reasoning tokens, effort levels and thinking budgets.
What you can see and what you pay for
A reasoning model produces reasoning tokens before its final answer. Providers differ in how much of that reasoning they show you. You are billed for all of the reasoning tokens, whether or not you see them.
| Provider | What the API returns | Where it appears |
|---|---|---|
| OpenAI (Responses API) | Raw reasoning is not returned. You can ask for a summary. | A `reasoning` item in `response.output` |
| Anthropic (Messages API) | Thinking blocks. On Claude 4 models these contain a summary of the thinking. | Blocks with `type == "thinking"` in `response.content` |
The consequence is that visible reasoning is often shorter than the reasoning you pay for. If you count the characters in a summary and compare them to the billed reasoning tokens, the two numbers will not match.
Anthropic: thinking blocks
When extended thinking is enabled, the response content list holds one or more thinking blocks followed by text blocks. The code below enables thinking and sorts the blocks.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=4096,
thinking={"type": "enabled", "budget_tokens": 2000},
messages=[
{"role": "user", "content": "Is 3599 a prime number? Explain briefly."}
],
)
for block in response.content:
if block.type == "thinking":
print("[thinking]", block.thinking)
elif block.type == "text":
print("[answer]", block.text)Keep these points in mind:
max_tokensmust be larger thanbudget_tokens, because thinking counts toward the output limit.- Each thinking block carries a
signaturefield. It is an encrypted value that lets the API check the block when you send it back. Do not edit it. - A block of type
redacted_thinkingcan appear when the thinking was flagged by safety systems. It is encrypted and has no readable text. Your code should not assume every block has athinkingattribute. - Billing is based on the full thinking the model produced, not on the summary you see.
Passing thinking blocks back
In a multi-turn conversation that uses tools, return the assistant's thinking blocks unchanged along with its tool calls. The API uses them to let the model continue its reasoning after the tool result. If you drop or alter them, the request can fail or the model can lose its line of thought.
OpenAI: reasoning summaries
OpenAI keeps the raw chain of thought private. The reasoning parameter accepts a summary field that requests a readable summary. Summaries can require organization verification, so a request may be rejected if your account is not eligible.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="o4-mini",
reasoning={"effort": "low", "summary": "auto"},
input="A train leaves at 14:10 and arrives at 17:45. How long is the trip?",
)
for item in response.output:
if item.type == "reasoning":
for part in item.summary:
print("[summary]", part.text)
print("[answer]", response.output_text)
print("reasoning tokens:", response.usage.output_tokens_details.reasoning_tokens)
print("total output tokens:", response.usage.output_tokens)The summary list can be empty. For an easy question the model may reason very little, and there is nothing to summarize. Loop over the list instead of indexing summary[0].
What to do with the visible reasoning
Summaries and thinking blocks are useful for debugging. If an answer is wrong, the summary often shows which assumption went off track. They are also useful when you tune prompts, because you can see whether the model used the facts you supplied.
Treat them with caution in two ways:
- Not a faithful record. A summary is a condensed account. It may omit steps, and the model's stated reasoning does not always match what drove its answer. Use it as a clue, not as proof.
- Not always for end users. Showing reasoning in a product can expose internal instructions or confuse readers. Decide on purpose whether to display it, and log it for developers instead when in doubt.
Also remember that summaries do not lower your bill. If you want fewer reasoning tokens, lower the effort level or the thinking budget.
Exercise
Your Anthropic request returns a response in which response.content[0].thinking raises an AttributeError. Name one likely cause and a safe way to write the loop.
Show answer
The first block is probably a redacted_thinking block, or a block of another type, which has no thinking attribute. Loop over response.content, check block.type ("thinking", "redacted_thinking", "text"), and read block.thinking only when the type is "thinking".
Exercise
A colleague sees that the visible summary is about 80 tokens long, but reasoning_tokens reports 1,500. Is something wrong with the billing?
Show answer
No. You are billed for all reasoning tokens the model generated. The summary is a condensed view of that reasoning, so it is much shorter than the billed amount.