Understanding LLM API Pricing: How Token Billing Logic Shapes Your Costs

    This article breaks down the billing logic behind recent LLM API price increases, explaining what the ratio between input, output, and cache-hit rates reveals about real inference costs. It covers the billing semantics of three token types, a reusable cost-estimation model, a practical optimization checklist, a framework for choosing between pay-as-you-go and subscription plans, and team-level adoption advice. Readers will learn to treat token structure as a controllable engineering variable rather than passively absorbing price changes.

    1. The Phenomenon: Unit Prices Multiply, but Bills Don’t Scale the Same Way

    Recently, flagship model API unit prices have risen sharply compared to the previous generation: output is now around 100 RMB per million tokens, input around 20 RMB, and cache hits around 1 RMB. Discussions easily get stuck on whether it is “expensive,” but the more valuable question is what the ratio structure among these three tiers tells us, and what engineering measures can offset it.

    Start by building a sense of scale. The cache-hit price is about 1/20 of the input price, and the input price is about 1/5 of the output price. That means there is roughly a 100x price gap between a cached token and an output token. This ratio is not set randomly; it approximately maps the distribution of real compute costs during inference. Processing uncached input requires full attention computation and KV cache writes; a cache hit only reuses existing state; and generating output requires token-by-token autoregressive decoding, where every step reads the entire history of states, incurring the highest memory-access overhead.

    The conclusion: a price increase is a change in unit price, while the bill is a product of structure. For the same workload, raising the cache hit rate from 20% to 60% can change costs far more than the unit price increase itself.

    2. Billing Semantics of the Three Token Types

    • Input tokens: the portion of the current request that is not reused from cache, billed at the input rate.
    • Output tokens: content generated by the model, including reasoning and the final answer, billed at the output rate and usually the most expensive tier.
    • Cache-hit tokens: the portion whose prefix exactly matches already-cached content, billed at a very low rate, but generally subject to constraints such as a minimum time-to-live, capacity limits, and eviction policies.

    Three common pitfalls deserve attention in engineering. First, caching is prefix-based, so any change to content near the front causes all subsequent tokens to degrade to cache misses. Second, whether multimodal inputs, tool return values, and retrieval snippets can be cached depends on the platform implementation and cannot be assumed to be cacheable by default. Third, caches have a lifecycle, and cold starts under burst traffic produce concentrated cache misses.

    3. A Reusable Cost-Estimation Model

    Estimate by token structure, not by “number of calls.” The sample code below provides a practical baseline algorithm:

    1. def estimate_cost(reqs, price):
    2. # price: unit price per million tokens, in RMB
    3. total = 0.0
    4. for r in reqs:
    5. in_tok = r["input_tokens"]
    6. hit = r["cached_tokens"]
    7. out = r["output_tokens"]
    8. miss = max(0, in_tok - hit)
    9. total += (miss * price["input"]
    10. + hit * price["cache"]
    11. + out * price["output"]) / 1_000_000
    12. return total

    With this function, you can run sensitivity analysis: fix the workload, set the hit rate to 0, 0.3, and 0.6 separately, and observe the decline curve of total cost; then scale up output length alone to see which item is the real cost driver. Most teams conclude that output length and uncached input together dominate the bill, and both are architecturally controllable.

    4. Optimization Checklist: Turning the Price Gap Structure into Design Constraints

    1. Prefix stabilization. Put the system prompt, tool definitions, a few examples, and the glossary at the front with fixed versions, and move volatile fields such as timestamps, session IDs, and random numbers to the end. This is the most cost-effective step for improving the hit rate.
    2. Context layering. Split and summarize long documents first, then inject relevant snippets on demand instead of stuffing in the whole document. Shorter context means fewer uncached input tokens.
    3. Output constraints. Use explicit structured formats, word limits, and instructions such as not repeating the input to compress generation length, directly cutting the most expensive tier.
    4. Tiered routing. Route tasks by difficulty to models of different size tiers: send simple classification and formatting to lightweight tiers, and reserve complex reasoning for the flagship tier.
    5. Batching and asynchrony. Use asynchronous or batch channels for offline tasks, trading latency for unit price.
    6. Observability. At the gateway layer, record the three token counts, hit rate, and converted cost for each request, aggregate by business line, and build a cost dashboard with alerts.
    1. Request -> Prefix normalization -> Cache lookup -> Reuse if hit
    2. -> Full encoding if miss -> Generation -> Log three token types and cost

    5. A Selection Framework for Pay-As-You-Go vs. Subscription Plans

    Two common purchasing paths exist in the industry: a fixed monthly fee in exchange for a quota, or paying for what you use.

    Pay-as-you-go offers elasticity and no idle capacity, making it suitable for scenarios with large traffic fluctuations or in a validation phase; the risk is the lack of a hard cap, requiring self-built quotas and circuit breakers. Subscription plans offer predictable costs and usually lower unit costs, making them suitable for stable, high-frequency coding and knowledge-work workloads; the risks are complex quota-deduction rules that may distinguish model tiers and context lengths and reset on weekly or credit cycles, plus possible throttling during peak hours.

    The decision method can be simplified into three steps: first, tally the real token structure over the past few weeks; then calculate the pay-as-you-go monthly cost baseline; finally, compare whether the plan’s converted unit price and quota ceiling cover the peak. If the peak exceeds the plan quota and overflow is billed at a high rate, a hybrid model often beats a single model.

    6. Team Adoption Advice

    Treat token cost as a first-class performance metric, alongside latency and success rate. Build a unified wrapper at the interface layer so that model replacement and routing policies are configurable; add cost-regression checks for prompt changes in CI to prevent a single prompt edit from quietly raising the entire bill; set target values for the cache hit rate and include them in retrospectives. Baidu AI Cloud provides supporting capabilities in model services, monitoring and alerting, and logging services, which teams can use to build their own cost-governance loop.

    7. Conclusion

    The unit price increase itself is uncontrollable; what is controllable is token structure. Understanding the compute logic behind the three price tiers—input, output, and cache hit—and making prefix stabilization, context layering, output constraints, and model routing default engineering practices means any round of price adjustment becomes a parameter update rather than a passively accepted cost shock.