Sub topic 2
Spending compute at inference time
This chapter assumes you have called an LLM API from code, know what tokens and context windows are, and can read short Python scripts. It covers one idea that the rest of the tutorial builds on. A model can improve its answer by doing more work when it answers, not only by being trained more.
Two places to spend compute
A language model uses compute in two phases.
- Training time is when the model learns from data. This cost is paid once by the provider, and it is fixed when you call the model.
- Inference time is when the model answers your request. This cost is paid on every call, and it grows with the number of tokens the model generates.
For years, quality gains came mostly from training: larger models, more data. Test-time compute is the other lever. It means spending more computation during inference on a single problem. The model gets more effort per question without any change to its weights.
Generating a token costs roughly the same amount of compute as any other token of that model. So the simplest way to spend more compute at inference is to let the model produce more tokens before it commits to an answer.
Why more tokens can mean better answers
A model writes one token at a time, and each token can depend on everything written before it. If the answer must appear in the first few tokens, the model has little room to work. If it can first write intermediate steps, those steps become context that later tokens can use.
Take the question "Is 3599 a prime number?" A model that answers "Yes" or "No" immediately must decide in one step. A model that first tries dividing by small primes can find that 3599 = 59 × 61. The steps do the work that a single guess cannot.
This is the link to chain-of-thought, the previous chapter's topic. Chain-of-thought is a way of using extra tokens. Test-time compute is the broader view: how many tokens, and how they are used, is a budget you can set.
Seeing the effect in a measurement
You can observe the relationship yourself. The script below counts how many tokens a model spends on a question, using the same call shape as later chapters. It assumes an OpenAI API key is set in your environment.
from openai import OpenAI
client = OpenAI()
questions = [
"What is the capital of France?",
"Is 3599 a prime number? Explain briefly.",
]
for q in questions:
response = client.responses.create(
model="o4-mini",
reasoning={"effort": "low"},
input=q,
)
details = response.usage.output_tokens_details
print(q)
print(" reasoning tokens:", details.reasoning_tokens)
print(" total output tokens:", response.usage.output_tokens)You should typically see few or no reasoning tokens for the capital question and noticeably more for the primality question. Exact numbers vary between runs and model versions, so treat them as approximate.
What changes for you
Spending compute at inference time has three consequences.
| Effect | What happens as inference compute rises |
|---|---|
| Quality | Often improves on multi-step problems such as math, code and planning |
| Latency | Grows, because the extra tokens must be generated before the answer |
| Cost | Grows, because you pay for generated tokens |
The effect is not uniform. A lookup question gains nothing from extra thinking, while a hard logic puzzle may gain a lot. Gains also shrink as you add more compute, a point the overthinking chapter returns to.
Common errors
- Assuming more compute is always better. Easy tasks get slower and costlier with no quality gain.
- Confusing a bigger model with more test-time compute. A larger model costs more per token. Test-time compute raises the number of tokens. You can change one without the other.
- Treating token counts as fixed. With the same prompt and settings, the number of thinking tokens can differ between calls.
Exercise
A teammate says, "To get better answers from the same model, we have to retrain it." Using the idea from this chapter, give one alternative, and name one cost of it.
Show answer
Spend more compute at inference time, for example by letting the model generate more reasoning tokens before it answers. The cost is higher latency and a higher bill, because the extra tokens are generated and billed on every request.
Exercise
Why might the query "What is the capital of France?" show fewer reasoning tokens than "Is 3599 a prime number?"
Show answer
The capital question can be answered directly from knowledge, so extra steps add nothing. The primality question needs intermediate work, such as testing divisors, so the model spends more tokens on it.