Why Output Tokens Cost More: Inference Costs and Pricing Logic
Output tokens are often priced higher than input tokens because prefill and autoregressive decoding place different demands on compute, memory bandwidth, KV cache, and concurrency. This article explains the technical cost structure behind the price gap, why it does not imply a fixed multiplier, how cache hits can reduce repeated prefill, and how developers can optimize context, output, cache reuse, latency, and total task cost.
1. Start with the Conclusion: The Price Gap Comes from Execution, Not the Token Itself
Input tokens and output tokens are both basic units of text processed by a model, but they play different roles during inference and follow different computational paths.
For common autoregressive generation models, input is usually processed in a concentrated way through the “prefill” stage, while output is produced step by step through the “decode” stage. Prefill can process many known positions in parallel in a single forward computation. Decode must wait for the result of the previous step before it can continue to the next step.
This difference affects hardware utilization, memory access efficiency, request occupancy time, and the system’s sustainable concurrency. As a result, output tokens usually have a higher rate than input tokens, and there is a clear technical basis for this.
However, two concepts must be distinguished:
- Resource cost: the compute, bandwidth, memory capacity, and scheduling resources actually consumed to complete inference.
- External price: the rate set by the service provider based on resource cost, service level, market competition, and business strategy.
Technical cost can explain the direction of the price difference, but it cannot by itself produce a fixed price multiplier. A performance difference in one scenario should not be treated as a universal billing rule for all models.
2. Prefill: Known Input Can Be Processed in Parallel
Suppose a user submits an input of length N. The model first needs to read these tokens, compute intermediate representations for each layer, and prepare the key-value cache needed by the attention mechanism for subsequent generation, known as the KV cache.
Although the model must obey the causal constraint, meaning a position cannot access future positions, all tokens in the input are already known. Therefore, within the same layer, computations for multiple positions can still be organized and executed in batches.
2.1 Why prefill often utilizes compute better
Linear transformations in a model can be abstracted as:
Y = XW
Here, X represents the hidden representations of a batch of tokens, and W represents model weights.
When more tokens are processed at once, the same set of weights can serve multiple input positions. The underlying computation can usually be organized as larger matrix multiplications, allowing more complete data reuse and amortizing some execution overhead.
From a hardware perspective, this usually means higher arithmetic intensity: more computation can be completed for a given amount of data moved. Therefore, when input length and batch size are sufficient, the prefill stage often more easily achieves higher computational throughput.
2.2 Input is not “almost free”
Parallel processing does not mean free processing. The longer the input, the more linear transformations must be executed, and attention computation may also increase significantly.
For standard dense causal attention, the scale of attention operations during the input stage usually grows quadratically with sequence length. Efficient implementations can reduce intermediate result storage and data movement, but this does not mean the growth trend in computation is eliminated in all cases.
Therefore, “a lower input unit price” should be understood as input tokens usually being easier to process efficiently per unit, not as input computation being negligible.
3. Decoding: Step-by-Step Generation Creates Different Resource Bottlenecks
After prefill is complete, the model predicts the next token based on the current context. After this token is added to the context, the model continues to predict the following token.
This process has an obvious serial dependency:
existing context → generate one token → update context → generate another token
For the same request, ordinary autoregressive decoding cannot compute all future tokens in a concentrated way like it does with known input.
3.1 Small-batch decoding is often memory-bandwidth bound
In single-request or small-batch scenarios, each decoding step computes only a small number of new positions. Many model weights still need to participate in computation, but the number of tokens involved in each computation is limited, so weight reuse is often lower than in prefill.
At this point, linear-layer computation can be approximated as matrix-vector multiplication, or narrower matrix multiplication. Compared with large-scale matrix multiplication, it is more likely to be limited by data movement capacity.
A simplified relationship can be used to understand the lower bound of single-step execution time:
step time ≥ max(required operations ÷ effective compute, required data movement ÷ effective bandwidth)
When the second term is larger, even if the hardware still has underutilized compute units, this round of computation cannot be significantly accelerated, because computation is still waiting for data to arrive.
However, “decoding is necessarily matrix-vector multiplication” is not precise. Servers usually combine multiple requests into a larger batch, thereby improving weight reuse and computational efficiency. The actual decoding bottleneck depends on model size, batch size, context length, and hardware configuration.
3.2 KV cache reduces recomputation but does not eliminate read cost
If the full history sequence were recomputed every time a new token is generated, inference efficiency would be very low. The purpose of the KV cache is to store the keys and values already computed for historical positions so that later steps can reuse them.
But reuse does not mean access-free.
In standard full-context attention, a newly generated position still needs to compute relevance with the keys of the existing context and use the corresponding values for aggregation. The longer the context, the more KV data usually needs to be accessed.
Therefore, as generation proceeds, the system not only needs to keep reading model weights but also needs to handle a gradually growing history cache. This is an important reason why long outputs and long contexts can slow down decoding.
4. Why Output Cost Includes a Term Related to Length Squared
Let the input length be N and the planned output be M tokens. To analyze the growth trend, the resource workload of decoding step t can be approximated as:
w(t) ≈ C + α(N + t)
Where:
- C represents work at each step that is weakly related to context length, such as the main linear transformations of the model;
- α represents the marginal attention workload coefficient caused by historical context;
- t ranges from 0 to M−1.
Summing over all generation steps:
W ≈ CM + α[NM + M(M−1)/2]
This formula reveals three sources of cost:
CM: the basic workload of step-by-step generation.
Each token produced requires one round of model computation, so this part increases linearly with output length.αNM: the persistent effect of input context on all output steps.
A longer input not only increases prefill cost but may also increase the attention workload of each subsequent step.αM(M−1)/2: cumulative work as output is continuously added to context.
Earlier generated tokens become history that later steps must access, so a term related to the square of output length appears.
Applicable boundaries
First, this is a simplified model of workload, not an exact latency formula for every request. Actual execution time is also affected by parallel computation, cache hierarchy, batch changes, and bandwidth utilization.
Second, the existence of a quadratic term does not mean the final total cost is necessarily dominated by it. Within a certain length range, model body computation or weight movement may still account for the main part.
Third, if a model uses local attention, sliding windows, or other mechanisms that limit the range of historical access, the formula above needs to be adjusted. When the effective history length is constrained by a fixed window, the attention part may not continue to grow with the full output length.
Finally, “the later token usually needs to process more history” does not mean users will see a per-token price that increases token by token. Common billing methods still use a uniform per-token rate, and providers balance resource differences across requests at the overall business scale.
5. Beyond Compute: Memory Footprint and Scheduling Also Affect Price
Inference services do not run only one request. Enterprise-grade services must simultaneously meet latency, throughput, and stability requirements for many users, so resource cost also includes system-level constraints.
5.1 Long outputs occupy active request slots for a long time
Input can usually complete prefill in a concentrated burst, while long output continues through multiple decoding rounds. During this period, the request must retain context state and participate in subsequent scheduling.
Even if a single step does not take long, the accumulated time may occupy significant device time and affect the entry and execution of other requests.
5.2 KV cache consumes memory capacity needed for concurrency
KV cache usage is roughly related to the following factors:
cache usage ∝ layers × sequence length × KV heads × dimension per head × bytes per element × concurrent sequences
This also needs to account for both keys and values, as well as actual memory management overhead.
When concurrency and context length increase at the same time, cache may become an important factor limiting throughput. Once memory is occupied by long requests, the system may be able to accommodate fewer other requests.
Therefore, the cost of a long-output request is not only how many operations it completes itself, but also its continuous occupation of shared service capacity.
5.3 There is a tradeoff between higher throughput and lower latency
Putting more requests into the same batch can usually improve weight reuse efficiency. But waiting to form batches, handling sequences of different lengths, and responding to burst traffic can all affect user experience.
Interactive services often need to focus on time to first token and the interval between adjacent output tokens, and cannot simply increase batch size indefinitely for maximum throughput.
Capacity headroom retained to meet low-latency targets is also part of price formation.
6. Why Cache Hits Can Receive Significant Discounts
Input caching is related to KV cache reuse, but it should not be simply understood as “if the input content is the same, it must be free.”
If multiple requests have exactly the same prefix and the server can reuse the already computed state for that prefix, repeated prefill work for the corresponding part can be avoided. For example, repeated system instructions, fixed task rules, and common background materials may all have reuse value.
But cache hits may still involve the following costs:
- cache indexing, matching, and consistency checks;
- storage and capacity occupation of cached state;
- transfer overhead when restoring data from different storage tiers;
- loading the cache into device memory available for computation;
- continued access to the cache during subsequent decoding.
In particular: hitting the input cache mainly reduces repeated prefill; it does not make subsequent generation ignore that context.
In addition, whether a cache can be reused is usually subject to model configuration, prefix matching rules, cache lifetime, and service implementation. Cache discounts can be large, but there is no universal multiplier applicable to all services, and an extreme price gap in one case should not be treated as a general technical law.
7. Why Hardware Efficiency Cannot Directly Derive Price Multiples
The actual price ratio between input and output is also affected by deployment methods and business models, including:
- model parameter scale and the number of parameters actually involved in computation each time;
- numerical precision and quantization methods;
- attention structure and KV cache organization;
- request length distribution and peak concurrency;
- batching strategy and device utilization;
- latency targets, availability requirements, and capacity reservation;
- cache reuse rate and external pricing strategy.
Therefore, “output costs several times more than input” can be the pricing result of a particular service, but it is not a physical constant of model inference.
A more reasonable conclusion is: standard autoregressive decoding often makes it harder to achieve efficient per-token processing than prefill, so a higher rate for output has technical justification; how much higher it is must be judged against actual service conditions.
8. How Developers Can Apply These Principles to Cost Optimization
8.1 Reduce ineffective output before compressing necessary input
Limit repeated explanations, specify output structure, and avoid meaningless filler. This can usually reduce both cost and end-to-end latency.
But output is not always better when shorter. If key steps, constraints, and necessary explanations are removed, follow-up questions may increase, potentially raising total cost. The optimization goal should be the effective information needed to complete the task, not the minimum word count for a single answer.
8.2 Control the context that actually participates in inference
Context size can be reduced through relevant snippet filtering, historical conversation summarization, and removal of duplicate material. Long input not only incurs input cost but may also increase the workload of each subsequent decoding step.
However, summarization also carries the risk of information loss. For tasks involving exact citations, numerical computation, and strict constraints, necessary raw information should be retained.
8.3 Keep stable prefixes stable
Placing long-lived instructions first and frequently changing data later can help systems with prefix caching mechanisms reuse them.
Specific benefits need to be verified according to service rules. Do not assume that any similar text will hit the cache, and do not omit conditions that affect task correctness in order to improve hit rate.
8.4 Measure cost, latency, and success rate together
Comparing only per-token prices can easily lead to wrong conclusions. More practical metrics include:
- total cost per successfully completed task;
- time to first token;
- overall completion time;
- average input and output length;
- cache hit rate;
- retry count and manual correction cost.
A simple formula can be used to estimate direct cost:
request cost ≈ uncached input volume × input rate
+ cached input volume × cache rate
+ output volume × output rate
Use consistent units in the calculation and check whether the cached part uses a separate billing basis. If the service has other billing items, they should also be included in the budget.
9. Conclusion
Output tokens are usually more expensive, not because output text is “more valuable,” but because input and output correspond to different inference execution modes.
Prefill can process many known positions in parallel and usually more easily utilizes computational throughput. Autoregressive decoding must proceed step by step and, in small-batch scenarios, is more likely to be limited by weight movement, KV cache access, and serial dependencies. As context grows, decoding also continuously bears a larger historical access burden and occupies memory and concurrent service capacity.
But these principles can only explain the cost structure. They cannot produce a uniform price multiplier, nor can a simplified workload formula be treated directly as a billing formula.
For developers, the most effective approach is to manage context length, output effectiveness, cache reuse, and task success rate together. What is truly worth optimizing is not an isolated token count, but completing a valuable task reliably at acceptable latency and total cost.
