Cost and latency of a task
Tokens per turn, the cache, output speed and human waits: the full arithmetic of a task, with a live calculator driven by the engine.
Loading the animation…
Concept
Everything in the earlier chapters ends up in two numbers: what a task costs, and how long it takes. Both are sums over the model calls, and the calculator above computes them the way the engine does: pick a task and a policy, and the engine runs it (in your browser, in a background thread) and takes every call apart.
Per call, the cost has three parts: the prompt tokens not in the cache, at the input price (or the cache-write price, if the prompt is being cached); the prompt tokens read from the cache, at about a tenth of that; and the output tokens, at several times the input price. The time has two: the time to the first token, which grows with the uncached prompt, and the decode time, which grows with the output. Around the calls come the tools, the human's answers and any back-off.
A few things the calculator shows:
- The model's price sets the scale. Fixing the test costs $0.016 at Claude Sonnet 4.6's list price, $0.00533 at Haiku 4.5's and $0.00148 at GPT-5 mini's, for the same tokens.
- Small prompts are never cached. The fix-the-test prompts stay under the 1,024-token minimum a prompt needs before it is cached, so turning the cache off changes nothing there ($0.016 either way). Reading the notes, 71% of the prompt tokens come from the cache at Sonnet's prices, but none at Haiku's, whose minimum is 4,096 tokens.
- Input dominates. Over the note-reading task the model is sent 16,179 tokens and writes 396 tokens: re-reading the context, not writing, is where the tokens go.
- People and slow hardware dominate the time. The same fix takes 7.71 s against a hosted API with nothing to approve, 27.6 s when a person approves each shell command and edit, and 36.2 s with the small local model on an old CPU, at no per-token price.
Maths
For model call with prompt tokens, of them read from the cache, and output tokens,
where becomes the cache-write price on a call whose prompt is written to the cache. Each call's time is a fixed overhead , plus the uncached prompt at the prefill rate, plus the output at the decode rate; a run adds the tools, the waits for the human and any back-off:
Because the whole context is re-sent on every turn (chapter 1), grows roughly with the square of the number of turns, while grows linearly: long tasks are input-bound, which is why caching (chapter 4), compaction (chapter 3) and sub-agents (chapter 6) all go after . Where and come from (the roofline of the hardware serving the model, batching, and the prefill/decode split) is the subject of LLM Inference Explained; how a serving system trades them against each other, including prefix caching, of Inference Trade-offs Explained.
Code
One call's cost and latency, cut from the vendored engine (accounting.ts):
const fresh = input - cached;
const rate = stored ? price.cache_write : price.input;
return (cached * price.cache_read + fresh * rate + output * price.output) / 1e6;
const ttft = profile.overhead_ms + ((input - cached) * 1000) / profile.prefill_tps;
return [ttft, ttft + (output * 1000) / profile.decode_tps];