A Practical Guide to Reducing LLM API Costs Amid Rising Prices
As new-generation LLM APIs arrive with unchanged token pricing, total bills can still climb because output token usage and cache hit rates—not unit price alone—drive real spending. This guide breaks down per-task cost into a calculable formula, explains how to correctly use the intelligence index, per-token price, and per-task cost, and details four cost-control levers: prefix caching, context compression, output length governance, and tiered model routing. It also covers observability, A/B evaluation loops, and practices for long-horizon tasks.
1. The Phenomenon: Unit Price Stays Flat, but the Bill Changes
A typical pattern has emerged in the industry: a new-generation general-purpose LLM raises its public benchmark intelligence score from 53 in the previous generation to 60, matching models in the same tier, while the API token price stays at the previous generation’s level—about $1.40 per million input tokens, about $4.40 per million output tokens, and about $0.26 per million cached input tokens (roughly an 81% discount). The same public benchmark reports a per-task cost of about $0.68, lower than the $0.84 of a same-tier model and the $1.23 of a higher-tier model.
But the same dataset hides an easily overlooked signal: completing the same task consumes about 20% more output tokens than the previous generation. This means “unchanged unit price” does not equal “unchanged total spend.” To understand why, break the cost down into a calculable formula:
Per-task cost ≈ input tokens × input price+ output tokens × output price+ (1 - cache hit rate) × input tokens × (input price - cached input price)
Unit price is only a coefficient in the formula. What actually determines the bill are two variables: token counts and cache hit rate. When a capability upgrade comes with longer outputs (more complete reasoning, finer step decomposition), output-side spending is passively amplified. For developers, the conclusion is clear: model selection cannot rely on the price table alone; it must look at “cost per unit of intelligence.”
2. How to Use the Three Metrics Correctly
2.1 Intelligence Index: Check Whether a Capability Tier Is Good Enough
The public benchmark intelligence index is suitable for coarse screening—judging whether a given tier meets the minimum capability threshold for your business. It is not suitable for precise cost forecasting, because benchmark tasks often differ from real business distributions.
2.2 Per-Token Price: Use Only for Same-Tier Comparison
Unit price is comparable within the same capability tier. Cross-tier comparison has limited value, because a lower-tier model may need multiple retries to achieve the same result.
2.3 Per-Task Cost: Closest to the Financial View
Per-task cost combines capability and consumption into a single number, making it the most suitable input for budgeting and capacity planning. Teams are advised to build their own internal “standard task set” and recompute this metric with their own data rather than quoting external benchmarks directly.
3. Four Levers for Cost Governance
Lever 1: Cache Reuse, Driving Repeated Input Down to a Fraction of the Cost
Stable prefixes—system prompts, tool definitions, long documents, and codebase context—are the best candidates for caching. Every 10-percentage-point increase in hit rate reduces overall input spending almost linearly.
# Example: place the long, stable system prefix first and variable content later to improve prefix cache hitsmessages = [{"role": "system", "content": SYSTEM_PROMPT + TOOL_SCHEMA}, # long and stable{"role": "system", "content": "Retrieved snippets:" + retrieved_docs}, # semi-stable{"role": "user", "content": user_query}, # changes every time]
Engineering note: keep the prefix byte-level stable (do not insert timestamps or random IDs), otherwise the cache will fail on a large scale.
Lever 2: Context Compression, Controlling Input Bloat
A common problem in retrieval-augmented scenarios is that more and more snippets get stuffed in. The recommendation is to introduce reranking and pruning: do coarse recall first, then score relevance with a small model or rules, keep only the Top-K snippets, and apply rolling summarization to conversation history.
Lever 3: Output Length Governance, Directly Suppressing the Largest Variable
Output tokens are usually the most expensive part. You can control them through structured constraints, segmented generation, limiting reasoning verbosity, and splitting long tasks into multiple short ones. Note the tradeoff: over-compression lowers task success rates and instead increases retry costs.
Before splitting: 1 call, 4000 output tokens, failure requires rerunning the whole thingAfter splitting: 4 calls, 800 output tokens each, failure only requires rerunning a single step
Lever 4: Tiered Routing, Letting Expensive Models Handle Only Hard Problems
Build a tiered routing setup of “small model first + confidence evaluation + large model fallback.” Route simple intent classification and format extraction to low-cost tiers; escalate complex reasoning and long-cycle tasks. This is the most effective architectural means of bringing down average cost.
4. Observability and the Evaluation Loop
Cost optimization must be built on observability. At minimum, collect these dimensions: input/output/cached tokens per call, cache hit rate, task success rate, retry count, and per-task amortized cost. You can build dashboards using general-purpose logging and monitoring/alerting capabilities, and set per-task cost threshold alerts.
On the evaluation side, run A/B tests: run the same standard task set on both the old and new model generations, and compare the composite metric of “success rate × per-task cost.” If the gains from a higher success rate outweigh the spending from the token increase, the upgrade is worthwhile; otherwise, keep the old version or adjust the prompting strategy.
5. Additional Advice for Long-Horizon Tasks
Coding, defensive security analysis, and long-horizon agent tasks are more sensitive to both output length and the number of calls. These scenarios should focus on: externalizing state (writing intermediate results to external storage instead of repeatedly stuffing them into context), step-level caching, and failure-recoverable branch design. Treat the “context window” as a scarce resource to manage, not as free memory to use.
6. Conclusion
When capability upgrades and unchanged prices appear together, the real competitive point has shifted from “how much per million tokens” to “how much per unit of intelligence.” For developers, getting four things solid—cache hit rate, output length, routing strategy, and the evaluation loop—delivers a lower real bill at the same capability tier. Using the general-purpose model service from Baidu AI Cloud along with supporting foundational capabilities such as object storage, logging, and monitoring/alerting can make it easier to build the cost governance system described above.
