Sub topic 10
Reasoning tokens and hidden output
This chapter assumes you can read basic Python, have called an LLM through a chat or completion API, and know that providers bill input and output tokens at separate per-million-token prices. It builds on the output limit and the combined input-plus-output budget from earlier chapters.
What hidden output is
Some models think before they answer. They generate a long chain of intermediate text, called reasoning tokens (or thinking tokens), and then write the answer you see. Depending on the provider, the reasoning text may be shown only as a short summary, or not shown at all.
The key point is that reasoning tokens are output tokens. The model generates them one at a time, just like the visible answer. This has three consequences:
- They are billed at the output price, even if you never see them.
- They count toward the output limit and the context window.
- They can make a short visible answer cost much more than its length suggests.
Why the visible answer misleads you
Suppose you ask a reasoning model a short math question. The answer is "42", about one token. If you estimate cost from the visible text, you would predict almost no output cost. But the model may have spent 1,500 reasoning tokens to get there.
The usage data from the API is the reliable source. Many APIs report reasoning tokens as a detail inside the output count. The exact field names differ by provider, so check your provider's documentation. Some report the total output tokens with a separate breakdown, and others fold everything into one number.
def split_output(total_output_tokens, reasoning_tokens):
visible = total_output_tokens - reasoning_tokens
return visible, reasoning_tokens
def output_cost(total_output_tokens, output_price_per_million):
return total_output_tokens * output_price_per_million / 1_000_000
# Placeholder numbers, not real rates.
total = 1501
reasoning = 1500
visible, hidden = split_output(total, reasoning)
print(visible, "visible token,", hidden, "hidden tokens")
print(f"${output_cost(total, 15.0):.4f}") # $0.0225Here the answer is one token, yet the output cost is $0.0225, almost entirely from hidden reasoning. If you had counted only the visible text, you would have estimated about $0.000015.
Effects on the token budget
Because reasoning tokens share the output limit, a low maximum can cause a problem. If the model spends the whole allowance on reasoning, nothing is left for the answer. You may get an empty reply or a truncated one, and you still pay for every token generated.
Many providers let you control how much reasoning the model does. Common controls are a reasoning effort level (such as low, medium, or high) or a token budget for thinking. Lower settings are cheaper and faster. Higher settings tend to help on hard problems such as multi-step logic or code with subtle bugs.
Reasoning across turns
In a multi-turn chat, providers differ on whether earlier reasoning is kept in the history. Many drop it from the next request, so it does not grow your input. Some features, such as tool use with extended thinking, may require you to pass the reasoning back. When reasoning is resent, it counts as input on every later turn. Read your provider's rules before assuming either behavior.
Deciding when to use it
| Task | Reasoning helps? | Cost effect |
|---|---|---|
| Classifying short text | Rarely | Adds cost with little gain |
| Extracting fields from a document | Rarely | Adds cost with little gain |
| Multi-step math or planning | Often | Large hidden output |
| Debugging complex code | Often | Large hidden output |
A practical approach: start without reasoning or at the lowest effort, measure quality, and raise the setting only if results are not good enough. Always check the usage data on real calls, since the number of reasoning tokens varies from one request to the next.
Exercise
A reasoning model returns a 40-token answer. The usage data reports 1,240 total output tokens. The output price is $10 per million tokens. How many tokens were hidden reasoning, and what did the output cost?
Show answer
Hidden reasoning was 1,240 - 40 = 1,200 tokens. All 1,240 output tokens are billed: 1,240 x 10 / 1,000,000 = $0.0124.
Exercise
You set the maximum output tokens to 500 on a reasoning model, and the reply comes back empty. Give a likely cause and one fix.
Show answer
The model probably used all 500 tokens on reasoning, leaving none for the answer. Raise the maximum, or lower the reasoning effort or thinking budget.