How to Calculate LLM API Costs After a 5x Price Increase

    A practical breakdown of how LLM API pricing actually works across input, output, and cache-hit tokens, why a 5x unit price increase does not mean a 5x larger bill, how to compare plans using leverage ratio instead of sticker price, and six cost-control techniques including prefix caching, context compression, and model routing. Includes a reusable cost estimation method with sample code.

    1. The Phenomenon: A 5x Unit Price Increase Does Not Mean a 5x Larger Bill

    The industry recently saw a typical price adjustment: a general-purpose LLM’s public price rose roughly fivefold compared with the previous generation, reaching the order of 100 RMB per million tokens on the output side and 20 RMB on the input side, while the cache-hit portion stayed at around 1 RMB. Most developers’ first reaction is “we can’t afford this anymore,” but that instinct is usually wrong.

    The reason is that an API bill is never determined by unit price alone. It follows this identity:

    1. Bill = input tokens × input price
    2. + output tokens × output price
    3. + cache-hit tokens × cache price
    4. + extra consumption from failed retries and timeouts

    Unit price is only three of the coefficients. What really determines the magnitude is token structure. In a single request, the system prompt, tool definitions, conversation history, and retrieved document fragments all fall on the input side and often account for more than 90% of the tokens. The output the model actually generates is usually a very small share. As a result, a fivefold increase in output pricing often has less marginal impact on the bill than whether the input side hits the cache.

    2. Split Pricing into Three Parts: Input, Output, and Cache Hits

    The first step to understanding cost is accepting that these three token types are three completely different products.

    Input tokens are a “read cost.” They grow linearly with context length, and long-document summarization, code repository Q&A, and multi-turn agent tasks all push this portion up. Output tokens are a “generation cost,” typically priced several times higher than input because autoregressive decoding is more compute-intensive. Cache-hit tokens are a “repeat read cost,” priced as low as one twentieth of the input price, essentially reusing the computed result for a stable, unchanging prefix (system prompt, tool schema, long documents).

    This structure yields the first cost-reduction principle directly: make unchanging content as long and as early as possible, and make changing content as short and as late as possible. Prefix stability determines the cache hit rate, and the cache hit rate affects the bill multiplicatively.

    3. Look Beyond Unit Price: Evaluate Plan Value with Leverage Ratio

    The real focus of the original discussion is not unit price but “how much usage you get back per unit of currency paid.” This metric can be formalized as the leverage ratio:

    1. Leverage ratio = usable quota within the plan ÷ plan price

    By the magnitudes in public discussion, some overseas offerings provide a leverage of more than 20x at the low tier and close to 50x at mid-to-high tiers, while the adjusted domestic option offers roughly only 6x to 14x at the 200 RMB tier. The gap is not 1.5x but 3x to 5x.

    It is worth stressing that the leverage ratio is only a static metric and must be combined with “average consumption per task” to reflect the real experience. If average token consumption per task in agent benchmarks is close to that of top-tier models, then a low leverage ratio directly means “fewer tasks completed for the same money.” Only when the low tier reaches more than 20x and the high tier more than 70x can a product be considered comparable on the same price band.

    4. Budget First: A Reusable Estimation Method

    Do not judge whether something is expensive by feel. Calculate first. The steps:

    1. Sample real requests and compute the mean and percentiles (P50/P95) for the three token types: input, output, and cache hits.
    2. Plug them into the three-part pricing to get the cost per request.
    3. Multiply by daily request volume and a retry factor (1.2 is a reasonable starting value).
    4. Use P95 rather than the mean for capacity planning to avoid an out-of-control bill at month end.

    Illustrative implementation:

    1. def estimate_cost(reqs, in_tok, out_tok, cache_tok,
    2. p_in=20, p_out=100, p_cache=1, retry=1.2):
    3. per = (in_tok * p_in + out_tok * p_out + cache_tok * p_cache) / 1_000_000
    4. return reqs * per * retry

    5. Six Actionable Cost-Reduction Techniques

    • Prefix pinning and cache reuse: keep the system prompt, tool definitions, and few-shot examples together at the very front, and avoid volatile concatenation such as timestamps.
    • Context compression: apply rolling summaries to prior turns, replacing full history with a structured summary, which usually cuts input by more than half.
    • Retrieval reranking and truncation: keep only passages strongly relevant to the current question and cap the length injected per request.
    • Tiered model routing: send intent classification, format conversion, and extraction tasks to a small model, and escalate to a large model only for complex reasoning.
    • Batching and asynchronization: merge deferrable tasks into combined submissions, trading throughput for unit price.
    • Observability loop: use logging services and monitoring alerts to attribute token consumption by business line, and set budget alerts and circuit-breaker thresholds.

    Routing logic on the gateway side can be minimal:

    1. def route(task):
    2. if task.kind in {"classify", "extract", "format"}:
    3. return SMALL_MODEL
    4. if task.difficulty >= 3 or task.needs_reasoning:
    5. return LARGE_MODEL
    6. return SMALL_MODEL

    6. Conclusion

    A fivefold unit price increase is a fact, but whether the bill spirals out of control depends on architecture. Split cost into input, output, and cache; evaluate plans with the leverage ratio rather than the sticker price; then constrain consumption with the three-piece set of cache hit rate, context compression, and tiered routing. Most workloads can maintain their existing cost curve through a price-increase cycle. Building a unified token gateway on top of the general-purpose model services, object storage, message queues, and monitoring and alerting capabilities offered by platforms such as Baidu AI Cloud is the key step in turning an unpredictable bill into a predictable engineering metric.