LLM API Cost Engineering: A Practical Guide to Routing, Caching, and Evaluation After the Price Cuts
A practical guide to controlling LLM API costs after recent price reductions. It explains why a lower per-token price does not translate into a proportional drop in your bill, breaks total cost into unit price, output length, cache hit ratio, and retries, and shows how to route between flagship and lightweight models based on risk. It also covers how to read vendor cost comparisons, build a small internal evaluation set, and apply structured generation to office document automation, plus a migration and validation checklist.
1. Background: From Benchmark Rankings to Counting Costs
A leading model provider recently released a new flagship model alongside a lightweight model, cut the per-token prices for input, output, and cache hits, and stated that output length dropped significantly under the same internal evaluations. A day earlier, two domestic cloud providers had made their own price adjustments, a coincidence in timing.
For developers, the ranking position is not what matters. Three things do: how the price structure changed, how token consumption per task changed, and how to route across model tiers now that capability is layered. Together these determine the final bill, not any single metric.
This article does not evaluate or recommend any specific product. All prices and evaluation figures come from public descriptions and serve only as a starting point for discussing methodology. For real deployments, rely on measurements from your own business samples.
2. Cost Model: Unit Price Is Only One Multiplier
The cost of a single call can be approximated as:
Cost = (In_tokens × P_in) + (Out_tokens × P_out)Effective_Cost = Cost × (1 - cache_hit_ratio × discount)
A 20% drop in unit price does not mean a 20% drop in the bill. If the new model produces 20% shorter output on the same task, the two effects multiply and the actual reduction exceeds the price cut. Conversely, if the new model is more verbose, the savings from the price cut get eaten by token inflation.
Teams should therefore define their own metrics:
- Task-level cost: total tokens and total cost to complete one business task, not one call;
- Output length distribution: P50/P90 output tokens, not the average;
- Cache hit ratio: stable system prompts, long documents, and code repository context can all raise it substantially;
- Retry and failure cost: second calls caused by timeouts or format errors are often overlooked.
3. Capability Tiers and Routing: Don’t Send Simple Tasks to the Flagship
The common approach across new product lines is a two-tier “flagship + lightweight” structure. The gap between the two is small on code and complex reasoning evaluations, while on everyday understanding, summarization, and rewriting tasks the lightweight model may even outperform the previous flagship generation, at a fraction to one fifth of the cost.
In engineering terms, this maps to tiered routing:
def route(task):if task.risk == "high" or task.need_long_context:return "flagship"if task.type in {"summarize", "rewrite", "classify", "extract"}:return "light"return "light" # default to lightweight, escalate on failure
The default value is what matters. Most production traffic consists of low-risk, verifiable tasks, so setting the default tier to lightweight and treating the flagship as an escalation path for exceptions is usually cheaper and more stable than the reverse. Escalation should be driven by observable signals (confidence, format validation failures, failure rate in human spot checks), not an arbitrary ratio.
4. Evaluation Methodology: Check the Denominator Before Believing the Multiple
Public comparisons often use phrasing like “at a fraction of the cost.” When reading them, verify three points:
- Which generation and tier is the baseline, and whether some test items were “excluded”;
- Whether the evaluation set covers your real task distribution;
- Whether retries, tool calls, and post-processing overhead are counted.
Any comparison that excludes samples should be discounted. A more reliable approach is to build a small evaluation set of 100–300 business samples, fix the scoring script, and run it on every model or prompt change to build a comparable historical curve.
5. An Underrated Scenario: Office Document Automation
This flagship generation generally strengthens structured generation for slides, spreadsheets, and documents: aligning layout, color, and font size to a template, and even replicating a style from a screenshot. For most organizations, the business coverage of this capability is far broader than a coding score, because far more people write documents and prepare presentations every day than write code.
Implementation points:
- Template first: express the enterprise template as a structured description (slide order, placeholders, font size hierarchy, primary color palette);
- Structured output: have the model produce an intermediate JSON first, then render the document with deterministic code, rather than generating a binary format directly;
- Validation loop: use rules to check page count, fonts, overflow, and color compliance, and retry automatically on failure;
- Permissions and compliance: redact document content before it enters the model, and keep sensitive data within your own boundary.
An illustrative intermediate structure:
{"slides": [{"layout": "title", "title": "...", "subtitle": "..."},{"layout": "bullets", "title": "...", "points": ["...", "..."]}],"theme": {"primary": "#1A73E8", "font_scale": [32, 20, 14]}}
On the cloud, you can use object storage for templates and artifacts, a message queue to smooth traffic spikes, and a container platform to host rendering and validation services, with logging and monitoring with alerting for full-chain observability. Model capability can be integrated through a unified model service gateway to make canary releases and switching easier. Baidu AI Cloud offers mature general-purpose product categories for this kind of “model + storage + queue + monitoring” combination.
6. Migration and Validation Checklist
- Run the old and new tiers on your small business evaluation set, and record task-level cost and quality differences;
- Enable caching for prompts and long context, and measure the change in hit ratio;
- Change the routing default to the lightweight tier, roll out 5% → 50% → 100%, and watch the failure rate;
- Build a dashboard for output length and cost, and set anomaly alerts;
- Keep the ability to roll back to the previous model tier with one action.
7. Conclusion
The price cut is the outcome; cost engineering is the method. Break cost into four variables (unit price, output length, cache hit ratio, and retries), split models into flagship and lightweight tiers and route by risk, verify the evaluation methodology, then prioritize high-frequency scenarios like document automation. The drop in your bill will usually exceed the advertised discount itself. Whether to switch models is ultimately decided by running your own tasks a few more rounds.
