The quiet cost of long context
Context windows have grown by roughly two orders of magnitude in three years, and the marketing has kept pace. What has not kept pace is the intuition most engineers carry about where the cost of a long request actually goes. The number on the pricing page is per token; the bill is not linear in the way people assume.
Start with the cache
The KV cache is the cleanest place to see the problem, because you can compute it exactly. For a transformer with L layers, H key-value heads, head dimension d, and fp16 storage, the cache per token is:
bytes_per_token = L × 2 × H × d × 2
Take a 70B-class model with 80 layers, 8 KV heads, and head dimension 128. That gives 4 KB per token per layer, or 320 KB per token in total.
- 32K context: about 10 GB
- 128K context: about 41 GB
- 1M context: about 320 GB
This is why long-context serving is not simply "the same thing but longer". At 1M tokens the cache alone exceeds any single accelerator, before you have stored a single weight. Every technique in the long-context toolbox — grouped-query attention, quantization, paged allocation, offloading — exists to fight this one number.
Grouped-query attention is the big lever: going from 64 KV heads to 8 cuts the cache by 8x. Quantizing the cache to int8 halves it again. Together, that 320 GB becomes 20 GB, which fits. But note what happened — you did not make long context cheap, you made it merely possible.
Prefill is the latency wall
The second cost is time, and it lands almost entirely before the first output token.
Prefill processes the whole prompt in parallel, which is good for utilization but means the work scales with prompt length. A million tokens at a generous 20K tokens per second of prefill throughput is still fifty seconds of silence before the model says anything. Users do not experience that as "long context". They experience it as a broken product.
Decode, by contrast, is one token at a time and dominated by memory bandwidth — every step re-reads the weights and the growing cache. At long context, decode gets slower as the cache grows, not because the math changed but because there is more memory to move per token.
Long context is paid for twice: once in prefill latency, and again in every subsequent decode step.
The quality assumption
There is a third cost that does not show up in any profiler. A model that accepts 1M tokens does not reliably use 1M tokens.
The "lost in the middle" effect is well documented and has not been fully solved by scale. Information placed in the middle of a long context is retrieved less reliably than information at the edges. Effective context — the length at which retrieval accuracy stays high — is consistently shorter than the advertised maximum, often by a large factor.
This matters for architecture decisions. If effective context is 30K and you are paying for 200K, you are buying latency and memory to store text the model will not attend to properly. The honest move is to measure effective context on your own task distribution rather than trusting the spec sheet.
What this implies for design
A few conclusions I have become fairly confident about:
- Retrieval is still necessary. Not because models cannot hold long context, but because putting everything in is economically irrational when most of it is irrelevant.
- Prompt caching changes the calculus. If the long prefix is stable across requests, prefill is paid once and the economics improve dramatically. This is the single highest-leverage optimization for long-context products.
- Measure effective context, not maximum context. Build a needle-in-haystack variant on your real documents. The gap between the two numbers is your actual headroom.
- Latency budgets are per-interaction, not per-token. A 40-second time-to-first-token is a product decision, not an infrastructure detail.
Long context is a real capability and I am glad it exists. But it is priced like a feature and costs like an architecture. Treating it as the latter is the difference between a demo that impresses and a service that survives its own traffic.