Pidoku

Test-Time Compute: The Economics of Reasoning Tokens

Module 27 Lesson 27.a 1h Difficulty 3/5

Prerequisites 12.c, 12.f, 23.b, 23.c, 24.e


Before you start: words you need#

WordPlain meaning
Reasoning tokensTokens a model writes while “thinking” before its answer. Often hidden from the user, but generated, stored in the KV cache and billed like any other output.
Test-time computeSpending more inference work on one question (longer thinking, several attempts, search) to get a better answer. “Test time” means “when the model is used”, as opposed to training time.
Effort / thinking budgetA request setting that tells a reasoning model roughly how much to think: a level such as low or high, or a maximum number of thinking tokens.
Best-of-N / self-consistencyAsk the same question N times in parallel, then pick an answer by majority vote or with a checker.
VerifierCode or a model that checks an answer: unit tests, a maths checker, a reward model.
KV·timeHow much KV-cache memory a request holds multiplied by how long it holds it (GiB·s). The real “rent” a long request pays on a GPU.
Little’s lawRequests in the system = arrival rate × time each one spends there (2.c, 23.b).

1. What is it?#

A reasoning model answers a hard question by first writing a long chain of thought, then a short answer. The chain may be 1,000 tokens or 50,000. Nothing about the model changed between the two cases; the operator, the user or the model itself decided to spend more compute at inference time. That is test-time compute, and it now comes in three shapes:

SEQUENTIAL   one attempt, longer thinking          prompt → [think ............] → answer
PARALLEL     N attempts, then vote or verify        prompt → [think] → a1
                                                           → [think] → a2  → pick one
                                                           → [think] → a3
SEARCH       a tree of partial attempts, scored     prompt → branch, score, prune, extend ...
             and pruned as they grow

Every serving stack now exposes a knob for it:

WhereKnobNotes
OpenAI APIreasoning.effortValues are model-dependent and can include none, minimal, low, medium, high, xhigh and max. Reasoning tokens are billed as output tokens and reported under output_tokens_details.
Anthropic APIthinking: {type: "adaptive"} with output_config: {effort: ...}The older fixed budget_tokens mode is deprecated on the 4.6 models and rejected by models numbered 4.7 and later. Thinking tokens count toward max_tokens and are reported in usage.output_tokens_details.thinking_tokens.
vLLM v0.32.0reasoning_effort and thinking_token_budget on the requestreasoning_effort accepts none … max (max is specific to DeepSeek V4) and turns the chat template’s enable_thinking on or off. thinking_token_budget forces the end-of-reasoning string once the budget is spent (18.i).

Facts checked on 13 November 2026.

This lesson is about the bill: what reasoning costs in GPU time, memory and money, and how to decide how much of it to buy. The research on how to scale test-time compute well lives in 24.e; how vLLM parses reasoning out of the output lives in 18.i.


2. Why does it matter?#

Because the cost of a request moved from the prompt to the output.

  • A chat answer used to be a few hundred output tokens. A reasoning answer to the same question can be 20,000. Output tokens are decode tokens, the expensive kind (12.c): each one needs a full pass over the weights and reads the whole KV cache so far.
  • The request lives 50 times longer. By Little’s law, at the same arrival rate you need 50 times more requests in flight, each holding a growing KV cache.
  • The user waits for tokens they never see. “Time to first token” stops meaning “time to first useful token”.
  • Prices are per token, so a product that turns on “high effort” by default can multiply its inference bill without changing a line of model code.

A principal engineer’s job here is to turn “think harder” into numbers: cost per correct answer, KV memory per stream, and latency the user will accept.


3. Simple analogy#

An exam where you pay the student by the word, including the scratch paper.

  • Sequential: let one student fill ten pages of scratch work before answering. Better answers on hard questions, slow, and you pay for every page.
  • Parallel: give the question to eight students at once and take the majority answer. Same wall-clock time as one student, eight times the paper.
  • Search: let students write the first step, keep the promising ones, and continue only those.

