LLM Inference Cost Optimization: A Practical Guide to Model Selection, Routing, and Unit Cost Control

    This guide explains how to evaluate and reduce large language model inference costs by focusing on cost per task rather than per-token price. It covers how to read API pricing structures, why output token efficiency and prompt caching matter, how reasoning effort acts as an adjustable cost-quality lever, and how to run a reproducible evaluation, canary rollout, and monitoring process. Readers will find routing pseudocode, cost formulas, and common pitfalls to avoid.

    1. The Real Problem: Stop Choosing the Strongest Model, Start Choosing the Right Cost Structure

    In enterprise LLM applications, the bill is not determined by unit price but by cost per task. For the same business scenario, switching models can double the cost or cut latency by roughly 30%. So evaluating whether a model offers good value requires looking at four dimensions at once: capability level, pricing structure, token efficiency, and throughput/latency.

    The core conclusion repeated throughout the source material is this: a newer general-purpose LLM has been positioned around cost-effectiveness. Its input price dropped by about half, its output price fell by nearly 60%, and cached input pricing dropped by about three quarters. Compared with higher tiers in the same model family and with comparable competitors, its price is generally about half as low (some comparisons are limited to input contexts under 272K). On capability, it sits slightly below the higher-tier version in the same family, but still outperforms some lightweight open-source options on public intelligence index evaluations. With a higher reasoning effort enabled, its score can match lightweight options while cost per task is actually lower.

    What these numbers mean for developers: model tiering has become the industry norm. Selection is no longer about one model doing everything, but about routing by task difficulty.

    2. Translating the Price List into Engineering Terms

    Before estimating cost, break the billing items apart. Mainstream APIs typically charge for four things: input tokens that miss the cache, input tokens that hit the cache, output tokens, and optional batch/asynchronous discounts.

    1. Cost per request =
    2. input tokens * input unit price
    3. + output tokens * output unit price
    4. + (1 - cache hit rate) adjustment

    Three key implications follow:

    1. Output unit price is usually several times the input price, so output token efficiency affects the bill more than context length. The source material notes that output token efficiency is close to the higher-tier model, which directly lowers cost per task.
    2. When cached input pricing drops to an extremely low level (on the order of about USD 0.05 per million tokens), the repeated cost of long system prompts, long documents, and fixed few-shot examples becomes almost negligible. Architecturally, you should actively fix the prompt prefix.
    3. The larger the context window, the more you should watch out for the anti-pattern of “stuffing the context,” which raises both input cost and time to first token.

    3. Reasoning Effort Tiers: An Underrated Cost Lever

    The most valuable observation in the source material: with the xhigh reasoning mode enabled, the intelligence index matches lightweight options, and cost per task is actually lower. This shows that reasoning effort is an adjustable capability-cost knob, not a fixed property.

    Engineering recommendations:

    • Simple classification, extraction, format conversion: lowest tier, or even disable thinking.
    • Multi-step reasoning, code generation, math and structured analysis: medium to high tier.
    • Hard one-off problems: highest tier, combined with result verification.

    Pseudocode for a routing strategy:

    1. def route(task):
    2. if task.difficulty <= 1:
    3. return ModelSpec(tier="flash", effort="low")
    4. elif task.difficulty <= 3:
    5. return ModelSpec(tier="standard", effort="medium")
    6. return ModelSpec(tier="standard", effort="xhigh")

    4. Cost per Task: The Only Trustworthy Comparison Basis

    Unit price comparisons are misleading. You must convert to cost per task = average tokens consumed per task × unit price. The magnitude relationships in the source material can be abstracted as: mid-tier model 0.72, cost-effective model 0.40, lightweight model 0.26 (in USD per task). The cost-effective model is about 44% cheaper than the higher-tier one and about 54% more expensive than the lightweight one; but with higher reasoning effort, it matches the lightweight option on capability at a lower cost.

    Conclusion: lightweight options are not absolutely cheaper. Once you need retries, decomposition, or secondary verification, their “cheapness” is offset by multiple calls. When evaluating, include retry rate and average number of rounds in the formula:

    1. Real cost = cost per round × (1 + retry rate) × average rounds

    5. Implementation Process: Four Steps to a Reproducible Selection

    1. Build an evaluation set: sample 100–300 items from real business traffic, labeled with difficulty and acceptance criteria.
    2. Set a baseline: record accuracy, P95 latency, and tokens consumed per task.
    3. Run sensitivity analysis: adjust reasoning effort, caching strategy, and context trimming ratio separately, and observe the inflection points of the cost curve.
    4. Canary and monitor: use monitoring/alerting and logging services to track token usage, cache hit rate, and failure retry rate, and review weekly.

    6. Common Pitfalls

    • Looking only at unit price and ignoring output efficiency;
    • Ignoring cache hit rate and paying repeatedly for long prompts;
    • Running full traffic at the highest reasoning effort;
    • Lacking retry and fallback paths, causing costs to spiral;
    • Not validating under context constraints such as <272K, leading to over-limit errors after launch.

    7. Conclusion

    Cost-effectiveness does not mean “the cheapest.” It means the lowest cost per task while meeting the quality threshold. By putting the four variables—pricing structure, caching, reasoning effort, and token efficiency—into a unified model, and pairing it with reproducible evaluation and canary monitoring, you can achieve a stable balance between budget and quality. If an organization already uses relevant general-purpose capabilities from Baidu AI Cloud (such as container platforms, logging services, and monitoring/alerting), the load-testing and cost-accounting process described above can be implemented directly as engineering practice.