Sub topic 4
Reasoning tokens: hidden, billed and counted
This chapter assumes you have called an LLM API from Python, know what tokens, context windows and max output tokens are, and can read short Python scripts. It covers what reasoning tokens are, how they show up in usage data, and where they surprise people.
What reasoning tokens are
A reasoning model writes an internal chain of thought before its final answer. Each token of that chain of thought is a reasoning token. The model generates these tokens the same way it generates answer tokens, so they take the same compute and time.
Three facts define them:
- Hidden. Most APIs do not return the raw reasoning. You may get a summary or a thinking block, covered in a later chapter, but not always the full text.
- Billed. Reasoning tokens are charged at the output token rate, even if you never see them.
- Counted. They count toward the output total and toward the output limit.
Where the tokens go
Your request has input tokens (the prompt). The response has output tokens, and those split into reasoning tokens and visible answer tokens.
Reading reasoning tokens from usage
The usage object in the response reports how many output tokens were reasoning. This example uses the OpenAI Responses API.
from openai import OpenAI
client = OpenAI()
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?",
)
print(response.output_text)
print("reasoning tokens:", response.usage.output_tokens_details.reasoning_tokens)
print("total output tokens:", response.usage.output_tokens)The answer is short, for example "3 hours 35 minutes". The total output tokens will often be much larger than the answer's length. The gap is the reasoning. Here, output_tokens already includes reasoning_tokens. Do not add them together, or you will count the reasoning twice.
For Anthropic models the thinking tokens are also part of the output tokens. Anthropic bills the full thinking, even when the API returns only a summary. Field names differ between providers and change over time, so check the current usage fields in your provider's documentation.
A worked cost example
Suppose a request uses 200 input tokens and returns 1,500 output tokens. The usage data says 1,350 of those were reasoning. The visible answer is about 150 tokens.
| Part | Tokens | Billed as |
|---|---|---|
| Input | 200 | Input rate |
| Reasoning | 1,350 | Output rate |
| Visible answer | 150 | Output rate |
You pay the output rate on 1,500 tokens, although you can read only 150 of them. Reasoning is 90% of the output bill in this case. If you estimate cost from the length of the visible text alone, you will underestimate it by a large factor.
Common errors
- Budgeting from the visible answer. Estimate cost from
output_tokensin the usage data, not from the length of the text you received. - Double counting. Treat reasoning tokens as a subset of output tokens, not an extra category on top of them.
- Assuming a fixed amount. Reasoning length varies with task difficulty, effort setting and prompt. Two similar requests can differ by several times.
- Ignoring the limit. Reasoning tokens count toward the maximum output setting. If reasoning uses up the limit, the answer can come back empty or cut off. The next chapters cover how to size that limit.
Logging reasoning share
A small helper that records the reasoning share makes these effects visible in your own logs.
def reasoning_share(reasoning_tokens, output_tokens):
"""Return the fraction of output tokens spent on reasoning."""
if output_tokens == 0:
return 0.0
return reasoning_tokens / output_tokens
print(reasoning_share(1350, 1500))This prints 0.9. Track it over many requests. A share that stays near zero on hard tasks may mean the effort is too low. A share near one on easy tasks points to wasted spend.
Exercise
A request returns usage data with outputtokens = 2,400, of which reasoningtokens = 2,100. The provider charges $10 per million output tokens. What did the output cost, and how many tokens did the user actually see in the answer?
Show answer
Output cost is 2,400 tokens at $10 per million, which is $0.024. The reasoning tokens are already included in the 2,400, so you do not add them again. The visible answer is 2,400 − 2,100 = 300 tokens, and the user paid for all 2,400.
Exercise
Why can a response with a very short visible answer still be expensive?
Show answer
The model may have spent most of its output tokens on hidden reasoning. Those tokens are billed at the output rate and counted in the output total, so a short answer can sit on top of a long chain of thought.