Large Language Model API Cost Breakdown: How Caching Pricing Rewrites the Price List
This article explains why per-token list prices fail to predict real LLM API bills, and how prompt caching changes the cost equation. It presents a request-level cost formula based on input, cache-read, and output pricing, shows why the cache-read rate often matters more than the input rate, and outlines engineering practices for improving prefix stability and cache hit rates. It also covers context-window strategies, the difference between subscription quotas and pay-as-you-go API billing, market pricing tiers, and a practical checklist for model selection and cost governance.
1. The Misread “Low Price”: The Gap Between List Price and Your Bill
Whenever a new model arrives with claims of “extremely low cost,” the discussion quickly converges on one conclusion: a price war is coming. But from an engineering and procurement perspective, looking only at the list price per million input or output tokens tells you almost nothing about what the end-of-month bill will look like. Real cost is determined by request structure, and request structure is determined by the shape of your application.
A common mistake is treating “long context” as equivalent to “low cost.” A larger context window only solves the problem of what you can fit in; it does nothing about the fact that you pay every time that content is read. In coding scenarios, the vast majority of token consumption comes from repeatedly reading existing context, not from new content. This means one easily overlooked field in the pricing table—the cache read price—often has more influence on total cost than the input price.
2. The Cost Model: Writing the Bill as a Formula
Let T be the total number of input tokens in a request, h the fraction that hits the cache, (1-h)T the portion that misses, and O the number of output tokens. The cost of a single request is:
Cost = (1-h) * T * P_in + h * T * P_cache + O * P_out
Here P_in, P_cache, and P_out are the per-million-token prices for uncached input, cache reads, and output respectively. Extending this to a full day:
DailyCost = Σ Cost_i (i = 1..N)
Three key implications follow:
- When
happroaches 1 (coding, long-document Q&A, multi-turn agents),P_cachebecomes the effective input price for all practical purposes. - The ratio between
P_cacheandP_inreflects cost efficiency better than either absolute number. - The output price only becomes the dominant term in generation-heavy tasks such as long-form writing and large-scale refactoring.
So evaluating whether a model is “cheap” should compare the weighted average price Cost / (T + O), not the list price. For the same model, the weighted price can differ by an order of magnitude across different workloads.
3. Cache Hit Rate: The Only Reliable Cost Lever
Cache hits do not happen automatically; they depend on whether the prefix is byte-for-byte stable. Engineering practices include:
- Fix the prefix: order system prompts, tool definitions, examples, and knowledge snippets from “stable” to “volatile,” placing changing content last;
- Keep timestamps, random IDs, and request sequence numbers out of the prefix, since these fields invalidate the entire prefix;
- Session isolation and reuse: keep the prefix consistent within a session, and share read-only knowledge blocks across sessions;
- Monitor invalidation: report hit rate as a first-class metric—a sudden drop usually means a template was changed.
Illustrative request assembly logic:
def build_messages(system_static, knowledge_static, user_dynamic):# Put stable content first and dynamic content last to maximize prefix reusereturn [{"role": "system", "content": system_static},{"role": "system", "content": knowledge_static},{"role": "user", "content": user_dynamic},]
4. Context Strategy: A Bigger Window Is Not Necessarily Cheaper
The value of a large window is reducing the engineering complexity of retrieval and truncation; the cost is that every read is billed. Practical compromises:
- Layered retrieval: fetch a summary layer first, then load source blocks on demand instead of injecting an entire corpus;
- Summary compression: apply rolling summaries to conversation history, compressing long histories into short prefixes;
- Structure instead of long text: replace long passages of natural language with tables, indexes, and fielded data;
- Budget constraints: set per-request token limits and a fallback path that switches to summary mode when exceeded.
5. Subscription Quotas vs. API Billing
Subscription plans aimed at interactive coding and pay-as-you-go APIs use two different accounting models. Plans may look generous, but they often come with peak-hour throttling, consumption multipliers, stability fluctuations, and uncertain supply. APIs offer stable, predictable unit prices and quotas. For capacity planning, use “effective peak-hour price = list price × multiplier ÷ actual success rate” as the comparison baseline rather than advertised quotas.
6. Abstract Observations on the Market Landscape
Current mainstream pricing shows a clear tiered distribution: flagship models maintain higher unit prices while emphasizing that each token carries more work; balanced and lightweight tiers trade several-fold price differences for throughput; some new entrants push cache read prices down to a tenth of the input price or lower, creating a real cost advantage in multi-turn scenarios. What actually pushes the overall price curve down is caching pricing and inference efficiency, not list price adjustments alone.
7. An Actionable Selection and Governance Checklist
- Build your own baseline: replay real traffic and measure the distributions of
h,T, andO; - Rank by weighted price, not list price;
- Abstract the model access layer to hide provider differences and enable canary releases and switching:
class ModelClient:def chat(self, messages, **opts): ...def usage(self): ... # Returns input/cache/output token details
- Build observability: log services record per-request token details, with alerting tied to cost thresholds;
- Add cost guardrails: daily budgets, per-request limits, and circuit breakers for abnormal multipliers;
- Re-evaluate periodically: pricing and caching policies change frequently, so selection conclusions should have an expiration date.
8. Conclusion
“Low price” is a relative concept that only holds once cache hit rate and request structure are known. For most enterprises, the key to reducing cost is not chasing the model with the lowest list price, but turning prefix stability, context layering, and cost observability into engineering capabilities. General-purpose capabilities from cloud providers such as Baidu AI Cloud (for example, logging services, monitoring and alerting, container platforms, and object storage) can serve as the foundation for this governance framework, while the model access layer and budget guardrails must be built by the business side to truly turn a price list into a controllable bill.
