Why LLM Bills Spike: Token, Cache, and Routing Cost Governance
After an LLM application launches, a sudden bill increase is common even when request volume rises only modestly. This article provides a reusable cost-analysis framework covering token structure, cache hit rate, routing strategy, and retries. It explains common misdiagnoses, cost formulas and sample calculations, cache-friendly design, routing evaluation by cost per successful task, and a closed-loop process of measurement, attribution, optimization, and monitoring. All prices are hypothetical examples for calculation only; confirm actual pricing and billing rules with your provider.
Why LLM Bills Spike: Token, Cache, and Routing Cost Governance
It is not rare for an LLM application’s bill to double soon after launch. Many teams first assume that call volume has increased, but a closer investigation often shows that requests may have grown by only 20% while costs have tripled. The cause is usually not a single unit price, but the combined effect of token structure, cache hit rate, and routing strategy. Call volume is only the surface signal. What really determines the bill is how many tokens each request consumes, how many of those tokens hit cache, which capability tier the request is routed to, and how much extra consumption is caused by failed retries.
This article does not discuss the pricing of any specific vendor or model. Instead, it presents a reusable cost-analysis method. All prices in this article are hypothetical examples used only to demonstrate the calculation process; they do not represent any real product pricing. Before launch, always rely on the actual service provider’s console and billing rules. Models will iterate and unit prices will change, but the analysis framework of input, output, cache, and routing remains useful over time.
1. Four Common Misdiagnoses Behind a Bill Spike
First, looking only at request count without looking at token structure. The cost of a request is determined by input tokens, cache-hit tokens, output tokens, and possible additional metering such as images and tool calls. Multi-turn conversations repeatedly carry historical context into the prompt, so input tokens accumulate with each turn. Tool-call results, retrieved snippets, and long-document summaries can also make input grow quickly.
Second, looking only at input unit price without looking at output unit price. In many scenarios, input tokens account for a high proportion of usage, but output unit prices are usually significantly higher than input unit prices. If output length is not controlled, or if the model tends to generate lengthy explanations, output cost can become the main driver.
Third, focusing only on unit price without focusing on cache hits. The cache-hit price is usually lower than the regular input price, but caching has prerequisites: a stable prefix, unchanged content, and stable ordering. Inserting timestamps, random user IDs, or dynamically sorted results into the system prompt can invalidate the cache. If the cache hit rate drops from 60% to 10%, the bill may rise noticeably.
Fourth, routing mismatch. Simple classification, customer-service Q&A, and summarization tasks routed to a high-complexity tier will amplify costs. Complex tasks routed to a lightweight tier may fail, and retries plus manual fallback can create even higher total costs. The goal of routing is not always to choose the cheapest option, but to use appropriate capability to complete the task and control cost per successful task.
2. Token: The First-Order Cost Variable
Token cost can be expressed with a basic formula:
Cost per request =input tokens without cache hit × input unit price+ input tokens with cache hit × cache-hit unit price+ output tokens × output unit price+ additional token cost caused by retries
All unit prices are normalized and calculated per million tokens. The following sample code illustrates the calculation:
def estimate_cost(reqs, avg_input, avg_output, cache_hit_rate, price, retry_rate=0):total_input = reqs * avg_inputcache_tokens = total_input * cache_hit_ratemiss_tokens = total_input - cache_tokensinput_cost = (miss_tokens / 1_000_000) * price["input"]cache_cost = (cache_tokens / 1_000_000) * price["cache"]output_cost = (reqs * avg_output / 1_000_000) * price["output"]base_cost = input_cost + cache_cost + output_costreturn base_cost * (1 + retry_rate)
Assume a business has 1 million requests per day, with an average input of 2,000 tokens, an average output of 500 tokens, and a cache hit rate of 20%. It uses a hypothetical balanced tier: input $1.00, cache hit $0.10, and output $6.00 per million tokens. Total input is 2 billion tokens, or 2,000 million tokens. Cache hits are 400 million tokens, and misses are 1,600 million tokens. Input cost is 1,600 × 1 + 400 × 0.1 = $1,640. Output cost is 500 million × 6 = $3,000. The total is about $4,640. If the cache hit rate rises to 60%, misses fall to 800 million tokens and cache hits rise to 1,200 million tokens. Input cost becomes 800 × 1 + 1,200 × 0.1 = $920, and total cost is about $3,920, a saving of about 15%. If output tokens drop from 500 to 300, output cost falls from $3,000 to $1,800, producing an even larger saving.
This shows that token optimization should start in three places: compress input, control output, and reduce retries. On the input side, you can trim context, summarize history, deduplicate retrieved snippets, and streamline system prompts. On the output side, you can set maximum output length, require structured short answers, and truncate streaming output as needed. On the retry side, use circuit breaking, idempotency, and failure classification to avoid duplicate billing caused by timeouts or format errors.
3. Cache: Hit Rate Is the Cost Lever
The core of cache governance is not whether caching exists, but whether the cache is hit consistently. Caching usually works for identical or stable prefixes. If the prefix differs on every request, the cache hit rate will be low. Common causes of invalidation include inserting the current time, a random request ID, or a user nickname into the system prompt; placing dynamic retrieval results before a fixed prefix; unstable field ordering in templates; frequent changes to the system prompt; and reordering historical messages on every turn in multi-turn conversations.
Cache-friendly design should follow the principles of “stable prefix, dynamic suffix, fixed structure”: place long-lived content such as role definitions, rules, and format requirements at the front; place dynamic content such as user questions, retrieval results, and tool returns at the back; keep template field ordering fixed; and summarize long conversations in stages instead of concatenating unlimited history. Cache hit rate should be monitored as a first-class metric, broken down by feature, tenant, and route.
It is important to note that a lower cache-hit unit price does not necessarily mean lower total cost. Cache writes, storage, or minimum billing units may be charged separately, subject to the actual billing rules. Governance should observe hit rate, cache token share, cache-related fees, and end-to-end savings together, rather than looking only at the unit-price difference.
4. Routing: Match Capability, Not Just the Lowest Price
Routing is the strategy of assigning requests to different capability tiers or processing paths. Common approaches include rule-based routing, classifier routing, complexity scoring, confidence-based fallback, and budget caps. The following table assumes hypothetical unit prices for demonstration only:
| Tier | Input unit price | Cache-hit unit price | Output unit price | Typical use |
|---|---|---|---|---|
| High-complexity tier | $4.00 | $0.40 | $24.00 | Complex reasoning, long tasks, critical business |
| Balanced tier | $1.00 | $0.10 | $6.00 | Summarization, general generation, medium tasks |
| Lightweight tier | $0.40 | $0.04 | $2.40 | Classification, customer service, high-concurrency light inference |
For the same 1 million requests, average input of 2,000 tokens, output of 500 tokens, and 20% cache hit rate, the lightweight tier costs about: missed input 1,600 × 0.4 = $640, cache 400 × 0.04 = $16, and output 500 × 2.4 = $1,200, for a total of about $1,856. The balanced tier costs about $4,640, and the high-complexity tier is significantly higher. If simple tasks are incorrectly routed to the high-complexity tier, costs can multiply. Conversely, if complex tasks are routed to the lightweight tier and then fail and retry, the total cost may exceed that of a single correct route.
Therefore, routing evaluation should not look only at unit price per call, but at cost per successful task:
Cost per successful task =total routing cost / number of successful tasks= (cost per request × number of requests × (1 + retry rate)) / number of successful tasks
A routing strategy should include task classification, confidence thresholds, failure fallback chains, maximum retry counts, budget caps, canary experiments, and quality spot checks. Monitoring metrics should include at least the request share, success rate, retry rate, average tokens, cost per successful task, latency, and quality score of each route. A sudden shift in route distribution is often an early signal of an abnormal bill.
5. Cost Governance Loop: Measure, Attribute, Optimize, Monitor
Cost governance cannot rely on one-time parameter tuning; it needs a closed loop. The first step is measurement: record request ID, business line, feature, routing tier, input tokens, cache-hit tokens, output tokens, retry count, latency, quality score, and estimated cost in request logs. The second step is attribution: break down costs by business line, tenant, feature, route, and cache status to identify top-consuming features and abnormal growth points. The third step is optimization: prompt compression, context summarization, cache-friendly refactoring, routing tiering, output limits, retry circuit breaking, batching, and flow control. The fourth step is monitoring and alerting: set alerts for daily budget, hour-over-hour comparison, cache hit rate decline, retry rate increase, abnormal tokens per request, and sudden route distribution shifts.
On Baidu AI Cloud, logging, monitoring and alerting, and cost-analysis capabilities can be combined to build an observability loop; specific APIs and billing rules depend on the actual console. Organizationally, assign a cost owner and budget threshold for each core feature, and run optimization strategies through canary rollout before full rollout, so that cost reduction does not come at the expense of quality.
6. Implementation Checklist and Conclusion
Before launch, use real de-identified samples to estimate daily tokens, output length, cache hit rate, and routing distribution, and set budget caps. After launch, prioritize three types of issues: overlong context, cache invalidation, and misrouting of simple tasks. Review top-consuming features, cost per successful task, cache hit rate, and retry rate weekly. Set truncation and manual review for abnormally long requests; create cache-friendly templates for high-frequency repeated prefixes; and evaluate routing against both quality and cost metrics.
An LLM bill spike is usually not caused by a single reason. It is often the combined result of token expansion, cache invalidation, and routing mismatch. By breaking costs down into tokens, cache, routing, and retries, and by building a loop that can measure, attribute, and optimize, cost governance can move from after-the-fact surprise to proactive control.
