Token Pricing, Context Windows, and Caching: What an LLM Actually Costs

Every LLM provider publishes a price per million input tokens and a slightly different price per million output tokens, and almost every first budget built from those two numbers turns out to be wrong by a factor of two or three. The reason is not hidden fees. It is that the billable unit is not the message you send. It is the entire context the model reads on every call, repeated on every turn, plus everything it writes, plus every retry you trigger because the first answer was unusable.

The short version: cost per call is roughly (system prompt + retrieved context + history + user message) times input price, plus output tokens times output price, minus whatever the provider lets you cache. Optimising the wrong term is the most common budgeting mistake in this space.

Why long system prompts are expensive out of proportion

A two-thousand-token instruction block feels free because you write it once. It is not free, because it is re-read on every single call. Ten thousand calls a day with a two-thousand-token preamble is twenty million input tokens a day that contain no new information. At a typical input price that is real money for nothing, and it grows linearly with traffic while your actual user content stays small.

The fix is not to shorten the prompt for its own sake but to separate the stable part from the variable part. Stable instructions, tool schemas, and formatting rules belong in a prefix that can be cached. Retrieved documents, conversation turns, and user input belong after it. Providers that support prefix caching price the cached portion at a steep discount, sometimes an order of magnitude, because the computation really is reused. Providers that do not support it charge full rate, which is a reason to prefer the ones that do for high-volume, prompt-heavy workloads.

History is the term nobody budgets for

Chat-shaped workloads accumulate history. Turn one sends ten tokens. Turn ten sends the whole transcript. If you keep the full transcript and let the model see it, the cost of a conversation grows quadratically with its length, which is fine for a demo and brutal for a support bot handling long sessions.

Practical trimming strategies, in order of how much they usually save: keep the last N turns verbatim and summarise earlier ones into a compact state block; drop tool call transcripts once their result has been incorporated into the answer; and store structured state (order number, account tier, open issue) outside the prompt rather than hoping the model remembers it. Each of these trades a small amount of fidelity for a large and predictable cost reduction. The trade is worth measuring rather than assuming: run the trimmed and untrimmed variants over fifty real conversations and compare both the bill and the answer quality.

Output tokens are the expensive half

Output is usually priced several times higher than input, because generating a token costs more compute than reading one. This has a counter-intuitive implication: verbose models are expensive even when their per-token price looks competitive. A model that writes three paragraphs where one would do is paying a premium on every response, and it is also making downstream parsing harder.

Where output length matters, constrain it in the request rather than in the prompt alone. Ask for a maximum length, request structured output with fixed fields, and reject responses that violate the schema instead of paying to read them. The saved output tokens usually outweigh the cost of a stricter contract, and the contract improves reliability as a side effect.

Retries are a hidden multiplier

Every retry doubles the input cost for that request, because the second attempt re-reads the same context. A workflow that silently retries twice on schema violations has an effective input price of three times the list price, and no line item on the invoice explains why the month was expensive.

Instrument the retry rate before optimising anything else. If more than fifteen percent of calls need a second attempt, the cheapest improvement available is usually a better schema or a smaller task, not a cheaper model. Splitting one hard request into two easy ones often cuts total tokens, because each half carries less context and fails less often.

Caching, in the three forms that matter

There are three distinct caching layers and they are routinely confused. Prefix caching is provider-side and automatic where supported; it rewards putting stable content first. Exact-match response caching is yours to build and is trivially valuable for repeated identical questions, which are common in FAQ-style traffic. Semantic caching, matching a new question to a stored answer by embedding similarity, saves more and carries risk, because a near-match can return a confidently wrong answer to a slightly different question.

Start with exact-match and prefix caching. Add semantic caching only where you can accept a wrong-but-close answer, or with a similarity threshold high enough that you would be comfortable showing the cached answer to a colleague. Record the hit rate; a semantic cache that hits five percent is not worth its failure modes.

A worked example with real proportions

Take a support assistant with a two-thousand-token instruction block, a three-hundred-token retrieved policy excerpt, eight turns of history averaging a hundred tokens each, and a question of forty tokens. The user content is under four hundred tokens. The context sent is over three thousand, and roughly two-thirds of it never changes between calls. On a provider with prefix caching, the stable two thousand is billed at the cached rate and the effective input cost falls by something close to half.

Now add a schema violation rate of one in five, which is common when the output contract is loose. The effective cost becomes roughly 1.5 times the clean number for input and the same for output. Two separate changes, caching the prefix and tightening the schema, together often cut the monthly bill by more than switching to a cheaper model would, and they do not degrade answer quality the way a model swap can.

The meter runs on every call, not on every message: prefix, history, output, retries.
The meter runs on every call, not on every message: prefix, history, output, retries.

What to check before you commit

  • Compute cost per shipped answer, not per call, and include retries.
  • Measure the retry rate first; fix reliability before shopping for cheaper tokens.
  • Put stable instructions first so prefix caching can apply.
  • Cap output length in the request, not only in the prompt.
  • Trim conversation history to a summary plus recent turns.
  • Log tokens in, tokens out, and cache hits per request, so the next budget is built from data.

None of this requires a sophisticated cost model. It requires knowing which of the four terms actually dominates your bill. In prompt-heavy workloads it is usually the repeated prefix. In chat workloads it is history. In extraction workloads it is output and retries. Find out which one you are, and the savings are large enough to notice on the first invoice.

Leave a Comment