And the exam room has a fixed number of desks (KV memory). A student with ten pages of scratch work occupies a desk ten times longer.


4. Tiny example: one maths question, five ways#

A 2,000-token prompt, a 400-token visible answer, served on one 8-GPU replica that costs $64 per hour and decodes 20,000 tokens per second in total (60 tokens per second per user). Section 6 has the program; here is its result.

policy           decoded   $/1k req   wait (s)   KV GiB·s   streams fit   $/1k correct
direct answer        400       0.71        6.7        2.2          1787           1.78
low effort          1900       2.04       31.7       14.3          1333           3.41
medium effort       6400       6.04      106.7       84.6           756           8.40
high effort        20400      18.49      340.0      632.9           322          23.70
8 x low, vote      15200      13.87       31.7       46.4           410          18.74

The accuracies behind the last column (40%, 60%, 72%, 78%, 74%) are made up for the example; replace them with your own evaluation. Three things show even so:

  1. “High effort” costs 26 times more per request than a direct answer and makes the user wait almost six minutes at 60 tokens per second.
  2. Eight parallel low-effort attempts cost less than one high-effort attempt, finish ten times sooner, and hold far less KV·time, because the 2,000-token prompt is cached once and shared (prefix caching, 17.f).
  3. Cost per correct answer is the number to compare. A policy that is cheaper per request can be dearer per correct answer, and the other way round.

5. Technical explanation#

Where the cost of a reasoning request goes#

prefill   2,000 tokens   compute-bound, fast, done once           ~0.02 s of replica time
decode   20,400 tokens   memory-bound, one token per step         ~1.0 s of replica time
KV       grows from 2,000 to 22,400 tokens, held for 340 s        ~630 GiB·s

Two effects make long chains worse than linear:

  • Each decode step gets slower as context grows. Attention reads the whole KV cache every step (12.f). At 22,000 tokens of context, attention reads can rival the weight reads for a small or medium model. Per-token cost is not constant across the chain.
  • KV memory caps the batch. The replica above can hold 1,787 direct-answer streams but only 322 high-effort ones. Fewer streams means a smaller decode batch, and decode throughput falls with batch size (2.d). With 322 streams at 60 tokens per second, the replica produces only about 19,300 tokens per second, which is roughly the 20,000 the example assumed. Push effort higher and the throughput assumption breaks.

Sequential, parallel or search: what each buys#

ShapeQuality leverServing costLatencyNeeds
Sequential (longer thinking)Strongest on problems that need many dependent stepsOutput tokens × growing contextGrows with lengthA model trained to think long
Parallel (best-of-N, vote)Strongest when a checker or a vote can pick the right answerN × output, prompt sharedOne attempt’s length (the slowest one)A vote or verifier; n > 1 or N requests with a shared prefix
Search (tree, beam, MCTS)Best on problems with a cheap step-level scorerHard to predict; many short branchesSeveral roundsA process reward model or step checker; engine support for forking

Snell et al. (2024) found that which method works best “critically varies depending on the difficulty of the prompt”. Allocating compute per prompt by difficulty was more than 4 times as efficient as plain best-of-N, and on problems where a small model already had some success, extra test-time compute let it beat a model 14 times larger at equal FLOPs. On the hardest problems it could not substitute for a stronger model. The serving consequence is the important part: one effort level for all traffic wastes money on easy requests and under-serves hard ones.

How budgets are enforced#

  • API level. effort levels are hints the model was trained to follow; they change the distribution of thinking lengths, not a hard cap. Anthropic’s adaptive mode lets the model skip thinking on easy inputs at lower effort.
  • Engine level. vLLM’s thinking_token_budget counts tokens from reasoning_start_str. When the count reaches the budget, it forces reasoning_end_str (which can include a transition phrase such as “I have to give the solution based on the reasoning directly now.”) so the model moves to its answer. This is a hard cap, implemented as forced tokens in the sampler.
  • max_tokens. The blunt instrument. Thinking counts toward it. If the limit is hit while the model is still thinking, the user gets no answer but still pays: OpenAI marks the response incomplete and warns this “might occur before any visible output tokens are produced”, and recommends reserving at least 25,000 tokens for reasoning and output when you start.

