Cost Engineering for LLM APIs: Why the Bill Can Rise Even When Token Prices Stay Flat
This article explains why a task's real cost can increase even when a new model's API price per million tokens stays unchanged. It breaks the bill into three coupled drivers—effective price per unit of intelligence, token efficiency, and cache structure—and presents a per-task cost model showing how input caching, output constraints, and model routing can be optimized. It covers output token governance, cache and batch processing practices, tiered routing for models with similar benchmark scores, the distinct cost structure of long-running agent tasks, and a six-metric checklist for model selection. The takeaway is that competition shifts from raw capability to cost per unit of intelligence.
1. The Phenomenon: Flat Unit Price, Higher Bill
A common pattern is emerging in the industry: a new generation of large models shows clearly higher benchmark scores, while the official API price per million tokens stays the same as the previous generation. On the surface this looks like pure upside, but it hides an engineering problem that is easy to miss—price per token is not the same as cost per task.
Abstracting this pattern yields three independent yet coupled cost drivers:
- Effective price of intelligence: the price paid to complete a unit of work at a given quality level. It is determined jointly by the token price and the number of tokens consumed to complete the task.
- Token efficiency: output redundancy at the same task quality. Newer models tend to produce longer reasoning chains and more self-checking, so output token counts commonly rise.
- Cache structure: the share of reusable prefixes. Cache hits typically deliver a discount close to 80%, making this the biggest lever for long-context and fixed system prompt scenarios.
The situation described in the original text sits exactly at the intersection of the first and second drivers: the unit price has not risen, benchmark scores are up by about 7 points within the same tier, but output tokens per task have increased by about 20%. That is how “unchanged unit price” and “higher actual spend” can both be true at once. For developers, this means model selection cannot rely on the price list alone; it requires a cost accounting system built around the task.
2. Cost Model: Breaking the Bill into Optimizable Variables
A sufficiently engineering-oriented approximation of per-task cost:
Cost_task ≈ (In + CachedIn × (1 - d) + Out) × Pricewhere:In = non-cached input tokensCachedIn = input tokens that hit the cached = cache discount rate (commonly 0.7~0.85 in the industry)Out = output tokens (including reasoning/thinking tokens)Price = unit price for the corresponding tier
This formula points to three actionable things:
- Caching on the input side: stable prefixes such as system prompts, tool definitions, and long documents should be placed at the very front of the request, byte-for-byte identical, so they hit the cache reliably.
- Constraints on the output side: output tokens are the only variable fully determined by business design, and compressing them often pays off more than negotiating price.
- Routing across the whole: not every request needs the strongest model; tiered routing can send most traffic to cheaper tiers.
An illustrative cache-friendly request structure:
{"messages": [{ "role": "system", "content": "<stable long system prompt and tool definitions>" },{ "role": "user", "content": "<the short question that changes this time>" }]}
The counter-example is prepending timestamps, random IDs, or retrieval results to the beginning of the system prompt. That makes the prefix different every time and renders the cache effectively useless.
3. Output Token Governance: What a 20% Output Increase Means
Rising output tokens usually come from longer reasoning, more verbose explanations, and repeated confirmation. Governance measures, ordered by cost-effectiveness:
- Explicit length budgets: state a target word or item count in the prompt, and require the conclusion first, then the supporting detail.
- Structured output: agree on fixed fields and enum values to reduce free text, and validate with server-side structured output capabilities.
- Turn off unnecessary explanation: classification, extraction, and rewriting tasks need only the result, not a display of the reasoning.
- Streaming and early stopping: streaming responses let the frontend terminate generation once conditions are met, avoiding payment for a redundant tail.
- Offline evaluation regression: treat output token count as a first-class metric in regression, so cost does not quietly climb after a model upgrade.
# Prompt template example (pseudocode)Constraint: output JSON only; fixed fields; total length under 120 characters; do not explain the process.
4. Caching and Batching: Actually Capturing the Discount
The cache discount only holds under “high hit rate, long reuse.” Engineering concerns include:
- Prefix stability: put volatile content later, and stable content first in a fixed order.
- Lifecycle management: caches usually have a time-to-live window, and hit rates drop under bursty traffic, so load testing is needed to verify.
- Batching and async: offline tasks should go through an asynchronous batch channel, which is usually cheaper than real-time calls.
- Observability: make cached input tokens, output tokens, and per-task cost into monitoring and alerting metrics, rather than reading the bill at month end.
5. Model Routing: A Tiered Strategy When Scores Are Similar but Prices Differ
When two models have close benchmark scores, the difference shows up mainly in per-task cost. A workable routing design:
if the task is simple classification/extraction:use the lightweight tierelif the task is routine coding and Q&A:use the main tierelse: # long-running agents, complex refactoring, defensive security analysisuse the strongest tier + a stricter output budget
The point of routing is not saving money but spending the high-intelligence budget on the requests that truly need it. Combined with retry and escalation on failure, it can significantly dilute average cost without lowering quality.
6. The Special Accounting of Long-Running Agent Tasks
Agent scenarios have a completely different cost structure from single-turn Q&A: multi-turn tool calls repeatedly carry context, and input tokens grow roughly linearly with the number of steps, or even faster. Recommendations:
- Compress and summarize context, keeping only information necessary for decisions;
- Truncate and structure tool return results, so entire logs do not enter the context;
- Set step and time limits, degrading or handing off to a human when exceeded;
- Enable caching for reusable prefixes, where the payoff is most visible in long tasks.
7. Selection Checklist and Conclusion
When evaluating a new generation of models, fix six metrics: task quality score on the same task, per-task cost, mean output tokens, cache hit rate, failure retry rate, and end-to-end latency. Deciding on the price list or a single benchmark score alone makes cost inversion likely under real traffic.
The conclusion is clear: when models of comparable intelligence begin competing within the same tier, the deciding factor shifts from “capability” to “cost per unit of intelligence.” An unchanged unit price is only the starting point; the real engineering dividend comes from the coordinated optimization of output budgets, cache structure, and tiered routing. On platforms such as Baidu AI Cloud, these capabilities can typically be composed from general-purpose building blocks—model serving, caching, asynchronous batch processing, and monitoring and alerting—without depending on any single vendor’s proprietary features.
