LLM Context Windows: What They Cost at Inference and How to Read the Trade-Offs

An LLM context window is a shared token budget. Models use less of it well than advertised, and long context raises latency, memory and cost per request.

LLM Context Windows: What They Cost at Inference and How to Read the Trade-Offs
Written by TechnoLynx Published on 11 Jul 2026

An LLM context window is the maximum number of tokens a model can work with in one request. That budget covers the prompt, the generated answer and, on reasoning models, the reasoning tokens as well. In production, two facts about it matter more than the headline size. Models use less of their window well than they advertise, and longer context costs more compute and latency, because attention cost grows with the square of sequence length.

TechnoLynx works out and cuts what a given context length costs on a team’s own serving path. That work is part of TechnoLynx’s generative and agentic AI R&D. The work starts with an audit that profiles the real request mix, before anyone chooses a window size, caching scheme or retrieval design.

What Does a 32K LLM Context Window Mean for a Production Request?

A 32K window is a shared budget of about 32,000 tokens per request, and both the input and the output draw on it. NVIDIA’s inference benchmarking guide defines context length as the tokens the model uses at each generation step, counting input and output generated so far, with one maximum allocated across both. Anthropic’s documentation lists everything that counts: the system prompt, every message including tool results, images and documents, the tool definitions, and the output for the turn, extended thinking included. A 30,000-token prompt sent to a 32K model leaves almost no room for the answer.

The context held in the window also occupies GPU memory. Each token that stays in context keeps its key and value tensors in GPU memory, so the model can attend back to it without recomputing it. That KV cache grows linearly with context length. A 2026 analysis of the KV cache as a memory wall works the figure out for Llama-3-70B in BF16: 327,680 bytes per token, which comes to 42 GB for one 128k-token sequence, on top of 140 GB of weights that already exceed a single 80 GB accelerator.

These numbers grow linearly with sequence length and batch size. NVIDIA’s worked example gives about 2 GB of KV cache for Llama 2 7B at 4,096 tokens and batch size 1. A 2026 survey estimates that a 7B model’s cache at 128K tokens (about 64 GB) is larger than an A100’s memory. How that memory pressure interacts with batching on a shared serving path deserves its own treatment. For this page, the point is that “32K” or “128K” is a memory cost as much as it is a feature.

What Happens When the Context Window Is Full?

OpenAI’s documentation warns that oversized prompts can produce truncated outputs, and that tokens generated past the limit may be cut off. Google’s Gemini documentation lists the strategies more limited windows require: dropping old messages, summarising content, retrieval with vector databases, and filtering prompts.

Compaction is one alternative to dropping turns. The conversation is summarised as it nears the limit, and a fresh window starts from the summary. Anthropic offers this server-side, so a conversation can continue past the window limit. A long-context survey notes that sliding-window attention, which keeps only the most recent tokens’ KV states, loses accuracy once the initial tokens are evicted. In our view, the question to ask of any overflow strategy is which information it discards. Anthropic’s compaction keeps decisions and drops redundant tool outputs; sliding windows degrade once the initial tokens are evicted.

Is a Model’s Advertised Context Window the Context It Actually Uses?

No. For almost all models tested, the advertised window is above the length at which they still perform well. One line of evidence is RULER (Hsieh et al., 2024). It tested a set of long-context models on tasks beyond simple in-context recall. Every model claimed 32K tokens or more, yet only half stayed above a quality threshold (Llama-2-7B’s score at 4K) at 32K, and almost all fell below it before their claimed length. In the NoLiMa benchmark, GPT-4o did not generalise beyond 8K.

These studies matter because the most widely used long-context test measures only a narrow capability. The needle-in-a-haystack test checks lexical retrieval of one planted fact, and models that score almost perfectly on it still degrade sharply on harder tasks as inputs grow. Chroma’s context-rot study held the needle-question pair fixed and varied only the amount of irrelevant content. Performance fell as input length grew, and distractors did more damage at longer lengths.

