Why Are Output Tokens More Expensive Than Input Tokens? A Breakdown of the Compute Cost Behind LLM Inference

    This article explains why LLM API pricing charges more for output tokens than input tokens, often by three to five times. It breaks down the two inference phases—prefill and decode—and shows how prefill is compute-bound while decode is memory-bound. You will find a quantitative framework for per-token marginal cost, why output cost grows with a quadratic term, how the gap translates into GPU-seconds, and why cache hits versus misses can differ by orders of magnitude. The article closes with practical guidance for cost estimation and optimization.

    Why Are Output Tokens More Expensive Than Input Tokens? A Breakdown of the Compute Cost Behind LLM Inference

    On almost every LLM application bill, teams run into the same counterintuitive pattern: a single token can cost three to five times more on the output side than on the input side. The first reaction is often that the vendor is manipulating prices. But once you break inference down to matrix operations and memory access, the price gap turns out to have a solid physical basis. This article explains why that gap exists and provides a quantitative framework you can use for cost estimation.

    1. Two Phases: Prefill and Decode

    A complete inference request is usually split into two phases with very different computational characteristics.

    The prefill phase processes all N tokens of the user input. The representations of all tokens can be computed in parallel in a single pass, which is essentially a series of matrix-by-matrix operations. Parallelism is extremely high, the compute units stay fully fed, and the phase is a classic compute-bound scenario.

    The decode phase emits M output tokens one at a time. Each step adds only one new position, yet the model weights must be read in full, and the attention part degenerates into matrix-by-vector operations. The floating-point work per step is small, but the amount of data that has to be moved does not shrink at the same rate. The bottleneck therefore shifts from compute to memory bandwidth, making this a classic memory-bound scenario.

    This difference is the starting point for all the cost reasoning that follows: it is not that output is “more valuable,” but that output “wastes hardware” more.

    2. Why the Marginal Cost per Token Rises Linearly

    Let C be the fixed cost of one full pass over the model weights, α the marginal coefficient of the attention computation, and t the number of tokens already generated. The approximate cost of generating the next token is:

    1. cost(t) ≈ C + α * (N + t)

    Here N is the input length and t is the current output position. The key is the (N + t) term: every time a new token is generated, the next forward pass has to read a KV cache that has grown by one slot. The longer the cache, the more data the attention part must scan, so the marginal cost climbs linearly with output length. This is exactly where “each token is a little more expensive than the previous one” comes from.

    Summing over t from 0 to M−1 gives the total cost of the entire output side:

    1. total ≈ C * M + α * (N * M + M * (M - 1) / 2)

    Notice that the last term is on the order of M². In other words, the accumulated cost on the output side does not grow linearly with output length; it carries a quadratic term. When output length grows from a few hundred to a few thousand tokens, this term quickly becomes dominant, so the unit cost of long-form generation is clearly worse than that of short answers.

    3. Translating to GPU-Seconds: Where the Five-to-Tenfold Gap Comes From

    Theoretical FLOPs explain only part of the gap. What actually determines the bill is how many GPU-seconds it takes to produce one token.

    Prefill has high utilization, and the available compute is used fully. Decode, by contrast, has to move the weights and the ever-growing KV cache from memory to the compute units at every step, leaving a large amount of compute idle. Once both phases are converted to the same measure, the hardware time per token on the decode side is typically five to ten times that of the prefill side.

    This also explains the three-to-fivefold output/input price ratio common in the industry: it is not a marketing choice but an approximate mapping of resource consumption. Ratios across different models fall between 2.5 and 8, and the variation comes mainly from pricing strategy and from how much the architecture mitigates the decode bottleneck—for example, more efficient attention structures, more aggressive cache compression, and wider batch scheduling all reduce the actual cost on the decode side.

    4. The Order-of-Magnitude Gap Between Cache Hits and Misses

    Consider a more extreme case: the price gap between a cache hit and a miss can reach two orders of magnitude. The number of input tokens is exactly the same in both cases; the only difference is that on a hit, prefill does not need to be rerun and the already-computed KV cache can be reused directly.

    In terms of cost structure, this is equivalent to erasing the large fixed expense of C * N and keeping only a small amount of verification and concatenation overhead. So any stable prefix—system prompts, long documents, few-shot templates—should be designed as a cacheable structure.

    Practical recommendations:

    • Put invariant content first and variable content last to maximize prefix reuse;
    • Set reasonable expiration and invalidation policies for the cache to avoid an inflated hit rate;
    • Track the token share of hits and misses separately in your monitoring and alerting system, and treat it as a core metric on the cost dashboard.

    5. Four Takeaways for Engineering Practice

    1. Cost estimation cannot rely on the per-token price alone; the quadratic term of output length must be included in the model, and long-output scenarios are especially sensitive.
    2. Optimizing the output side takes priority over optimizing the input side: capping the maximum generation length, using structured output, and reducing redundant reasoning chains give the most direct gains.
    3. Improving the cache hit rate is the most cost-effective lever, and it is an architecture-level optimization rather than parameter tuning.
    4. If you use a cloud inference service, you can combine elastic scaling on a container platform, object storage for long documents, and logging and monitoring services for usage attribution, breaking the bill down to the business dimension.

    Once you understand this logic, the numbers on the pricing table are no longer a black box: on the input side you are buying parallel compute, and on the output side you are buying serial time dragged down by bandwidth and cache length.