LLM API Pricing Explained: Input, Output, and Cache-Hit Billing for Cost Optimization

    A single API price hike is easy to notice but hard to interpret on its own, because LLM API pricing is a structured model built from several billing dimensions rather than one number. This article breaks down the three-tier billing model (input, output, and cache-hit tokens), explains why autoregressive output costs more than input, and how prefix caching lowers cost. It contrasts metered pay-as-you-go with subscription plans, provides a formula and a runnable script for estimating real cost from your own usage patterns, and closes with a practical cost-optimization checklist for developers.

    1. Reading the Billing Structure from a Single Price Change

    Recently, a cloud provider raised the price of its next-generation LLM API noticeably compared with the previous generation, and it redrew the unit prices for input, output, and cache hits. On the surface this is just a price adjustment. But if you only focus on “how many times more expensive it got,” you can easily miss a more important point: LLM API pricing has never been a single number. It is a structured model composed of several billing dimensions.

    Understanding that structure is the prerequisite for judging whether a service is actually cheap or expensive. For developers and businesses, the same price table can produce very different real costs under different usage patterns. So instead of fixating on the size of a single price change, it is more useful to explain the billing mechanism itself clearly first.

    2. Three-Tier Billing: Input, Output, and Cache Hits

    Most mainstream LLM services now use tokens as the billing unit and split a single request into three billing dimensions:

    • Input tokens: the entire context sent to the model, including the system prompt, conversation history, the user question, and any supplementary material.
    • Output tokens: the response the model generates.
    • Cache-hit tokens: the part of the input that hits a prefix cache and does not need to be recomputed.

    The following purely illustrative example shows the relative magnitude of the three (the numbers are only to aid understanding and do not represent any real product):

    1. Hypothetical input price: $20 per million tokens
    2. Hypothetical output price: $100 per million tokens # about 5x the input price
    3. Hypothetical cache hit: $1 per million tokens # about 1/20 of the input price

    This example carries two important economic signals: first, the output unit price is often several times the input price; second, the cache-hit unit price can be far lower than ordinary input.

    3. Why Output Costs More Than Input: The Compute Behind Autoregressive Generation

    Many people wonder: if the output is usually shorter than the input, why is it more expensive? The answer lies in the computational characteristics of autoregressive generation.

    A large model generates content token by token. For every new token it produces, it has to run a forward pass again over all the existing context. In other words, generation length and per-token compute cost are additive: when the model outputs the Nth token, it still needs to “look back” over everything that came before.

    The following pseudocode gives an intuitive feel for the difference in complexity:

    1. # Input phase: process all input tokens in parallel at once (Prefill)
    2. def prefill(input_tokens):
    3. # Highly parallel, high GPU utilization, so the unit cost is amortized
    4. return process_all_at_once(input_tokens)
    5. # Output phase: generate tokens one by one, sequentially (Decode)
    6. def decode(max_len):
    7. outputs = []
    8. for _ in range(max_len):
    9. # Each step needs a fresh forward pass and is hard to parallelize well
    10. next_token = model.forward_step(outputs)
    11. outputs.append(next_token)
    12. return outputs

    The input phase can be highly parallelized, with high compute utilization and an amortized unit cost. The output phase advances sequentially, so the real throughput of a single computation is limited and the unit cost is naturally higher. This is the fundamental compute reason why output costs more than input, and it also explains why long-form generation tasks cost significantly more than short question-and-answer exchanges.

    4. Why Cache Hits Cut Costs So Much: Reusing Already-Computed Prefixes

    The deep discount for cache hits works through prefix caching.

    In conversational, RAG, and code-assistance scenarios, requests often share a large, identical prefix, such as a fixed system prompt, unchanged knowledge-base snippets, or the history of a multi-turn conversation. Recomputing these prefixes every time wastes compute and increases time-to-first-token.

    The caching mechanism stores the intermediate state of an already-computed prefix (the key-value cache) and reuses it directly on a later hit, performing incremental computation only for the new content:

    1. First request: [2000-token system prompt] + [user question] -> prefix must be fully computed
    2. Second request: [2000-token system prompt] + [new question] -> prefix hits cache, only the new question is computed

    Because the reused portion generates almost no new computation, providers can offer a near-symbolic cache price. This also carries an important engineering lesson: a stable, structured prompt design is itself a way to save money.

    5. Subscription Plans vs. Pay-as-You-Go: Why List Price Is Just a “Suggested Retail Price”

    The original discussion made a sharp observation: in a sense, API pricing is a “suggested retail price.” The reason is that the heaviest users often go through a coding subscription plan (subscription-based) rather than pure metered API usage, and the two are different cost models.

    The differences can be summarized as follows:

    Dimension Pay-as-you-go (API) Subscription (Plan)
    Billing Based on actual token usage Fixed monthly fee + quota pool
    Cost predictability Low (varies with usage) High (cost is capped)
    Quota constraints No quota cap, only rate limits Quota pool cap with periodic resets
    Best for Low or spiky usage High-intensity, steady usage

    For high-frequency users, a subscription plan does not necessarily feel cheaper per token. There are three reasons:

    1. The ceiling of the quota pool: a plan gives a finite quota, which is quickly exhausted under heavy use, after which you are rate-limited or must purchase more.
    2. Differences in periodic quota resets: reset cycles (weekly, daily) and reset rules differ across services, and this directly affects the effective compute available to you.
    3. Quotas for different scenarios may be independent: conversational and code-assistance scenarios may use separate quota pools that cannot simply be borrowed against each other, further compressing the quota actually available for a single use.

    As a result, when a user subscribes to several services at once, the “perceived price difference” quickly converges, everyone hits the quota wall and gets rate-limited, so the real value gap is far smaller than the gap in listed unit prices.

    6. How to Estimate Your Real Cost

    Instead of being led by the listed numbers, build your own cost-estimation method. The core formula is not complicated:

    1. cost per request = input tokens × input price
    2. + output tokens × output price
    3. + cache-hit tokens × cache-hit price

    The key in practice is to accurately estimate the proportion of each dimension. Here is a runnable estimation script as an example:

    1. def estimate_cost(input_tokens, output_tokens, cache_hit_tokens,
    2. price_in=20, price_out=100, price_cache=1):
    3. """Estimate the cost of a single request, priced per million tokens"""
    4. real_input = input_tokens - cache_hit_tokens
    5. cost = (real_input * price_in
    6. + output_tokens * price_out
    7. + cache_hit_tokens * price_cache) / 1_000_000
    8. return cost
    9. # Scenario A: short Q&A, no cache
    10. print(estimate_cost(input_tokens=1000, output_tokens=500, cache_hit_tokens=0))
    11. # Scenario B: long-document RAG, heavy prefix reuse
    12. print(estimate_cost(input_tokens=20000, output_tokens=1000,
    13. cache_hit_tokens=18000))

    For the same kind of call, Scenario B may actually cost less than the seemingly “shorter-input” Scenario A, because it hits the cache heavily. This shows that listed unit price alone cannot determine cost; you must factor in the usage pattern.

    7. A Cost-Optimization Checklist for Developers

    Drawing on all of the mechanisms above, here is a practical set of optimization strategies:

    • Keep prompt structure stable to maximize cache hits: put unchanging system prompts, instructions, and reference material first and keep them fixed, avoid frequent changes, and make the prefix as cache-friendly as possible.
    • Control output length: because output costs more per token, instruct the model to answer concisely and cap the maximum generation length when necessary.
    • Trim the input context: deduplicate, prune, and rerank retrieval results before sending them to the model to reduce useless tokens.
    • Choose the billing model by scenario: use pay-as-you-go for low-frequency or spiky usage; evaluate a subscription plan for steady, high-intensity use, and plan your task cadence around the periodic reset rules.
    • Set up usage monitoring and alerts: use logging and monitoring/alerting capabilities to collect token consumption, cache-hit rate, and the cost curve, so cost is observable and can be flagged early.
    • Evaluate “feels cheap” with caution: under a subscription, the real constraints are quota and resets, not the listed unit price, so factor the quota wall and rate-limit rules into your choice.

    8. Conclusion

    A single price change draws attention because it puts the question “where exactly does an LLM cost money?” back on the table. The rational approach is not to agonize over how many times a unit price went up, but to understand the compute logic behind the three-tier billing of input, output, and cache; to see the distinct constraints of subscription and pay-as-you-go models; and to keep cost in your own hands with quantifiable estimation and optimization methods. Once the billing mechanism is fully clear, choosing a service stops being a passive decision driven by listed prices and becomes an active decision based on your real workload.