LLM Inference Cost and Task Routing: An Engineering Playbook

    This article explains how to treat large language model selection as a scheduling problem rather than a one-time choice. It covers how to read capability tiers, how to measure model performance on your own task categories, how to build a cost model that separates input, cached input, and output tokens, and how to design a tiered execution architecture with validation, bounded escalation, and stage-level metrics. A four-step rollout process and common anti-patterns are also included.

    1. Reframing the Problem: Why “Which Model Should We Use?” Is the Wrong Question

    Model capabilities keep stratifying and inference prices keep falling, yet many teams still pick a single strongest model and run their entire pipeline through it. The problem is that real business workflows are not one task. They are chains of stages with fundamentally different characteristics. Some stages involve long-chain reasoning and cross-module localization. Others are format conversion, field extraction, or template-based generation. Some simply re-read the same document repeatedly to answer questions. Forcing all of these into one model at one invocation tier wastes budget and makes quality bottlenecks hard to locate.

    A more rigorous framing is this: under a given quality constraint, how do you decompose work into independently measurable stages and choose the most cost-effective execution path for each one? The capability and price tiers now appearing within a single model family turn this from guesswork into something computable.

    2. Reading Capability Tiers Correctly: Replace Leaderboards with Stage Metrics

    Third-party benchmarks published by vendors — for example, evaluations targeting real code repository edits that check whether changes meet maintainer merge standards, and evaluations of multi-step agent tasks that report both scores and cost — are useful priors, not conclusions. Three reasons:

    1. Distribution shift: benchmark tasks often differ dramatically from your business in input length, number of tool calls, and error tolerance.
    2. Metrics are not additive: similar total scores do not mean similar performance at every stage. One model may lead on long-chain reasoning while another merely ties on short tasks.
    3. Different cost accounting: the “cost per completed task” in a benchmark usually includes retries and wasted calls, while your system may have caching and pre-validation, giving it a completely different cost structure.

    The more reliable engineering approach is to use benchmarks as a candidate filter, then run a second measurement pass on your own task set. Cover at least three representative stage types:

    • Defect fixing: given a repository and a failing test case, produce the minimal change that passes validation.
    • Document QA: given a long and outdated document, answer several individually verifiable questions, testing the ability to reconstruct an evidence chain.
    • Multi-step tool use: tasks requiring repeated retrieval, computation, or execution tool calls, testing planning and error correction.

    3. Cost Model: Three Token Types Must Be Accounted for Separately

    Getting the budget right starts with accepting that the unit prices of input, cache-hit input, and output often differ by an order of magnitude. Ignoring this leads to severely misjudging the cost of scenarios that repeatedly call with long context.

    A directly usable accounting function:

    1. def estimate_cost(in_tokens, cached_in_tokens, out_tokens,
    2. p_in, p_cached, p_out):
    3. # Prices are normalized per million tokens
    4. return (in_tokens * p_in
    5. + cached_in_tokens * p_cached
    6. + out_tokens * p_out) / 1_000_000

    Two practical conclusions follow:

    • When repeatedly processing the same material, keep the stable prefix (system prompt, specification documents, code index summary) fixed at the front to maximize cache hits. The cost structure shifts from linear growth to roughly constant plus a small increment.
    • When every call reads entirely new material, output length and retry count are the main variables. Prioritize compressing output, constraining format, and cutting wasted rounds.

    4. Routing and Escalation: Run the Cheap Path First, Escalate the Hard Cases

    The recommended architecture is tiered execution with progressive escalation, not a wholesale replacement of the pipeline:

    1. Request -> Preprocess and normalize -> Lightweight model executes
    2. | |- Passes validation -> Return
    3. | |- Fails N times in a row -> Escalate to a higher tier
    4. | |- Cache hit -> Reuse directly
    5. -> Record stage-level metrics (accuracy / human rework rounds / actual spend)

    Key design points:

    1. Validation comes first. Use executable unit tests, schema validation, and rule comparison as the objective judge. Do not let a model’s self-assessment decide whether escalation is needed.
    2. Escalation must be bounded. Set a maximum number of escalation rounds and an overall budget cap so long-chain tasks do not spiral into ever more expensive detours.
    3. Instrument at the stage level. Metrics must attach to stages rather than the whole request, otherwise you cannot tell whether gains came from the model or from caching and validation.
    4. Canary and rollback. Run the new path against a control on a small traffic slice first, keep a switch for the old path, and roll out gradually by stage.

    5. A Four-Step Rollout

    Step one: pick three things you do often as a baseline — fix one known defect, answer verifiable questions from one old document, run one multi-step task that needs tools. Record whether key results were correct, how many rounds of human edits were needed, and the final cost.

    Step two: run ablation experiments. Disable caching, disable validation, and disable escalation one at a time, then observe changes in cost and quality to identify the real cost drivers.

    Step three: set routing thresholds. Trigger escalation on two conditions together — consecutive failures plus a per-stage budget — to avoid misjudgment from a single metric.

    Step four: build a dashboard. Put each stage’s success rate, rework rounds, cache hit rate, and cost per task in one view, review weekly, and adjust thresholds.

    6. Common Anti-Patterns

    • Substituting overall ranking for stage measurement, so production results miss expectations.
    • Concatenating all prompts into a dynamic long text, so the cache never hits and the bill runs out of control.
    • Lacking objective validation, so escalation decisions are led by the model’s own account.
    • Replacing the entire workflow at once, so neither gains nor risks can be attributed.

    7. Conclusion

    Capability tiers and price tiers have turned model selection into a scheduling problem. With the general-purpose building blocks available on cloud platforms such as Baidu AI Cloud — object storage for materials, message queues to decouple tasks, container platforms to host inference services, and logging plus monitoring and alerting for stage-level observability — a team can build the measurement system first and discuss model choice afterward. Let the lightweight path carry the routine load, hand the stages that keep getting stuck to the higher-capability tier, and let data rather than leaderboards decide every call.