Why Output Tokens Cost More Than Input Tokens in LLM Inference
LLM APIs often charge more for output tokens than input tokens. This gap is rooted in the different computation paths of the prefill and decode phases, not in the perceived value of generated text. This article explains why input tokens can be processed in parallel, why output tokens must be generated sequentially, why decode is often memory-bandwidth-bound, how KV cache growth affects marginal cost, and what developers can do to reduce output-side expenses.
Two Phases in LLM Inference: Prefill and Decode
In large language model inference, input tokens and output tokens are not processed through the same computational path. A single inference request can be split into two phases:
- Prefill: The model processes the entire user input at once.
- Decode: The model generates output tokens one by one from the existing context.
Input token costs are mainly concentrated in the prefill phase, while output token costs are mainly concentrated in the decode phase. The difference in parallelism and hardware utilization between these two phases is what causes input and output rates to differ.
It is important to note that token prices are not equal to some fixed physical cost. Actual pricing is also influenced by model scale, service quality, resource supply, caching strategy, concurrency level, and business model. However, from the underlying compute mechanism, output tokens often do have a higher marginal cost.
Why Input Tokens Can Be Processed Efficiently
Let the input sequence length be (N) and the model hidden dimension be (d). During prefill, the model can process all (N) tokens simultaneously.
The main computations in a Transformer layer include:
- Query, key, and value projections in attention;
- Attention matrix computation;
- Output projection;
- Matrix multiplications in feed-forward networks;
- Layer normalization, activation functions, and other auxiliary operations.
At a coarse level, the compute cost of one layer can be expressed as:
[
O(Nd^2) + O(N^2d)
]
where:
- (O(Nd^2)) mainly comes from linear layers and feed-forward networks;
- (O(N^2d)) mainly comes from attention-related matrix computations.
Although the attention cost grows with sequence length, prefill has a key characteristic: many tokens can be computed in parallel.
GPUs are especially good at large-scale matrix operations. When the input sequence is long enough, linear layers can be organized into large matrix multiplications, so compute units receive enough data to stay busy. Compared with processing vectors one by one, this style of computation makes it easier to:
- Improve compute core utilization;
- Coalesce memory accesses;
- Use high-throughput matrix operation instructions;
- Batch work across multiple requests;
- Amortize scheduling and kernel launch overhead.
Therefore, input tokens may be large in number, but from the hardware perspective they can often be processed “in bulk.” As long as input length and concurrency reach a certain scale, GPU compute resources can be utilized more effectively.
Why Output Tokens Must Be Generated Sequentially
The output phase uses an autoregressive mechanism. The model generates the first token, adds it to the context, then generates the second token, and so on.
Assume the model needs to generate (M) tokens. The basic process is:
existing context -> generate token 1existing context + token 1 -> generate token 2existing context + token 1 + token 2 -> generate token 3...
This dependency means output tokens cannot be fully parallelized in the same way as input tokens. Token (t+1) depends on the result of token (t), so at least within a single request, the decode process has an unavoidable serial component.
For each generated token, the model must perform a complete forward pass. Although the inference system can use KV cache to avoid recomputing the queries, keys, and values of historical tokens, the model weights still need to participate in the computation for the current token.
In other words, generating one token is not a small local operation. The current token must pass through all layers of the model.
Decode Bottleneck: Memory Bandwidth, Not Raw Compute
At each decode step, the number of tokens being processed is usually very small. In the common case, each request processes only one new token per step. As a result, the matrix operation shape becomes closer to “matrix times vector” rather than the more efficient “matrix times matrix.”
This creates two consequences.
1. Compute Units Are Hard to Saturate
Large matrix multiplications can keep GPU compute cores busy, while matrix-vector operations have relatively limited parallelism. Even if the model needs to read a large amount of weight data, the actual number of multiply-accumulate operations may not be enough to fully occupy all compute units.
2. Weight Reads Become the Main Cost
Every generated token requires the model to use weights across different layers. For large-parameter models, this means the inference hardware must continuously move weights from high-bandwidth memory regions to compute units.
At this point, the limiting factor is often not “whether there are enough multipliers,” but:
Whether the weights and cached data can be delivered to the compute location fast enough.
This is a typical memory-bandwidth-bound scenario. GPU utilization metrics also need to be interpreted carefully here. The compute utilization shown by monitoring tools may not be high, but memory bandwidth, cache access, or memory controllers may already be close to the bottleneck.
Therefore, although decode looks like it only generates one token at a time, each step may actually require a weight-access sweep across the entire model.
Why KV Cache Makes Later Tokens More Expensive
In the attention mechanism, historical tokens produce keys and values. To avoid recomputing this historical information at every step, inference systems usually store those intermediate results. This is called KV cache.
Assume the original input length is (N), and (t) output tokens have already been generated. The context length that needs to be considered in the next step is approximately:
[
N+t
]
When generating a new token, the current query vector needs to match against historical keys and then aggregate the corresponding values. Therefore, as the context grows, the amount of data involved in each step’s attention operation also increases.
A simplified model of the cost at step (t) can be written as:
[
C_t \approx C+\alpha(N+t)
]
where:
- (C) is the base cost of reading model weights and performing fixed forward computation;
- (\alpha(N+t)) is the attention and KV cache access cost related to the current context length;
- (\alpha) is a coefficient that depends on model structure, hidden dimension, attention head configuration, and hardware access patterns.
If the model continuously generates (M) tokens, the total cost can be approximated as:
[
\sum_{t=0}^{M-1} C_t
\approx
CM+\alpha\left(NM+\frac{M(M-1)}{2}\right)
]
This expression reveals an important pattern: output cost does not always grow strictly linearly with token count.
In the formula:
- (CM) is the fixed model forward cost borne by every output token;
- (\alpha NM) is the cumulative impact of the input context on all output steps;
- (\alpha M(M-1)/2) is the quadratic term caused by the output sequence’s own growth.
Therefore, the longer the generated sequence, the higher the marginal cost of later tokens may be compared with earlier tokens. The idea that “after generating each token, the next one becomes more expensive” is essentially the result of growing KV cache access costs as the cache expands.
However, in real systems, whether the quadratic term is significant depends on context length, model structure, KV cache compression, batching strategy, and memory hierarchy. It is an important theoretical trend, not a guarantee that every request will show strict quadratic growth.
Why the Input/Output Price Gap Is Not a Direct Multiple of Theoretical Cost
From the perspective of physical resources, the output side is often more expensive than the input side. The main reasons include:
- The output phase has serial dependencies;
- The per-step matrix size is small, so compute utilization is lower;
- Every output token requires a full model forward pass;
- KV cache grows with context;
- Long outputs extend GPU occupancy time per request;
- Decode is harder to amortize fixed overhead through batched matrix operations.
But the actual price ratio usually does not equal some hardware cost ratio. Inference services also need to account for the following factors.
Concurrency and Continuous Batching
The server can batch the tokens currently being generated by multiple requests into one batch. This effectively merges many matrix-vector operations into larger matrix operations, improving GPU utilization and lowering per-token cost.
However, continuous batching is affected by request arrival time, sequence length, memory capacity, and scheduling policy. Different workloads have different concurrency patterns, so their costs are not the same.
Service Quality Requirements
Low-latency services usually need to reserve more resources and cannot simply maximize batch size. If users require shorter time-to-first-token or more stable per-token output speed, the system may not be able to wait long enough for request aggregation.
Model Structure Differences
Models differ in parameter count, number of layers, hidden dimension, attention structure, and KV cache layout. Some architectures can reduce KV cache size or reduce data access during decode, but they cannot completely eliminate the serial nature of autoregressive generation.
Pricing Strategy
Service prices also include capacity planning, operations, peak redundancy, reliability guarantees, and product strategy. Therefore, the input/output price ratio is a combined result and cannot be interpreted as a direct mapping of one hardware metric.
Why Cache Hits Can Dramatically Reduce Input Cost
In addition to the input/output price difference, cache hits and cache misses can also result in a large price difference.
When a long prefix appears repeatedly across multiple requests, the system can save the intermediate state from previous computations. Later requests can reuse it instead of performing the full prefill computation again.
For example, the following content may be cacheable:
- Fixed system instructions;
- Long enterprise knowledge-base prefixes;
- Repeatedly used tool descriptions;
- Historical content that remains unchanged in multi-turn conversations;
- Uniform format constraints and templates.
After a cache hit, the system usually still needs to perform context verification, cache lookup, and subsequent decoding, but it can avoid a large number of repeated matrix computations. Compared with processing the entire input again, the savings can be significant.
However, cache is not “free storage.” It consumes memory or other storage resources and requires handling:
- Cache lifecycle;
- Isolation between different requests;
- Version and model consistency;
- Context prefix matching;
- Eviction policies;
- Capacity contention under high concurrency.
Therefore, the lower price of cache hits is essentially a reflection of reusing already computed results, not evidence that input tokens require no computation.
How Developers Can Reduce Output Cost
Once the cost sources are understood, the following directions can be used for optimization.
1. Control Unnecessary Output Length
If a task only needs structured results, explicitly define field ranges, length limits, and stopping conditions. Overly long explanations increase decode steps and may also expand KV cache access costs.
2. Compress Repeated Context
Avoid sending the exact same rules, documents, and tool instructions in every request. For stable prefixes, design a consistent template to improve cache reuse opportunities.
3. Break Large Tasks into Reasonable Steps
Asking the model to generate extremely long content in one request can make later tokens more expensive. For complex tasks, a phased workflow such as planning, retrieval, execution, and summarization can balance accuracy and cost.
4. Distinguish Low-Latency from High-Throughput Scenarios
Real-time interaction is more concerned with time-to-first-token and per-token response speed. Offline batch processing is better suited to larger batches and higher hardware utilization. The same inference strategy should not be used for both scenarios.
5. Prefer Structured Output
Structured output reduces redundant content generated by free-form responses and makes automatic validation easier. The more clearly output fields are defined, the easier it is to control token count.
Conclusion
The price difference between input tokens and output tokens is not fundamentally because output text is “more valuable.” It is because the two correspond to different computation processes.
The input phase can process many tokens in parallel and is well suited to high-throughput matrix operations. The output phase must generate tokens autoregressively, with each step requiring a full model forward pass and access to a growing KV cache. The main bottleneck often shifts from raw compute to memory bandwidth and data movement, leading to higher per-token resource consumption.
From a cost-model perspective, total output cost usually includes fixed per-token overhead, the cumulative impact of the input context, and an additional term related to output sequence growth. Cache hits reduce repeated prefill work by reusing already computed intermediate results.
When designing large language model applications, developers should not only focus on input token count. A more reasonable cost analysis should also consider output length, context growth rate, cache hit rate, concurrency patterns, and latency requirements. Only by placing these factors into a unified inference cost model can the rate difference be truly understood and effective optimization paths be found.