What the bill looks like at a provider#

Reasoning tokens are charged at the output price, and output tokens cost several times input tokens at every major provider because decode is memory-bound (23.c). Two details catch teams out:

  • On Claude Opus 4.5 and models numbered 4.6 and later, earlier turns’ thinking blocks stay in context and are billed as input on later turns. On agent loops this adds up (27.b).
  • Changing the effort level or thinking budget between turns invalidates the prompt cache for the conversation (the setting is rendered into the prompt). Pick a level per session and hold it.

6. Under the hood: the cost model#

Go
// reasoncost.go — what reasoning tokens cost a self-hosted replica.
package main

import "fmt"

type policy struct {
	name      string
	samples   int     // parallel attempts sharing one prompt
	reasoning int     // hidden reasoning tokens per attempt
	answer    int     // visible answer tokens per attempt
	accuracy  float64 // ILLUSTRATIVE: replace with your own eval numbers
}

func main() {
	const (
		prompt       = 2_000    // input tokens
		replicaUSDh  = 64.0     // 8 GPUs × $8/GPU-hour
		decodeTokS   = 20_000.0 // replica decode throughput at this interactivity
		prefillTokS  = 100_000.0
		perUserTokS  = 60.0  // tokens per second one stream sees
		kvKiBPerTok  = 160.0 // 80 layers × 8 KV heads × 128 dims × K and V × 1 byte (FP8)
		kvBudgetGiB  = 600.0 // HBM left for KV across the replica
		usdPerSecond = replicaUSDh / 3600
	)
	policies := []policy{
		{"direct answer", 1, 0, 400, 0.40},
		{"low effort", 1, 1_500, 400, 0.60},
		{"medium effort", 1, 6_000, 400, 0.72},
		{"high effort", 1, 20_000, 400, 0.78},
		{"8 x low, vote", 8, 1_500, 400, 0.74},
	}
	fmt.Println("policy           decoded   $/1k req   wait (s)   KV GiB·s   streams fit   $/1k correct")
	for _, p := range policies {
		out := p.samples * (p.reasoning + p.answer)
		cost := (float64(out)/decodeTokS + prompt/prefillTokS) * usdPerSecond * 1000
		wait := float64(p.reasoning+p.answer) / perUserTokS // attempts run side by side
		perAttempt := float64(p.reasoning + p.answer)
		avgCtxTok := prompt + float64(p.samples)*perAttempt/2 // prompt KV is shared
		kvGiB := avgCtxTok * kvKiBPerTok / (1 << 20)
		fmt.Printf("%-15s %8d   %8.2f   %8.1f   %8.1f   %11.0f   %12.2f\n",
			p.name, out, cost, wait, kvGiB*wait, kvBudgetGiB/kvGiB, cost/p.accuracy)
	}
}

Output:

policy           decoded   $/1k req   wait (s)   KV GiB·s   streams fit   $/1k correct
direct answer        400       0.71        6.7        2.2          1787           1.78
low effort          1900       2.04       31.7       14.3          1333           3.41
medium effort       6400       6.04      106.7       84.6           756           8.40
high effort        20400      18.49      340.0      632.9           322          23.70
8 x low, vote      15200      13.87       31.7       46.4           410          18.74

How to read it:

  • streams fit uses the average context over a request’s life (the KV grows from the prompt to the full length). For the voting policy it counts whole requests of eight attempts.
  • KV GiB·s is the memory rent. High effort pays 290 times the rent of a direct answer for less than twice the (illustrative) accuracy.
  • The model is linear on purpose. It ignores slower decode at long context and the fall in throughput when the batch shrinks. Both make long chains more expensive than shown. Exercise A adds them.