Where information sits in the prompt matters too. The Lost in the Middle study (Liu et al., 2023) found that performance was often highest when relevant information appeared at the start or end of the input, and dropped significantly when it sat in the middle, even for models built for long context. Anthropic now describes this decline in its own documentation as context rot: as token count grows, accuracy and recall degrade, so what you put in the window matters as much as how much space it has.

If you are comparing models by headline window size, the comparison of which LLM has the largest context window and why that number won’t decide it takes that question further. For a deployment decision, treat the advertised window as a ceiling. The usable figure comes from evaluating your own task at your own lengths.

Why a Longer Context Makes Each Inference Request Slower and More Expensive

Long context costs more because attention compares every token with every other token, so the work of processing the prompt grows with the square of its length. A 2024 long-context serving study (Medha) puts it plainly: a 100K-token request is not 100× but about 10,000× more expensive to compute than a 1K-token request. The same study estimates 2.8 ExaFLOPs to process 1M tokens with Llama-3 70B, at least 48 minutes on one H100 even at full utilisation. The 2026 KV-cache analysis finds that at 128k context the quadratic term already makes up 55% of prefill cost, so doubling the context more than doubles the recompute time.

Longer prompts show up first as a slower first token. NVIDIA explains that time to first token (TTFT) rises with prompt length because the whole input has to be processed to build the KV cache. Google’s Gemini guidance says the same: every request has some fixed latency, but longer queries generally take longer to the first token. Generation then has its own cost. Each new token reads the model weights and the whole KV cache from memory, so decoding is limited by memory bandwidth and slows as the cache grows. How prefill and decode scale differently with context is a separate, deeper question. The short version is that long contexts hurt both phases, for different reasons.

On a shared GPU, a long request also slows the short ones. The Medha authors describe a convoy effect: long requests stall short interactive ones. With only 5% long requests in the workload, one state-of-the-art system showed a 30× rise in median latency and 174× worse tail latency for short requests. A context-length policy is also a latency policy for every other user on that path.

Anthropic bills its newer models’ full 1M-token window at standard per-token rates, so a 900k-token request pays the same rate per token as a 9k-token one. The rate is flat, but every token sent is still billed. Claude Haiku 5.5, by contrast, charges higher prices for the whole request once the prompt goes over 100,000 tokens. The LLM token calculator for estimating inference cost per request shows how to turn token counts into a per-request figure.

How Caching Earlier Context Changes the Cost of Long Prompts

Prefix caching stores the KV state of a prompt prefix once and reuses it for every request that shares that prefix. That pattern is common in system prompts, few-shot examples, retrieved documents and multi-turn history. When reuse is exact, nothing is lost and prefill compute is saved, because shared positions are never re-encoded. The vLLM documentation gives the standard case: a user asking repeated questions about the same long manual or annual report, where the document is processed once and later requests reuse its KV cache. The same 2026 analysis estimates that recomputing a 128k-token KV cache takes about 25 seconds of B200 prefill, while fetching a stored copy over PCIe Gen5 takes about 0.66 seconds.

Caching has two limits that are easy to miss. It speeds up only the prefill phase, so it does nothing for long answers or for requests that share no prefix. And cached tokens still take up the window: Anthropic’s documentation states that caching changes what you pay for those tokens, not whether they count.

Anthropic and OpenAI pricing reflects the same mechanism, with a premium to write the cache and a discount to read it.

Prompt-Caching Terms by Provider

Provider (per its documentation) Cache write Cache read Default lifetime Minimum cacheable prefix
Anthropic (Claude) 1.25× base input for 5 minutes; 2× for 1 hour 0.1× base input on most models 5 minutes, refreshed free on each use Model-specific threshold
OpenAI (GPT-5.6 and later) 1.25× uncached input for 30 minutes; 2.5× for 12 hours 0.1× on most of these models 30 minutes 1,024 tokens
Google (Gemini) Implicit caching on by default for Gemini 2.5 and newer, savings passed on automatically Not stated in Gemini’s caching documentation Not stated; explicit caches billed per hour of storage 2,048 tokens (2.5 Flash, 2.5 Pro); 4,096 on newer models

