LLM Inference Cost Optimization Under Rising API Prices
This article examines the three-tier billing structure of large language model APIs and explains why output tokens are the most expensive component. It then presents practical cost-optimization approaches: maximizing prefix cache hit rates, enforcing strict output-length governance, routing tasks across model tiers, and building end-to-end cost observability. Readers will learn how to keep total cost of ownership under control even when unit API prices rise sharply.
LLM Inference Cost Optimization Under Rising API Prices
A major LLM vendor recently announced API pricing for its new flagship model, sparking extensive discussion in developer communities. The output-side price reached 100 CNY per million tokens; input-side pricing was 20 CNY per million tokens on a cache miss and as low as 1–2 CNY per million tokens on a cache hit. Compared with the previous generation, output-side pricing is nearly four times higher, and input-side pricing is about three times higher. For teams that rely heavily on LLM APIs, this is not just a change in the bill—it is a full stress test for architecture and engineering practices. This article does not evaluate any specific product. Instead, it uses this pricing shift as a starting point to break down LLM API billing structures and present a systematic approach to cost optimization.
1. Understand the Bill First: The Three-Tier Structure of LLM API Pricing
Before optimizing, it is important to understand where the money goes. Mainstream API billing can usually be divided into three tiers:
- Input, cache miss: Tokens newly entering the model context on each request must go through full prefill computation. This is the most expensive part of input-side cost.
- Input, cache hit: Tokens that match a historical request prefix can reuse the already-computed KV Cache, so computational overhead drops significantly. As a result, the price is usually only a fraction of the cache-miss tier.
- Output: Tokens are generated autoregressively one by one, cannot be parallelized, and require access to the full model weights and KV Cache at every step. This is the highest unit-cost tier of all.
The new-generation pricing reveals a clear trend: the price gaps among the three tiers have widened significantly. In the previous generation, cache-miss input was about 6 times the price of cache-hit input; in the new generation, it is around 10 times. The ratio of output price to cache-hit price has expanded from about 25 times to about 50 times. In other words, the pricing model strongly “rewards” cache reuse while “penalizing” verbose output. This is not random price inflation; it is a price signal guiding users to optimize how they call the API.
2. Why Output Is the Most Expensive: Pricing Logic Through the Lens of Inference Mechanics
Price differences reflect real differences in compute cost. Understanding this helps build the right optimization intuition.
- The prefill stage is parallelizable. Input tokens can be sent into the model at once for parallel computation, leading to high GPU utilization and relatively controllable per-token cost.
- The decode stage is serial. Each generated token requires a full forward pass, and the process is limited by memory bandwidth. It is a typical memory-bound task with low GPU compute utilization. This is the fundamental reason output tokens are an order of magnitude more expensive than input tokens.
- KV Cache reuse changes input cost. When a request prefix hits the cache, those tokens do not need attention recomputation, so cost drops sharply. That is why the cache-hit tier is priced so low.
Therefore, the 50x “output / cache-hit” price gap is essentially the vendor transparently passing the real hardware cost structure into pricing. For developers, it is effectively an official optimization guide: generate less and reuse more.
3. Cost Optimization Practice 1: Maximize Prefix Cache Hit Rate
Now that the price gap between cache hits and misses has reached 10x, improving cache hit rate is the highest-leverage optimization. The core principle is: put stable, unchanging content at the very beginning of the prompt, and place dynamic content at the end.
Consider an intelligent coding assistant scenario. A common anti-pattern is:
[User's current question] + [Conversation history] + [System prompt and tool definitions]
With this arrangement, the user question changes every time and sits at the front, so the entire prefix cannot be reused and the hit rate is close to zero. The optimized structure should be:
[System prompt and tool definitions (stable, several KB)]+ [Project context / retrieved code snippets (relatively stable within a session)]+ [Conversation history (grows incrementally, prefix reusable)]+ [User's current question (changes each time, placed last)]
This way, everything except the final short segment can hit the cache. In practice, teams should also:
- Avoid inserting timestamps, random IDs, or other volatile fields into the prefix, since they break the cache from the insertion point onward.
- Update context in batches and centrally, rather than inserting new content into the middle on every turn.
- Use logging and monitoring alerting capabilities to establish observability metrics for cache hit rate, and alert promptly when the hit rate falls below a threshold.
For an application with meaningful daily call volume, raising the hit rate from 20% to 80% could reduce input-side cost by more than 70%. Under the new pricing with a 10x gap between cache hits and misses, the benefit is especially significant.
4. Cost Optimization Practice 2: Enforce Rigid Governance of Output Length
Output is the most expensive tier, and it is also the easiest part to let spiral out of control. Output-token waste usually comes from three sources:
- Redundant explanatory text. Models tend to produce polite but verbose answers. System prompts can explicitly constrain output format—for example, “output code directly without explanation”—which can immediately compress output volume.
- Structured output instead of natural language. In engineering pipelines, having the model output structured results such as JSON and letting the program render them into human-readable text often saves a large number of tokens while reducing parsing errors.
- Lack of maximum-length control. A reasonable maximum output length should be set in call parameters, and abnormal long outputs should be monitored. A runaway loop generation could burn a day’s budget within minutes.
A rough sense of scale: at 100 CNY per million output tokens, 1,000 extra useless tokens per request across 100,000 requests means 100 million extra tokens—pure waste at the stated output price. Output governance is a classic “small change, large return” measure.
5. Cost Optimization Practice 3: Model Routing and Task Tiering
After flagship-model price increases, the strategy of “send every request to the strongest model” becomes increasingly uneconomical. A reasonable approach is to build a model routing layer that routes by task difficulty:
- Simple tasks—format conversion, intent classification, short-text rewriting, and the deterministic parts of code completion—can be routed to lightweight models or previous-generation cost-effective models, potentially at a fraction of flagship cost.
- Complex tasks—multi-step reasoning, cross-file code refactoring, and architecture-level design—should be routed to flagship models.
- A classifier can use a very small model or rule engine for pre-judgment; the routing cost itself must be far lower than the savings from diversion.
In addition, non-real-time tasks such as batch code review, document generation, and offline evaluation can be accumulated into batch jobs. Queues can smooth peaks and fill valleys, and some platforms offer discounts for offline batch calls. Building asynchronous processing pipelines with message queues and container platforms is a mature engineering pattern.
6. Cost Optimization Practice 4: Build an End-to-End Cost Observability System
In an era of price changes, “invisible cost” is the biggest risk. Teams should establish the following mechanisms:
- Meter with tags by business line and functional module, making clear which feature each token consumption is attributed to and avoiding “the total bill is high, but we do not know where it went.”
- Core metrics dashboard: average input tokens per request, output tokens, cache hit rate, cost per task, and monthly trends. These can be built on general logging and monitoring alerting capabilities.
- Budget circuit breaker: set daily or weekly budget caps for each module. When triggered, automatically degrade to cost-effective models or queue processing to prevent abnormal traffic from causing bill overruns.
- Preparedness for pricing changes: abstract model calls into an adapter layer so the underlying model can be replaced. When a model generation’s price changes significantly, teams can switch quickly or use mixed scheduling instead of being locked in by a single vendor’s pricing strategy.
7. Conclusion: Rising Prices Are a Challenge and a Chance to Upgrade Engineering Capability
Returning to the initial question: output-side price nearly four times higher and input-side price about three times higher will indeed create real cost pressure for heavy users. But from another perspective, the change in pricing structure—a 10x gap between cache hits and misses, and a 50x gap between output and cache hits—is effectively a best-practices document written in prices.
The response can be summarized in four phrases: stable prefix, cache first; concise output, controlled length; task tiering, routed distribution; metering by owner, budget circuit breakers. With these in place, even if unit prices multiply, total cost of ownership can remain controllable—and may even be lower than rough usage of older models.
Competition in large models will eventually move from a “capability race” to a “cost-efficiency race.” For developers, those who establish fine-grained inference cost governance earlier will be better positioned to turn technological dividends into business value in an era of rapid model iteration and frequent pricing adjustments.
