How LLM cost, context and latency work
You pay per token, and output costs several times input. Doubling context roughly doubles input cost; caching, batch, effort and model choice are the levers.
You pay per token, and output costs several times input. Doubling context roughly doubles input cost; caching, batch, effort and model choice are the levers.
Prompt caching reuses the processed start of a repeated prompt, so it bills at a tenth or less of the input price. How Claude, OpenAI and Gemini differ.
Make the model a setting, not a dependency: a thin interface, evals per task and a tested fallback. Route across models only where cost or residency pays.
A recurring report. A slow review. A prototype that needs to work in the real world.
Every major language model bills by the token, with input and output priced separately and output costing several times more. A request's bill is roughly its input tokens times the input rate, plus its output tokens (including any hidden reasoning) times the output rate, minus discounts for cached input and batch processing. Double the context and you roughly double the input cost; latency is the wait for the first token (driven by uncached input and thinking) plus the time spent writing the reply.
You don't need deep ML theory to estimate an AI feature before you build it, or to know which levers to pull once it's live; you just need to understand how tokens, context windows and output generation drive the bill.
Key takeaways
Models don't read words. A tokeniser chops text into pieces from a fixed vocabulary (a common English word, part of a longer word, a number or a punctuation mark) and the model works on those. A short everyday word is usually one token; a rare or long word breaks into several, so "interoperability" might split into "inter", "oper" and "ability" depending on the tokeniser. Numbers, code, tables and non-English text tend to burn more tokens per word.
Every model family ships its own tokeniser, so the exact same document can land on noticeably different token counts across providers. That makes headline price per million tokens a shaky comparison on its own. Count tokens on your real documents with each provider's counting tool, and compare cost per task.
Every major API structures billing the same way, just with different numbers:
The diagram breaks down one retrieval request both ways. Output is roughly one token in seven, and more than half the cost.
As a dated reference point, Anthropic's current list prices:
| Model | Input | Output | Context window |
|---|---|---|---|
| Claude Haiku 5.5 | $0.10 (prompts up to 100K tokens), $0.50 above | $0.50, $2.50 above 100K | 1M tokens |
| Claude Sonnet 5.5 | $2 | $10 | 1M tokens |
| Claude Opus 5.5 | $4 | $20 | 1M tokens |
| Claude Fable 5.2 | $8 | $40 | 1M tokens |
Checked 11 November 2026. Prices move; see Anthropic, OpenAI and Google for live rates. Batch requests cost about half on Anthropic and OpenAI.
On your invoice, roughly yes. Inside the model, standard attention compares every token against every other, so raw compute climbs faster than input length. That isn't how providers bill you: because pricing is per token, a 100,000-token request costs around 100 times the input of a 1,000-token request on the same model, rather than 10,000 times.
Three things bend that straight line:
Million-token windows are routine now: every current Claude model has one. That's plenty to drop a thick contract bundle or a sizeable codebase into a single call, and for one-off analysis of a fixed set of files it's often the cleanest route.
For a service answering lots of questions across a large or moving collection, retrieval usually wins. Sending only the relevant passages costs a fraction per question, keeps answers tied to citations, and lets you enforce each user's permissions before anything touches the model. Older models also stumbled over facts buried in the middle of a long prompt (the "lost in the middle" effect). Current models are far better, though you should still test recall on your own documents before betting on it.
| Option | When to use | Trade-offs |
|---|---|---|
| Long context | A fixed set of documents, analysed in depth a few times; or a stable reference that caching can reuse | Cost and latency climb with every token sent; permissions apply to the whole bundle at once |
| Retrieval (RAG) | Many questions over a large or changing collection, with citations and per-user access | Answers are only as good as the search; needs a pipeline and retrieval evals |
| Both | Retrieve the relevant documents, then read them whole rather than as fragments | More tokens per question than plain RAG, with fewer misses from chunking |
For more on that trade-off, see how in-house AI search works and fine-tuning vs RAG.
Models generate output one token at a time, each depending on everything before it, so output is slower and dearer to produce than input is to read. Reasoning models add a second output stream: they think before replying, and that thinking bills as output tokens even when the API sends back only a summary or nothing at all.
Most providers expose an effort or reasoning effort control. Low effort fits classification, extraction and routine lookups; higher effort earns its keep on multi-step analysis and agent work. Set it per task and measure: the exact same model at different effort levels can vary several-fold in token spend. Asking for a tight format, or a structured output carrying only the fields you need, trims the visible answer too.
A single call's wait splits cleanly into two halves:
An agent or multi-step workflow pays both on every turn and adds tool execution time on top, so the number of round trips is often what hurts most. Streaming doesn't finish the job any quicker, yet showing tokens as they arrive makes a long answer feel much shorter.
Roughly in order of effort against payoff:
Judge every tweak by cost per correct result on a fixed test set (see how to evaluate AI systems). A cheaper call that triggers a retry or a manual fix isn't cheaper.
A transformer is the neural network architecture behind modern language models, introduced in the 2017 paper Attention Is All You Need. Its core mechanism, attention, lets the model weigh how every token relates to every other in one pass instead of stepping word by word. In "the bank by the river was steep", attention is what ties "bank" to "river".
Two consequences of that design explain all the economics above. Input is processed in parallel across the whole prompt, which keeps input cheap per token and makes prefix caching possible. Output has to be written one token at a time, each conditioned on the last, which is why output costs more, long answers take longer and replies stream word by word.
Costing a new use case
Before building, cost out a typical request and a typical day across two or three models at the effort level you expect. Wire in caching and structured outputs from the start, and log input, cached, output and reasoning tokens on every call so real figures replace your estimate within a week.
Then tune on evidence: push non-urgent jobs to batch, dial down effort where quality holds, and test a smaller model per task against a fixed set of examples. Most of the saving comes from those choices, not from haggling over price per token.
We cost AI workloads on real tokens before writing production code, then keep them measured once live. How we scope and cost AI builds →