The Anthropic write and read rates come from its pricing page. At Anthropic’s rates, a 5-minute cache pays for itself after one read. OpenAI works through the same arithmetic: writing a prefix once and reusing it once costs 1.35× its normal input price, against 2× for processing it twice, and one write plus nine reads costs 2.15× against 10×.

A discount on paper does not guarantee a cache hit. OpenAI notes that cached states live on individual machines, and a request reuses a prefix only if it reaches a machine holding a matching entry that has not expired. Its minimum lifetime governs whether a request qualifies for the read price, not whether stored tensors are reused. Anthropic adds that a cache breakpoint placed on content that changes every request, such as a timestamp or the user’s input, writes a new entry every time and never hits. Anthropic’s documentation advises putting the stable material first and the variable material last. OpenAI advises tracking the cache-hit rate as cached tokens divided by total input tokens.

When Is a Smaller Context Window a Better Trade-off than a Larger One?

A smaller window wins when the extra tokens add cost faster than they add accuracy. Retrieval Meets Long Context (2023) found that a model with a 4K window plus simple retrieval matched a fine-tuned 16K-window model on long-context tasks while using much less computation. Chroma found significantly higher performance on focused prompts than on full prompts across every model it tested. Another study found that introducing irrelevant context into the window significantly degrades performance.

Full context remains necessary for peak performance, but with clear diminishing returns relative to its cost. The 2026 Efficiency Frontier study found that reaching the highest performance levels with full-context prompting took more than 2× the token cost of balanced operating points, and moving from mid-range to high performance more than doubled token usage. It also found that no single strategy wins everywhere. Single, isolated queries favour lightweight retrieval, while persistent assistants that reuse the same material many times benefit from heavier up-front compression.

Choosing Between a Long Window, Retrieval and Curation

Situation Leaning Why
Each query touches a different slice of a large corpus Retrieval into a modest window Isolated queries favour lightweight retrieval
Many queries hit the same long document or history Long context with prefix caching, or compression Reuse spreads the up-front cost across requests
The task needs the highest accuracy over the whole input Full context, with the cost budgeted Peak performance needed full context at over 2× the tokens
Inputs carry lots of loosely related material Curate before you send Focused prompts beat full prompts
Long and short requests share GPUs under latency targets Measure latency with the real long-request mix Even 5% long requests raised short-request median latency 30×

Anthropic’s engineering guidance puts the general principle as: find the smallest set of high-signal tokens that maximises the chance of the outcome you want.

Measure What Your Requests Use Before You Pay for Headroom

None of the studies above measured your workload. RULER, for example, generates synthetic test examples. The 2026 KV-cache analysis lists its own assumptions, such as a FlashAttention-class kernel and fixed prefill utilisation. What carries over is the shape of the trade-off: attention cost that grows faster than length, a KV cache that grows linearly with it, accuracy that falls off before the advertised limit, and caching that helps only when prefixes repeat.

So the useful number is not the model’s maximum. It is the token distribution of your real requests, what that distribution costs per request, and where accuracy on your task starts to drop. Profiling real inference bottlenecks before optimising keeps that work grounded in context rather than best-practice dogma. For turning those measurements into a cost baseline, the inference cost audit applied to an LLM serving workload works through a full example. For reading latency and throughput results without being misled, see LLM inference benchmarks and what they measure.

FAQ

How Does an LLM Use Its Context?

While processing input, the model computes key-value states for each token, which let it refer back to earlier tokens as it reads new input and generates output. Every token in the window attends to every other, so a longer context stretches the model’s attention thin.

Which LLM Has the Longest Context Window?

Several models now advertise windows of a million tokens or more. Chroma’s study notes Gemini 1.5 Pro’s 1M window in early 2024, followed by GPT-4.1’s 1M window. The ranking says little about usable length, which is why the practical reading of which LLM has the largest AI context window is worth checking before you choose.