Sub topic 9
Reasoning Tokens and When Extra Thinking Pays Off
This chapter assumes you know how input and output tokens are priced, that output tokens usually cost more per token than input tokens, and that you can read short Python functions.
What reasoning tokens are
Some models can "think" before they answer. They write out intermediate steps first, then produce the visible reply. These intermediate tokens are called reasoning tokens (or thinking tokens).
Providers generally bill reasoning tokens at the output rate, even when the thinking is hidden or summarized in the response. Check your provider's docs for how they appear in usage data. Some report them as a separate field, and others fold them into the output count.
This matters because output is the expensive side of the bill. A short answer with a long hidden thought can cost far more than the answer's length suggests.
def request_cost(usage, price):
"""Cost in USD. Prices are USD per million tokens."""
return (
usage["input_tokens"] * price["input"]
+ usage["output_tokens"] * price["output"]
) / 1_000_000
# Placeholder prices, not real rates.
price = {"input": 3.0, "output": 15.0}
no_thinking = {"input_tokens": 20_000, "output_tokens": 500}
with_thinking = {"input_tokens": 20_000, "output_tokens": 500 + 8_000}
print(request_cost(no_thinking, price)) # 0.0675
print(request_cost(with_thinking, price)) # 0.1875The visible answer is the same length in both cases. Thinking raises the cost of this request from about 6.8 cents to about 18.8 cents, a factor of nearly 3.
Why it compounds in an agent loop
An agent loop makes many requests. If every step uses a large thinking budget, the extra output cost is paid on every turn. Thinking tokens from earlier turns are often dropped from later context, but this varies by provider, so confirm it before assuming it. Where they are kept, they also add to the input resent on each later turn.
The diagram below shows where the thinking tokens sit within one step.
When extra thinking pays off
Thinking helps when the step needs several dependent decisions. It helps less when the answer is mostly lookup or mechanical edits.
| Step type | Extra thinking | Reason |
|---|---|---|
| Planning a multi-file change | Usually worth it | A wrong plan wastes every later turn |
| Debugging an unclear failure | Often worth it | Needs hypotheses and elimination |
| Applying a specified edit | Rarely worth it | The decision is already made |
| Summarizing tool output | Rarely worth it | Compression, not reasoning |
| Running tests and reading the result | Rarely worth it | Mechanical |
The rule is to spend thinking where one error is expensive. A bad plan costs many turns. A bad one-line edit is usually caught by the next test run.
Setting a budget for thinking
Most providers let you turn thinking on or off, or cap it with a budget or an effort level. The parameter names differ, so use your provider's documentation. A simple policy keeps the setting next to your routing table.
THINKING_BUDGET = {
"plan": 8_000,
"debug": 4_000,
"edit": 0,
"run_tests": 0,
}
def thinking_budget(step_kind):
return THINKING_BUDGET.get(step_kind, 0)
print(thinking_budget("plan")) # 8000
print(thinking_budget("other")) # 0Defaulting to zero means a new step type costs nothing extra until you decide it deserves thinking.
Common errors
- Turning thinking on globally because one hard step needed it.
- Judging cost by visible output length, which hides the reasoning tokens.
- Comparing a thinking model to a non-thinking model on price per token alone. Compare cost per resolved task instead, as covered later in this tutorial.
- Assuming thinking tokens are free of latency. They are generated before the answer, so they add waiting time.
Exercise
A step sends 30,000 input tokens and produces 600 visible output tokens. With thinking enabled it also produces 6,000 reasoning tokens. Using placeholder prices of 3.0 USD input and 15.0 USD output per million tokens, how much more does the thinking version cost?
Show answer
Without thinking: 30,000 × 3.0 / 1M = 0.09, plus 600 × 15.0 / 1M = 0.009, total 0.099 USD. With thinking: output is 6,600 tokens, so 6,600 × 15.0 / 1M = 0.099, total 0.189 USD. The thinking version costs 0.09 USD more, which is almost double.
Exercise
Name one step in a coding agent where you would enable a thinking budget and one where you would not. Give the reason for each.
Show answer
Enable it for planning a multi-file change, because a wrong plan wastes every later turn. Leave it off for running tests, because reading a pass or fail result is mechanical and the extra output tokens add cost and latency without improving the outcome.