Sub topic 2
Spending Compute at Inference Time
This chapter assumes you have called an LLM API from code, know what tokens, context windows and max output tokens are, and can read short Python programs. It follows the chapter on step-by-step reasoning and comes before the chapter that defines reasoning models.
Two places to spend compute
A language model uses compute in two phases.
- Training happens once, before release. The provider spends a very large amount of compute to set the model's weights. You never pay for it directly, and it is the same for every request.
- Inference happens each time you send a request. The model reads your prompt and generates tokens. You pay for this compute, per request, through token prices and waiting time.
For years, most progress in model quality came from spending more on training: bigger models, more data, longer runs. Test-time compute is the other lever. It means spending more compute while answering a particular question, so that a hard question gets more work than an easy one. The name comes from "test time", the machine learning term for the moment a trained model is used on new inputs. "Inference-time compute" means the same thing.
| Row | Training compute | Test-time compute |
|---|---|---|
| When it is spent | Once, before release | On every request |
| Who decides the amount | The model provider | You, through API settings, and the model itself |
| Who pays | The provider | You, per request |
| Varies by question | No | Yes |
| What it changes | The model's weights | How much work goes into one answer |
The second lever matters because a model that can vary its effort per question is not stuck at a single quality level. You can trade money and time for accuracy, one request at a time.
Why more tokens can improve an answer
A transformer model produces one token per forward pass. A forward pass has a fixed number of layers, so the computation behind each token has a fixed depth. If the model must answer immediately, all the work needed to reach the answer has to fit inside that fixed depth.
Many problems need more serial steps than one pass can hold: multi-digit arithmetic, scheduling puzzles, tracing code, checking a proof. If the model first writes out intermediate results, each written token becomes input to later passes. The output text works as a scratchpad. The model can store partial results, check them, and build on them.
Two consequences follow:
- The number of tokens generated before the final answer sets how much serial computation the model can apply to the problem.
- Those tokens cost the same as any other output tokens, which is why test-time compute shows up in your bill and your latency.
The previous chapter covered chain-of-thought prompting, where you ask a standard model to show its work. Reasoning models take the same idea further. They are trained to produce long, useful chains of intermediate text on their own, without being asked in the prompt. The next chapter covers how they are built.
Ways to spend extra compute
There is more than one way to turn extra inference compute into a better answer. The approaches differ in how they use the extra tokens.
- Longer sequential reasoning. The model writes one long chain: it works through the problem, notices a mistake, backs up and tries another route. This is what reasoning models do, and it is what effort levels and thinking budgets control.
- Parallel sampling with voting. You ask the same question several times and take the most common final answer. This is called self-consistency or majority voting.
- Best-of-n with a checker. You generate several candidate answers and pick the one that a verifier, such as a unit test, a rule, or a scoring model, accepts or ranks highest.
- Draft and revise. One call writes an answer and another call critiques and improves it.
These strategies can be combined. Reasoning model APIs mainly expose the first one, and you can still layer voting or checking on top by making several calls.
A small calculation: voting
Parallel voting is the easiest strategy to analyze, and it shows the shape of the trade-off. Suppose a model answers a question correctly with probability p on each independent sample. You take n samples (use an odd n to avoid ties) and return the majority answer. The chance that the majority is correct is the chance that more than half the samples are correct, which is a binomial sum.
from math import comb
def majority_accuracy(p: float, n: int) -> float:
"""Chance that more than half of n independent samples are correct (n odd)."""
need = n // 2 + 1
return sum(comb(n, k) * p**k * (1 - p) ** (n - k) for k in range(need, n + 1))
for p in (0.6, 0.4):
print(f"single-sample accuracy p={p}")
for n in (1, 5, 15, 51):
print(f" n={n:>3} majority accuracy={majority_accuracy(p, n):.3f} cost={n}x")Run this and compare the two blocks. With p = 0.6, five samples give about 0.683 (the sum is 0.3456 + 0.2592 + 0.07776). Accuracy keeps rising as n grows, but each step costs more and gains less. With p = 0.4, the same procedure gets worse as n grows, because the majority converges on the wrong answer.
What the calculation teaches
Three patterns from the voting example also hold for test-time compute in general.
Cost grows linearly, gains flatten. Doubling the compute doubles the bill. The accuracy gain from each extra unit of compute shrinks as accuracy approaches its ceiling. Reported scaling curves for reasoning models show a similar pattern: accuracy on hard benchmarks improves as the reasoning budget grows, and the curve bends over. Treat this as a rule of thumb, since the exact shape depends on the model and the task.
The starting point matters. Extra compute helps most when the model is sometimes right but not reliably so. If the model is almost always right already, you pay for nothing. If it is almost never right, more thinking rarely fixes it.
Compute cannot supply missing knowledge. Thinking longer does not teach the model a fact it never learned. If you ask for the current price of a product or an internal API's behavior, a long chain of thought will produce a more elaborate guess. Retrieval or tool use addresses that problem, not more reasoning.
Fixed versus adaptive compute
A standard chat model spends roughly the same depth per output token and typically produces a short answer, so the compute for a simple question and a hard one differs little. A reasoning model spends variable compute. It may stop after a few hundred tokens on an easy question and use many thousands on a hard one. This adaptivity is useful, because you do not need to guess in advance how long each problem will take. It also makes the cost of a request unpredictable: the same prompt on the same model can yield different token counts on different runs.
This is why the API controls in later chapters exist. Effort levels and thinking budgets do not set an exact number of tokens. They steer how much the model is likely to think, or cap how much it may think.
What this means for your API calls
Treat test-time compute as a third quantity you tune, next to model choice and prompt design.
- Cost. Reasoning tokens are billed as output tokens. A short visible answer can hide a large bill.
- Latency. Tokens are generated one at a time, so more reasoning means more waiting before the final answer starts.
- Output limit. Reasoning tokens usually count against the maximum output tokens you set. A limit that was generous for a chat model can cut a reasoning model off before it answers.
- Quality. Gains are largest on multi-step problems and small on lookups, rewriting and simple extraction.
The following chapters cover each of these in detail. For now, the working model is: a request has a compute budget that you partly control, and spending it pays off only when the task is hard enough and the model is capable enough to use it.
Common mistakes
- Assuming that more thinking always improves results. Past a point it adds cost and delay without gains, and sometimes the model second-guesses a correct answer.
- Using voting on tasks with no single checkable answer, such as free-form writing, where "the most common answer" has no meaning.
- Ignoring correlated errors and expecting voting to fix a systematic misunderstanding.
- Comparing reasoning and standard models on cost per token only. The cost per request is what matters, and it includes the hidden thinking.
- Judging an effort setting from one or two examples. Outputs vary from run to run, so you need a set of cases, which the final chapter of this tutorial builds.
Exercise
A model answers a yes/no question correctly 55% of the time per sample, with errors that are independent across samples. You use majority voting with 5 samples at 1x cost each. Is the accuracy about 55%, clearly higher, or lower? Then explain why the gain would shrink if the model tends to repeat the same mistake.
Show answer
Compute P(at least 3 of 5 correct) with p = 0.55. P(3) = 10 × 0.55³ × 0.45² ≈ 0.3369, P(4) = 5 × 0.55⁴ × 0.45 ≈ 0.2059, P(5) = 0.55⁵ ≈ 0.0503. The sum is about 0.593, so accuracy is higher than 55%, by about four points, at 5 times the cost. If the model tends to repeat the same mistake, the samples are not independent. The wrong answer then wins the vote in many of the cases where a single sample would also have been wrong, so the real gain is smaller than 0.593 suggests.
Exercise
A teammate says: "We pay for the answer we read, so a reasoning model that returns three sentences must cost about the same as a standard model that returns three sentences." What is wrong with this, and what would you check in the API response to confirm?
Show answer
Reasoning tokens are generated and billed as output tokens even when they are not shown, so a three-sentence reply can follow thousands of reasoning tokens. The cost and latency depend on total output tokens, not on the visible length. To confirm, read the usage section of the response, for example the reasoning token count and the total output token count, and compare the total with the length of the visible text.