Sub topic 10
Reasoning Tokens and Hidden Output
This chapter assumes you have read the earlier chapters on output limits and per-token pricing. You should know that input and output tokens are billed at different rates. You should also know that a context window has to hold the prompt and the reply together. The code uses basic Python.
Some models produce tokens you never see in the answer. These tokens still count against your output limit, and they still appear on your bill. This chapter covers where they come from, how to find them in the usage data, and how to budget for them.
What reasoning tokens are
A reasoning model works through a problem before it answers. It generates intermediate text, such as plans, partial calculations, and checks of its own work. Providers call this text reasoning, thinking, or a chain of thought. The model then writes the final answer.
The intermediate text is made of tokens, just like the answer. The model produces it with the same process and pays for it with the same compute. Providers therefore bill it as output tokens.
The details differ by provider and by model:
- Some APIs return a summary of the reasoning, some return the full text, and some return nothing.
- Some APIs let you set a reasoning effort level or a thinking budget. Others decide on their own how much to reason.
- Hidden output can also include other tokens you did not ask for in the visible text. Examples are tool-call arguments and internal formatting.
The rule that holds across providers is this. The billed output token count can be much larger than the number of tokens in the text you receive.
Why the visible text misleads you
Suppose you count tokens in the reply with a tokenizer library, as you did in the counting chapter. You might expect that number to match the output tokens on the invoice. For a model that does not reason, it will come close. For a reasoning model, it can be far off.
| Quantity | Where you see it | Includes reasoning? |
|---|---|---|
| Tokens in the reply text | Your own tokenizer count | No |
| Output tokens in usage data | API response | Yes |
| Output tokens on the bill | Invoice or dashboard | Yes |
| Output limit you set | Request parameter | Usually yes |
The first row is the only one that ignores reasoning. If you estimate cost from the reply text alone, you will undercount.
Where hidden tokens sit in the budget
The output limit is a cap on everything the model generates for that call. For most reasoning models, the cap covers reasoning and the visible answer together. The context window, which must hold input plus all output, also counts both.
This leads to a failure mode that surprises many people. Say you set the output cap to 1,000 tokens and ask a hard question. The model may use all 1,000 tokens on reasoning and stop. The response then arrives with an empty or cut-off answer. The API usually signals this with a finish reason such as length or max_tokens, but the exact name varies. You are billed for all 1,000 tokens even though you got nothing useful.
Reading reasoning tokens from usage data
The usage chapter showed that API responses report input and output token counts. Reasoning models usually add a breakdown of the output count. The field names differ by provider. A typical shape looks like this:
usage = {
"input_tokens": 2000,
"output_tokens": 2000,
"output_tokens_details": {"reasoning_tokens": 1700},
}
def split_output(usage):
"""Return (reasoning_tokens, visible_tokens) from a usage dict."""
total = usage["output_tokens"]
details = usage.get("output_tokens_details", {})
reasoning = details.get("reasoning_tokens", 0)
return reasoning, total - reasoning
reasoning, visible = split_output(usage)
print(reasoning, "reasoning tokens")
print(visible, "visible tokens")This prints 1700 reasoning tokens and 300 visible tokens. The dictionary above is an example of the shape, not a real provider's schema. Check your provider's documentation for the actual names. Some providers report only the total and give no breakdown. In that case you can estimate the hidden part by subtracting your own tokenizer count of the visible reply from the reported output total. The result is approximate, because tokenizers differ between model families.
What reasoning does to cost
Reasoning tokens are billed at the output price, which is usually several times the input price. That makes them the most expensive kind of token in most calls.
Use the placeholder prices from the earlier chapters: $3 per million input tokens and $15 per million output tokens. Take a call with 2,000 input tokens and a 300-token visible answer. First, price it as if the model did not reason:
- Input: 2,000 × 3 = 6,000
- Output: 300 × 15 = 4,500
- Total: 10,500 divided by 1,000,000 = $0.0105
Now say the model also used 1,700 reasoning tokens. Output becomes 2,000 tokens:
- Input: 2,000 × 3 = 6,000
- Output: 2,000 × 15 = 30,000
- Total: 36,000 divided by 1,000,000 = $0.0360
The same prompt and the same answer now cost about 3.4 times as much. Nothing in the visible text changed.
def call_cost(usage, input_price_per_million, output_price_per_million):
"""Cost of one call. output_tokens already includes reasoning."""
return (
usage["input_tokens"] * input_price_per_million
+ usage["output_tokens"] * output_price_per_million
) / 1_000_000
usage = {
"input_tokens": 2000,
"output_tokens": 2000,
"output_tokens_details": {"reasoning_tokens": 1700},
}
# Placeholder prices in dollars per million tokens, not real rates.
print(f"${call_cost(usage, 3.0, 15.0):.4f}") # $0.0360This function assumes output_tokens already includes reasoning. If your provider reports reasoning as a separate field that is not in the total, add it before pricing.
Budgeting before the call
You cannot know the reasoning length in advance, but you can bound it. The output cap gives a worst case, and you can check both limits before sending the request.
def worst_case(input_tokens, max_output_tokens, context_window,
input_price_per_million, output_price_per_million):
"""Return (fits, max_cost) for a call that uses the full output cap."""
fits = input_tokens + max_output_tokens <= context_window
max_cost = (
input_tokens * input_price_per_million
+ max_output_tokens * output_price_per_million
) / 1_000_000
return fits, max_cost
fits, max_cost = worst_case(2000, 4000, 8000, 3.0, 15.0)
print(fits) # True
print(f"${max_cost:.4f}") # $0.0660This reports the most the call can cost with a 4,000-token cap. A typical call will cost less. The ceiling is still useful for setting spending alerts and for deciding whether the cap is sensible.
Two other effects matter for planning:
- Variance. Reasoning length depends on how hard the model finds the question. Two similar prompts can differ by a factor of ten in output tokens. Budget with percentiles from real traffic, not with one sample.
- History. Reasoning from earlier turns is generally not part of the history you resend, so it does not compound the way visible replies do. Some providers do require you to pass reasoning blocks back in certain cases, such as multi-step tool use. In those cases it counts as input tokens on later calls. Read your provider's rules for this.
Controlling reasoning spend
You have a few levers, and they trade quality against cost:
- Choose whether to use a reasoning model at all. Simple tasks such as extraction, classification, and short rewrites rarely benefit from reasoning. A non-reasoning model is cheaper and faster for them.
- Set the reasoning effort or thinking budget, where the API offers one. A lower setting reduces typical reasoning length. It may also reduce accuracy on hard problems.
- Set an output cap with headroom. Allow room for reasoning plus the answer you want. Then watch the finish reason for truncation.
- Ask for concise answers. This shortens the visible part only. It rarely changes how much the model reasons, so it is the weakest lever.
- Measure. Log the reasoning count from each response. Compare cost per task across settings on a sample of your real prompts.
Common mistakes
- Estimating cost from the visible reply length. This undercounts on reasoning models.
- Setting a tight output cap and getting empty answers. The reasoning consumed the cap.
- Assuming reasoning text is returned. Many APIs withhold it or return only a summary, yet you still pay for the full amount.
- Assuming the usage breakdown is the same across providers. Field names, and whether totals include reasoning, differ.
- Comparing per-token prices alone when choosing between models. A model with a lower price that reasons for three times as long can cost more per task.
Exercise
A call sends 5,000 input tokens. The usage data reports 3,200 output tokens, of which 2,600 are reasoning tokens. Prices are $2 per million input tokens and $10 per million output tokens. (a) How many tokens are in the visible answer? (b) What did the call cost? (c) What would it have cost if the model had produced the same visible answer with no reasoning?
Show answer
(a) 3,200 − 2,600 = 600 visible tokens. (b) Input: 5,000 × 2 = 10,000. Output: 3,200 × 10 = 32,000. Total 42,000 divided by 1,000,000 = $0.042. (c) Output would be 600 × 10 = 6,000, so the total is 16,000 divided by 1,000,000 = $0.016. The reasoning added $0.026, which is 62% of the bill.
Exercise
You set the output cap to 1,500 tokens on a reasoning model. A request returns an empty answer and a finish reason of length, and you are billed for 1,500 output tokens. What most likely happened, and what are two ways to fix it?
Show answer
The model spent the whole 1,500-token cap on reasoning and had no tokens left for the answer. Fixes: raise the output cap to leave room for both reasoning and the answer, or lower the reasoning effort or thinking budget so the model reasons less. Using a non-reasoning model for the task is a third option if the task is simple.