Cost Governance for LLM APIs: How to Control Token Costs After a Price Increase
This article breaks down why a large language model API price increase affects the entire application stack, and how engineering teams can respond. It explains the three billing dimensions of modern LLM APIs—input tokens, output tokens, and cache reads and writes—and the practical conclusions that follow from them. It then covers four layers of cost governance: context engineering, caching strategy, model tier routing, and observability, along with architecture-level cost-saving patterns such as batching, semantic result reuse, streaming output, hard token limits, and fallback plans. Common pitfalls and a four-step rollout path are included to help readers balance output quality and cost sustainably.
1. Why a Single Price Change Affects the Whole Stack
A cloud provider recently announced a price increase for its next-generation large language model API. Billing is per million tokens: input is priced at $10 and output at $50, while cache reads and writes are billed separately. The previous generation was priced at $5 for input and $30 for output. That means input doubled, output rose by roughly 67%, and caching is no longer a free add-on but an independently metered item.
For a single call, this is just a unit price change. For a production system handling a million requests per day, it rewrites the entire cost structure. What makes it more pressing is the timing: the increase lands at a stage where contexts keep getting longer and agents take more steps, so token consumption is already growing fast. Unit price and usage volume compound each other.
2. Build the Right Mental Model for Billing
Much cost overruns trace back to treating an API as “charged per call.” Mainstream billing actually has three dimensions:
- Input tokens: system prompts, conversation history, retrieved snippets, and tool return values all count.
- Output tokens: generated content, usually priced significantly higher than input.
- Cache reads and writes: context that hits the cache is read at a lower price, while writing to the cache is a one-time extra cost.
Three engineering conclusions follow:
- Output is more expensive than input, so controlling generation length is often more effective than compressing prompts.
- Caching only pays off when reuse count × savings exceeds the write cost; writing a one-off long prefix to the cache is a net loss.
- In multi-turn conversations, history accumulates linearly, so the marginal cost of a long session keeps rising.
Illustrative pseudocode (to convey billing intuition, not any vendor’s API):
def estimate_cost(in_tokens, out_tokens, cache_hits, cache_writes):# Unit prices are illustrative; refer to the provider's billing rules for actual valuescost = in_tokens * P_IN + out_tokens * P_OUTcost += cache_hits * P_CACHE_READ + cache_writes * P_CACHE_WRITEreturn cost
3. Four Layers of Cost Governance
3.1 Context Engineering: Spend Tokens on Useful Information
- Remove redundancy from system prompts and avoid prompt bloat that keeps growing.
- During retrieval augmentation, rerank and truncate so only highly relevant snippets remain.
- Segment and summarize long documents before they enter the reasoning context.
- Use a sliding window plus summary compression for conversation history instead of concatenating everything.
3.2 Caching Strategy: Make Stable Prefixes Reusable
Put the parts that do not change across requests—tool definitions, domain descriptions, long documents—at the very front of the prompt to form a stable prefix and improve cache hit rates. Place volatile content such as timestamps and user identifiers at the end. Use monitoring to track hit rates and write amortization so you do not pay for low-frequency prefixes.
3.3 Model Tier Routing: Not Every Request Deserves the Flagship Model
Intent classification → simple Q&A / formatting extraction → small model→ routine reasoning and writing → mid-tier model→ complex planning / long-chain reasoning → flagship model
Combined with confidence thresholds and retry-on-failure that escalates to a higher tier, routing can push average cost down to a fraction of the original in most scenarios while preserving quality on critical paths.
3.4 Observability: No Measurement, No Optimization
Metrics that must be collected include input and output tokens per request, cache hits and write volume, cost per call and per user, and the amplification factor from failed retries. Set budget thresholds and alerts, and apply per-tenant quotas to prevent runaway loops from inflating the bill.
4. Architecture-Level Cost Reduction
- Batching and asynchrony: route offline jobs through async queues to smooth out peaks and troughs.
- Result reuse: apply semantic-level caching to frequent identical questions and return on a hit.
- Streaming output: return content as it is generated to reduce duplicate consumption caused by timeout retries.
- Timeouts and maximum token limits: add hard constraints to every call to prevent runaway generation.
- Fallback plans: automatically switch to a lower-tier model or rule-based fallback when the primary model is unavailable or over budget.
5. Common Pitfalls
- Compressing only the input while letting output grow, so the bill rises instead of falling.
- Scattered cache writes and unstable prefixes, keeping hit rates chronically low.
- Sending everything to the flagship model and using “quality first” to mask the absence of routing design.
- Looking only at the monthly total instead of the per-request cost distribution, which makes hotspots impossible to locate.
- Treating a price increase as simply “switch to a cheaper model” and ignoring the gains from restructuring prompts and the request path.
6. Rollout Path and Conclusion
A four-step approach is recommended: first, add usage and cost instrumentation to establish a baseline; then slim down prompts and context, usually the fastest win; next, roll out caching and semantic reuse; finally, introduce tiered routing and budget alerts to close the loop.
The consuming party cannot decide on price changes, but how tokens are consumed is fully controllable. Get the four things solid—the billing model, context engineering, caching and routing, and monitoring with alerts—and you can achieve a sustainable balance between quality and cost. If you want to reduce the burden of self-building and operating this system, you can also rely on general cloud capabilities from providers such as Baidu AI Cloud (for example, object storage, message queues, container platforms, log services, and monitoring and alerting) to host this cost governance setup.
