Sub topic 4
Reasoning tokens: hidden, billed and counted
This chapter assumes you have called an LLM API from code and can read Python. It also assumes you know what tokens, context windows and a maximum output setting are. The previous chapters covered what a reasoning model is. This chapter covers what its thinking costs you in tokens, where those tokens appear in the API response, and which of your limits they use up.
What a reasoning token is
A reasoning token is a token the model generates while working toward an answer, before it writes the part you asked for. The model produces these tokens the same way it produces any other output, one at a time. The difference is what happens to them afterward:
- They are not part of the final answer text.
- Most APIs do not return them in full. You get either nothing or a summary (see "Seeing the reasoning" later in this tutorial).
- They are still generated, so you pay for them and wait for them.
A reasoning model's response therefore has two parts. The first is the reasoning, which is mostly hidden. The second is the visible answer. Both are output tokens as far as the provider's meter is concerned.
Hidden does not mean free
Three things follow from the fact that reasoning tokens are output tokens.
- They are billed. Providers charge output tokens at the output rate, which is usually several times the input rate. Reasoning tokens are charged at that rate even though you never see most of them.
- They take time. Generation is sequential. Each reasoning token adds roughly the same delay as an answer token. A response with 3,000 reasoning tokens and a 50-token answer takes about as long as generating 3,050 tokens.
- They count toward limits. A maximum-output setting caps reasoning and answer together. The next chapters cover output limits in detail. For now, remember that a low cap can be used up by reasoning, which leaves no room for the answer.
A short answer does not imply a cheap request. A one-word reply can sit on top of thousands of reasoning tokens.
Reading the counts from the API
The two main APIs report reasoning differently.
| Provider and API | Where to read it | Included in the output total? | What you can see |
|---|---|---|---|
| OpenAI Responses API | `usage.output_tokens_details.reasoning_tokens` | Yes, inside `usage.output_tokens` | The answer. Reasoning summaries only if you request them. |
| Anthropic Messages API | `usage.output_tokens` | Yes, thinking and answer are one total | Thinking blocks in `response.content` |
The OpenAI response gives you a separate field for the reasoning count, so you can compute the split directly. The following script sends a small question and prints the split.
from openai import OpenAI
client = OpenAI()
def reasoning_share(usage):
"""Return (reasoning_tokens, answer_tokens, share_of_output)."""
total = usage.output_tokens
reasoning = usage.output_tokens_details.reasoning_tokens
answer = total - reasoning
share = reasoning / total if total else 0.0
return reasoning, answer, share
response = client.responses.create(
model="o4-mini",
reasoning={"effort": "low"},
input="A train leaves at 14:10 and arrives at 17:45. How long is the trip?",
)
reasoning, answer, share = reasoning_share(response.usage)
print(response.output_text)
print("reasoning tokens:", reasoning)
print("answer tokens:", answer)
print("total output tokens:", response.usage.output_tokens)
print(f"share spent on reasoning: {share:.0%}")Run it a few times. The reasoning count changes between runs, even for the same prompt, because the model's thinking is sampled like any other text. Treat one measurement as a single sample, not a fixed property of the prompt.
With the Anthropic API, you enable thinking and the response carries thinking blocks next to the text block. The usage object reports one output total.
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)
print("input tokens:", response.usage.input_tokens)
print("output tokens (thinking + answer):", response.usage.output_tokens)Here max_tokens must be larger than budget_tokens. The next chapters explain why.
Do not trust your own token counting
It is tempting to count tokens in the returned text with a tokenizer and compare that with the bill. That works for the answer, but it does not work for reasoning. Three cases cause mismatches:
- Reasoning that is never returned. OpenAI reasoning models do not return their raw reasoning. There is no text to count, so the
reasoning_tokensfield is the only record. - Summaries. When the API returns a summary, the summary is shorter than the reasoning it describes.
- Encrypted or redacted content. Some responses include thinking content that is encrypted or redacted. It is returned so you can pass it back in later turns, but you cannot read it.
The rule is simple. Log usage from every response and read counts from there. Count text yourself only for text you wrote, such as your prompt.
A worked cost example
Suppose a response reports 700 output tokens, and 640 of them are reasoning tokens. The answer is 60 tokens. Prices change, so this example uses a placeholder rate of 4.00 currency units per million output tokens. Substitute your provider's current price.
def output_cost(output_tokens, price_per_million):
return output_tokens / 1_000_000 * price_per_million
PRICE = 4.00 # placeholder: replace with your model's output price per 1M tokens
billed = output_cost(700, PRICE)
visible_only = output_cost(60, PRICE)
print(f"billed: {billed:.5f}")
print(f"visible only: {visible_only:.5f}")
print(f"ratio: {billed / visible_only:.1f}x")The script prints a billed cost of 0.00280, a visible-only cost of 0.00024, and a ratio of 11.7x. If you estimated cost from the length of the answer you could see, you would be low by a factor of almost twelve. At a thousand requests per day, that gap becomes a real line item.
The input side matters less here, but it is not zero. Your prompt is billed as input as usual. Some providers also bill a reduced rate for cached input, which is unrelated to reasoning.
Reasoning tokens across turns
In a conversation, each new request sends earlier messages back as input. Reasoning tokens from earlier turns behave differently from answer tokens:
- With plain chat turns, the providers generally do not carry the old reasoning forward as input. The earlier turn's reasoning was billed once as output, and it does not keep re-billing as input on every later turn.
- With tool use, the rules are stricter. If the model reasons, calls a tool, and you send the tool result, the API may require you to pass the reasoning items (OpenAI) or thinking blocks (Anthropic) from that turn back unchanged. In that case they do count as input on the follow-up request.
Check the current documentation for the model you use. This area changes between model versions, and a request that drops required thinking blocks can be rejected or can lose reasoning continuity.
Reasoning tokens also occupy the context window while the response is being generated. A prompt that nearly fills the window leaves little room for thinking, even when your output cap is high.
Common mistakes
- Reading
output_textlength as the cost. The visible text is a small part of the output on hard prompts. Readusage. - Setting a low output cap and getting an empty answer. Reasoning uses the cap first. If it runs out, the response can end with reasoning only and no answer text. Check the response status or stop reason before you use the text.
- Comparing runs with one sample. Reasoning length varies per run. Compare averages over a set of cases, as the evaluation chapter shows.
- Assuming zero reasoning means zero cost. On some settings the model may reason very little, but the count is rarely exactly zero. Measure it.
- Logging only the final text. If you do not store
usage, you cannot explain a bill later.
Summary of the working model
- Reasoning tokens are output tokens generated before the visible answer.
- They are billed at the output rate, add latency, and count against the output cap.
- You read counts from
usage. OpenAI gives a dedicated reasoning field. Anthropic gives a combined output total. - The visible text, including a returned summary, can understate what you were charged for.
- The count varies from run to run, so measure over many cases.
Exercise
A request reports output_tokens of 1,500 and reasoning_tokens of 1,350. The answer text you received is 150 tokens long. Your output price is 8.00 per million tokens. (a) What did the output cost? (b) What would you have estimated from the visible answer alone? (c) Why can the second number be wrong even if you count the answer tokens correctly?
Show answer
(a) 1,500 / 1,000,000 x 8.00 = 0.012. (b) 150 / 1,000,000 x 8.00 = 0.0012, which is one tenth of the real cost. (c) Reasoning tokens are billed as output tokens even though they are not in the answer text, so the answer length misses 1,350 billed tokens. The usage object is the reliable source.
Exercise
You switch from the OpenAI example to the Anthropic example and print the number of tokens in the returned thinking text. It is smaller than the thinking share of usage.output_tokens would suggest. Give two reasons this can happen.
Show answer
On Claude 4 models the returned thinking is a summary, and you are billed for the full thinking, so the visible text is shorter than what was generated. The returned content can also be redacted or encrypted, which hides tokens that were still generated and billed. In both cases the usage totals are authoritative.