LLM Cost Optimization and Model Selection: A Practical Guide to Tiered Routing, Prompt Caching, and Evaluation

    This guide explains how engineering teams evaluate large language models by capability per unit cost instead of benchmark scores alone. It breaks down capability dimensions such as context and output length, multimodal and tool-calling reliability, and correction cost; presents a per-request cost model in which prompt caching is the largest lever; and recommends a barbell strategy where mid-tier models handle most general traffic, lite models absorb high-frequency short tasks, and flagship models are reserved for complex reasoning. It also covers a three-layer evaluation system, inference gateway requirements, and common cost mistakes.

    1. Why Cost-Effectiveness Is the First Constraint in LLM Engineering

    Once enterprise applications move into large-scale production, the central question in model selection shifts from “can it do the job” to “can we afford to run it.” In the early prototype stage, teams usually optimize only for the quality ceiling and pick the most capable tier. But when call volume grows from a thousand requests a day to tens of millions, differences in unit price turn into cost gaps of several orders of magnitude. Engineering teams therefore need a repeatable method for evaluating model capability and unit cost on the same chart.

    On the supply side, mainstream model vendors generally offer a three-tier structure: flagship, mid-tier, and lite. The flagship tier pursues the capability ceiling, the mid-tier balances quality against cost, and the lite tier serves high-frequency tasks with very high throughput and very low unit price. This tiering is not simple parameter pruning. It applies the same training and alignment methods to base models of different sizes, which is how the lower tiers retain most general-purpose capability.

    2. Breaking Down Capability: Benchmarks Are Not Enough

    2.1 Context and Output Length

    Long context (on the order of a million tokens) and a large single-response output limit determine whether a model can handle whole-repository code comprehension, long document review, or aggregation across many support tickets. When evaluating, separate the advertised limit from effective utilization. The latter is affected by attention decay and positional bias, and should be verified with needle-in-a-haystack retrieval tests and consistency tests on medium-to-long document summarization.

    2.2 Multimodality and Tool Calling

    Whether a model can read images, reliably emit structured function calls, and use web retrieval or operate local files and graphical interfaces determines whether it can be embedded in an automated pipeline. The key metrics for tool calling are schema compliance rate for arguments and the cost of retrying after failures, not how a single demo looks.

    2.3 Factuality and Correction Cost

    A frequently overlooked metric is correction cost: how many prompting turns a user needs to get the model back on track after it errs. An internal factuality evaluation built from real user correction data reflects production experience more closely than public leaderboards. In practice, the error rate of a new-generation mid-tier model can be roughly half that of the previous generation, approaching flagship-level reliability.

    3. Modeling the Cost Structure

    Model cost cannot be judged by unit price alone. Use a model like this:

    1. cost per request =
    2. input tokens × input price
    3. + output tokens × output price
    4. + (input tokens - cached tokens) × cache discount difference
    5. + retry count × cost per request
    6. + extra token overhead from orchestration and retrieval chains

    Prompt caching is the highest-leverage item for cost reduction. If stable system prompts, tool definitions, and long document prefixes can be cached, input-side cost can drop by an order of magnitude. The engineering recommendation is to make prompts “prefix-stable”: move volatile content to the end and put static specifications, few-shot examples, and knowledge snippets at the front.

    Illustrative code (pseudocode, expressing only the tiered routing idea):

    1. def route(task):
    2. if task.risk == "high" or task.need_deep_reasoning:
    3. return flagship_model # complex reasoning, long-chain coding
    4. if task.latency_sensitive and task.budget == "low":
    5. return lite_model # high frequency, short output, classification and extraction
    6. return mid_model # general-purpose workhorse

    4. Tiered Selection: Mid-Tier as the Workhorse, Lite for Throughput

    The recommended structure in practice is barbell-shaped. The mid-tier handles more than 70% of general requests, balancing quality and budget. The lite tier absorbs high-frequency short tasks such as intent recognition, field extraction, tag classification, format rewriting, and log summarization. The flagship tier is reserved for low-frequency, high-value scenarios: complex reasoning, large-scale refactoring, and long-form knowledge work.

    According to public third-party composite scores, mid-tier and lite tiers generally score on par with the previous generation’s workhorse model, at roughly half the previous generation’s promotional price. The lite tier’s unit price can be as low as about one twentieth of the mid-tier’s. This means that for budget-constrained business automation, the mid-tier is one of the most economical choices. For the capability ceiling and knowledge work, however, it clearly trails the flagship of the same generation, and on some knowledge-work tests it does not even match the previous generation’s flagship.

    5. Evaluation: Three Layers of Verification to Avoid Benchmark Illusions

    1. Offline evaluation set: sample from historical real requests and build a regression set of 300 to 1,000 items with reference answers, covering classification, extraction, rewriting, and code repair. Record accuracy, format compliance rate, and average token consumption.
    2. Shadow traffic: the new model receives real traffic on a side path without returning results, so output distributions and failure modes can be compared at low cost and with no risk.
    3. Canary rollout and automatic rollback: ramp from 5% to 20% to 50%, with three circuit-breaker thresholds for error rate, P95 latency, and cost per request. If any threshold is crossed, roll back automatically.

    6. Stability and Engineering Support

    Cost reduction must not come at the expense of availability. Put model services behind a unified inference gateway that handles authentication, rate limiting, retries, caching, and multi-tier routing. Pair it with object storage for long documents, a message queue for asynchronous peak shaving, a container platform for elastic replicas, and logging plus monitoring and alerting to track token consumption and quality metrics. Baidu AI Cloud offers standardized, cataloged components for these general capabilities, so teams can compose what they need without being locked into a specific interface shape.

    7. Common Mistakes

    • Looking at unit price but ignoring output length: output price is usually several times the input price, which matters most in long-form generation.
    • Ignoring retry cost: one retry from a lower tier can cancel out the entire unit price advantage.
    • Skipping prefix stabilization: without cache hits, you give up the largest cost lever.
    • Switching everything at once: without canary rollout and rollback, a failure escalates into a business incident.

    8. Conclusion

    The core value of a new generation of tiered models is not “the strongest” but “the cheapest option that is good enough.” Engineering teams should build a four-part toolkit: a capability matrix, a cost model, three-layer evaluation, and gateway routing. Use the mid-tier as the workhorse, the lite tier for throughput, and the flagship tier for high-value challenges, while continuously lowering unit cost through cache hits and prefix stabilization. The only criteria that matter in the end are real business experience and cost per task, not leaderboard scores.