7. Performance implications#

  • Reasoning traffic is decode-bound and KV-bound. Everything that makes decode cheaper pays off more: speculative decoding (13.n, 24.e), FP8 or FP4 KV cache (13.h), attention variants with smaller KV (12.g), and offloading cold KV (14.k).
  • Length variance hurts batching. A batch mixes 500-token and 30,000-token chains. Short ones finish and are replaced (continuous batching, 12.j), but the long tail sets p99 latency and holds KV for minutes.
  • Parallel attempts are cheap in prefill, expensive in decode. With prefix caching, N attempts prefill the prompt once. vLLM’s n parameter forks one request into N sequences that share the prompt’s KV blocks.
  • Early stopping saves real money. If 6 of 8 voters already agree, the remaining two can be aborted. Research schedulers do this automatically (24.e); you can do it in the client today.

8. Production implications#

  • Choose effort per route, not per platform. Use a cheap classifier, the product surface, or the customer tier to pick effort. Cascades (21.k) apply: answer with low effort, escalate on low confidence or a failed check.
  • Cap every request. Set max_tokens with enough room for thinking plus answer, and a thinking_token_budget (self-hosted) or an effort level (APIs). Alert on finish_reason == "length".
  • Measure tokens per task, not per request. Track reasoning tokens p50, p90 and p99 per route, and the ratio of reasoning to visible tokens.
  • Rewrite the latency SLO. Separate “time to first token” (which now includes thinking) from “time to first visible token”, and decide which one the product promises (23.a).
  • Plan capacity with the long tail. Little’s law with the mean output length under-sizes KV memory; size for the p90 context (23.b).
  • Stream thinking or progress if the product allows, so users see that work is happening.
  • Hold effort constant within a session so the prompt cache keeps hitting.

9. Common mistakes#

  1. Turning on the highest effort level by default “for quality”, without measuring cost per correct answer.
  2. Setting max_tokens for the visible answer only, so the model is cut off mid-thought and the user gets nothing but a bill.
  3. Benchmarking a reasoning model with fixed short outputs; real chains are 10–100 times longer and change the bottleneck from compute to KV memory.
  4. Comparing policies on cost per request instead of cost per correct answer.
  5. Running N parallel attempts as N unrelated requests on different replicas, so the prompt is prefilled N times.
  6. Changing the effort level turn by turn in a conversation and losing the prompt cache.
  7. Using the mean reasoning length for capacity planning.

10. Hands-on exercise#

A. Make the model honest. Extend reasoncost.go so that (i) per-token decode time grows with context (add a term proportional to context length for attention reads), and (ii) decode throughput is capped by streams fit × perUserTokS. How much more does “high effort” cost now?

B. Measure a real distribution. Serve a small reasoning model with vLLM and --reasoning-parser. Send 200 maths questions at reasoning_effort low and high. Plot the distribution of reasoning tokens (from usage) and note p50, p90, p99.

C. Budget it. Repeat B with thinking_token_budget set to your p50. Compare accuracy and cost per correct answer against no budget.

D. Vote early. Implement best-of-8 with majority vote in a client, and abort remaining attempts once 5 agree. How many decode tokens did early stopping save?


11. Interview questions#

  1. Why does a reasoning model cost more to serve than a chat model of the same size, beyond “more tokens”?
  2. Compare sequential and parallel test-time compute in serving cost, latency and memory.
  3. How would you choose an effort level per request in a product with mixed traffic?
  4. Why can best-of-N be cheaper per request than one high-effort attempt, and when is it not?
  5. A team sees many responses with no visible answer and full charges. What happened and how do you fix it?
  6. How does reasoning traffic change your capacity plan for KV memory?

12. Further reading#

Checked on 13 November 2026.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in