Why Are LLM Output Tokens More Expensive Than Input Tokens
This article explains why LLM providers charge more for output tokens than input tokens, and why cache hits can be dramatically cheaper than cache misses. It breaks inference into the prefill and decode phases, showing how prefill is a compute-heavy, highly parallel matrix operation with near-constant per-token cost, while decode is memory-bandwidth-bound, serial, and carries a quadratic cost term as the KV cache grows. It also covers how these hardware differences translate into typical 3x–5x output-to-input price ratios and order-of-magnitude cache-hit discounts, and ends with practical tips for controlling token costs.
1. The Starting Point: Why the Same Token Has Different Prices
When building LLM applications, developers often notice something odd: within a single provider’s price list, input tokens and output tokens have clearly different unit prices, and the gap between cache hits and cache misses is even more dramatic. The first instinct is often “this is just marketing pricing.” But from an engineering standpoint, this price difference has a solid physical basis.
To understand it, you need to split a single inference request into two phases: prefill and decode. Prefill processes the user’s input prompt; decode generates the answer token by token. The two behave completely differently on the hardware, so their cost structures naturally differ.
2. Prefill: One Large-Scale Parallel Matrix Operation
Let the input length be N and the model’s hidden dimension be d. In the prefill phase, all input tokens are fed into the model at once. Each layer is mainly a matrix multiplication shaped like (N, d) × (d, d), and the attention part needs to compute an N×N relationship matrix. The overall floating-point workload is roughly on the order of O(N·d²) + O(N²·d).
The key point: both terms grow with N, but amortized per token, they are close to a constant. In other words, the longer the input, the more stable the average compute cost per token. At the same time, because it is a single large-batch parallel operation, the matrices are large enough to keep the GPU’s compute units well fed, and measured utilization can typically be pushed above 80%.
Here is pseudocode expressing this “batch parallel” shape:
# Prefill: one forward pass over all input tokenshidden = model.forward(input_ids) # shape [N, d]kv_cache = hidden.kv # save K/V for reuse during decode
This is a “compute-heavy, memory-light” task where the hardware’s FLOPS are fully utilized.
3. Decode: The Serial Bottleneck from Autoregression
The output side is a completely different story. M output tokens must be generated one at a time: to compute the t-th token, you first run a full forward pass, reading the entire model weights from memory once, then perform an attention computation over the N+t−1 tokens accumulated so far. Only after the t-th token is done can the t+1-th begin.
# Decode: generate token by token, seriallyfor t in range(M):logits = model.forward(last_token, kv_cache) # matrix-vector multiplynext_token = sample(logits)kv_cache = append(kv_cache, next_token) # KV cache grows by one slot each step
The arithmetic intensity here is extremely low: a single step is a matrix-vector multiply, which consumes little compute, but memory bandwidth is maxed out. The bottleneck shifts from “how fast can we compute” to “how fast can we move data,” and GPU utilization is noticeably lower than in the prefill phase.
Summing the total work across M steps, the compute per token can be approximated as C + α(N+t): C is the fixed cost of one pass over the weights, and α is the marginal coefficient for attention. Summing over t from 0 to M−1:
Total cost ≈ C·M + α·(N·M + M(M−1)/2)
A quadratic term related to M² appears here. This is exactly the source of “each new token generated makes the next one a bit more expensive”—the KV cache grows by one slot each step, the marginal cost rises linearly with output length, and the accumulation becomes quadratic growth. Output cost is not linear in M; it carries a quadratic term.
4. Converting to GPU-Seconds: The Physical Source of the 3x–5x Price Gap
Stacking the compute difference on top of the utilization difference, and converting to “GPU-seconds consumed to produce one token,” the decode side typically costs 5 to 10 times more than the prefill side. This is the physical root of why output/input unit price ratios in the market generally fall in the 3x–5x range. The ratio varies slightly across models (some around 2.5x, some close to 8x), and the differences come mainly from two sources: first, commercial pricing strategy; second, how much the architecture mitigates the decode bottleneck—for example, more efficient attention structures, more aggressive KV cache compression, and speculative decoding can all lower the actual cost on the decode side.
5. Cache Hits: The Logic Behind a 120x Price Gap
Now look at the huge gap between cache hits and misses. The number of input tokens is exactly the same in both cases; the only difference is that on a hit, there is no need to rerun prefill, and the already-computed KV cache can be loaded and reused directly from memory or external storage.
A miss pays the full O(N·d²) prefill compute; a hit is left with only a load and a small amount of verification. Since prefill itself is the compute-heavy stage, skipping it brings an order-of-magnitude cost reduction, which explains why the hit price can be as low as one percent of the miss price.
In engineering terms, this capability is typically provided by a cloud platform’s general-purpose infrastructure, such as low-latency cache services, object storage, and message queues, used to store and schedule the KV cache.
6. Practical Advice for Developers
- Control output length: The quadratic term means long outputs are disproportionately expensive. If a structured short answer will do, don’t let the model generate at length.
- Keep the prompt prefix stable: Put the system prompt and fixed context at the very front and keep it byte-for-byte consistent to maximize the chance of a cache hit.
- Reuse conversation context: In multi-turn conversations, reuse the historical KV cache to avoid recomputing a long prefix every turn.
- Separate long-input and long-output tasks: Evaluate the cost of “long input, short output” extraction tasks separately from “short input, long output” generation tasks.
- Build cost observability: Use monitoring, alerting, and logging services to track the distribution of input/output/hit tokens and pinpoint the real cost hotspots.
Once you understand the fundamental differences between input and output in terms of compute, bandwidth, and seriality, you can turn the token bill from a “black box” into a predictable, optimizable engineering metric.
