Why LLM Bills Spike: Cost Governance for Tokens, Caching, and Routing

    Many teams see their monthly AI bill multiply even when call volume stays flat. This article explains the three structural drivers behind rising LLM costs—expensive output tokens, missed prefix-cache discounts, and poor model routing—and shows how to measure and control them. You will learn a practical cost framework, how to instrument token usage, how to design stable prefixes for higher cache hit rates, and how to tier requests across model capabilities with confidence-based fallback. The goal is to turn AI spending from a month-end surprise into a predictable, per-day metric.

    1. The Real Reason Bills Spike: Structure, Not Unit Price

    Most teams react the same way the first time they see a monthly AI bill: call volume has not grown tenfold, yet the cost has multiplied several times over. The cause is usually not that “the unit price went up,” but that three structural factors are deteriorating at the same time.

    First, the unit price of output tokens is often several times that of input tokens, and agent-style applications naturally have a high share of output. Second, the cache is not actually being hit, so repeated prefixes that should be billed at a discounted rate are charged at full price again and again. Third, routing is missing, so every request goes to the strongest model, and even simple tasks pay flagship prices.

    Put these three points together and you get a simple cost inequality:

    1. Total cost ≈ Σ(input tokens × input price + output tokens × output price)
    2. - discount savings from cache hits
    3. + premium from poor routing

    Governing the bill essentially means compressing all three of these at once.

    2. Pricing Model: Treat the “Current Model” as a Sample, Not a Conclusion

    A common pricing model in the industry is based on the input price, cache-hit price, and output price per million tokens. It is worth stressing that specific models and unit prices change very quickly, so any price table can only serve as a sample of the calculation method. Before going live, you should rely on the actual bill in the provider’s console. What stays effective in the long run is the analysis framework below.

    Pricing dimension Description Optimization lever
    Input price Prompts, context, retrieved snippets, conversation history Trim context, reuse prefixes
    Cache-hit price Repeated prefixes billed at a significant discount Stable prefixes, higher hit rate
    Output price Generated content, usually the most expensive Limit length, structured output
    Routing premium Using a high-capability model for low-difficulty requests Tiered selection, confidence fallback

    A key implication: since the output price is usually several times the input price, any prompt habit of “generating a bit more to be safe” amplifies the bill by that same multiple. Managing output length as a budget item often delivers immediate gains.

    3. Tokens: From “Feels Expensive” to “Measurable”

    The first step in cost governance is measurement. Without token attribution by business, by session, and by model, optimization is just guesswork.

    It is recommended to instrument logging uniformly on the application side, recording at least the following fields:

    1. {
    2. "biz": "customer_service",
    3. "session_id": "s-10086",
    4. "model_tier": "small",
    5. "input_tokens": 1840,
    6. "cached_tokens": 1500,
    7. "output_tokens": 260,
    8. "latency_ms": 1320,
    9. "cache_hit": true
    10. }

    With this data, you can compute three core metrics: average cost per request, cache hit rate, and output-to-input ratio. In practice, if the cache hit rate stays persistently low in long-context, repeated-call scenarios, the prefix design has a problem; if the output-to-input ratio stays high, the prompt is inducing the model to produce long output.

    Common ways to compress input include: placing stable system instructions, tool descriptions, and examples at the very front of the prompt to form a reusable prefix; reranking and truncating retrieval results to keep only highly relevant snippets; and applying rolling summaries to conversation history instead of concatenating everything.

    4. Caching: The Most Easily Wasted Discount

    The logic behind prefix caching is straightforward: the hit portion is billed at a discounted price. But it is extremely sensitive to “prefix stability”—if even one byte in the prefix changes, everything after it is invalidated.

    Bad pattern:

    1. Call 1: system instruction + current time 2026-08-06 14:22:31 + user question
    2. Call 2: system instruction + current time 2026-08-06 14:22:47 + user question
    3. → Each call is treated as a brand-new prefix, zero cache hits

    Good pattern:

    1. [Stable segment] system instruction + tool definitions + domain knowledge + output format constraints
    2. [Variable segment] timestamp, session context, user question
    3. → The stable segment can be reused, and the hit portion enjoys the discount

    There are three engineering points: put volatile content at the end; avoid inserting random IDs, timestamps, or request sequence numbers into the stable segment; and keep prefixes consistent within a batch for batch jobs. In addition, caches usually have a time-to-live limit, so burst traffic and low-frequency tasks should be evaluated separately for their benefits. Do not blindly assume that “adding a cache always saves money.”

    5. Routing: Put Each Type of Request in the Right Capability Tier

    The goal of routing is not to “always use the cheapest option,” but to match difficulty with capability. A common approach is to layer requests by complexity: classification, extraction, format conversion, and short summarization go to a lightweight tier; multi-step reasoning, code generation, and long-document agent tasks go to a high-capability tier.

    1. def route(req):
    2. if req.kind in {"classify", "extract", "reformat"}:
    3. return "small"
    4. if req.estimated_steps <= 2 and req.confidence > 0.8:
    5. return "small"
    6. return "large" # complex reasoning and agent workflows

    A more robust approach is “small model first + confidence fallback”: the lightweight tier produces a result with a self-assessed score first, and if the score falls below a threshold, the request is escalated to a large model and recomputed. Compared with sending everything to the high tier at once, this strategy significantly lowers average cost in most businesses while confining high cost to the requests that are genuinely difficult.

    6. Implementation Roadmap: Four Steps to Turn Cost into a Controllable Metric

    1. Attribution: Build a token ledger by business and by model dimension, so you first see where the money goes.
    2. Peak shaving: Address overly long context and redundant output; set output-length and structure constraints.
    3. Efficiency: Rebuild stable prefixes and raise the cache hit rate, converting repeated overhead into discounted overhead.
    4. Tiering: Roll out tiered routing and fallback mechanisms, and set budgets and alerts for each tier.

    The supporting engineering measures can reuse a general capability combination: use a logging service for usage auditing, use monitoring and alerting to set thresholds on daily cost, use a message queue to smooth out batch-job peaks, and use object storage to accumulate reusable knowledge snippets that reduce repeated input.

    7. Common Pitfalls

    • Looking only at unit price and not structure: savings from a lower unit price are often offset by output inflation.
    • Treating the price table as a conclusion: models iterate fast, so calibrate against the actual bill.
    • “Configure the cache and forget it”: without monitoring the hit rate, it is as if there is no cache.
    • One-size-fits-all routing: pushing everything down sacrifices quality on critical tasks, while pushing everything up lets costs spiral out of control.

    Conclusion

    AI cost governance is not a one-time procurement negotiation, but an ongoing engineering practice. Treat tokens as a measurable resource, treat caching as an asset that needs maintenance, and treat routing as an architecture decision, and the bill will turn from a “month-end surprise” into a curve you can predict day by day. On Baidu AI Cloud, by combining general capabilities such as logging, monitoring, message queues, and object storage to build this closed loop, teams can compress unit business cost into a sustainable range while preserving quality.