Multi-Model Tiered Routing for AI Agents: How to Reduce Costs

    AI agents often make multiple model calls per task, so comparing unit token prices alone is not enough to estimate cost. This article explains how to understand common billing dimensions, calibrate a cost model from actual usage, route tasks across model tiers by role, and apply engineering controls such as prefix caching, context trimming, structured output, and result reuse. It also covers validation methods and risks to manage when optimizing agent costs.

    1. Background

    Agent applications usually make multiple rounds of model calls in a single task, including decomposing requirements, retrieving information, generating code, and self-review. Most services bill by input and output tokens. As the number of calls increases, differences in unit prices are quickly amplified. Therefore, comparing unit prices alone is not enough when selecting models; estimates should also account for task structure, input/output ratio, and cache hit rates.

    2. Understand the Billing Structure

    Common billing dimensions fall into three categories:

    • Input tokens: system prompts, conversation history, retrieval results, and similar content.
    • Output tokens: content generated by the model. Most platforms charge more for output than for input because generation requires per-token computation.
    • Cached input tokens: when the same prefix is reused, this part of the input is usually billed at a price significantly lower than regular input.

    Different platforms use different metering units, conversion methods, and prices, and these can change over time. Actual estimates should be based on the official documentation for the relevant platform, and these parameters should be made configurable.

    3. Infer a Cost Model from Actual Usage

    If total consumption is available only from a bill or usage dashboard, regression can be used to infer the relative consumption rate of each model. The steps are:

    1. Group by model and record the input tokens, output tokens, cached tokens, and corresponding charge for each request.
    2. Build a linear model: charge ≈ a × regular input + b × output + c × cached input. The three coefficients are the relative consumption rates for that model.
    3. Keep part of the samples as a validation set to test out-of-sample error.
    4. Examine the residual distribution. If residuals show a clear pattern, it usually indicates a billing factor that has not been included, such as a fixed per-request overhead or a phase change in billing rules.

    A high goodness of fit only means the model explains the current data under the current rules. After billing rules or model versions change, data must be collected again and the model recalibrated.

    4. Route by Task Role

    The core principle of tiered routing is to use high-capability models for steps with high judgment density and low-cost models for steps that are repetitive and rule-based. Common tiers include:

    1. Planning layer: decompose goals, define steps, and determine dependencies. It makes few calls but has the greatest impact on overall quality.
    2. Reasoning layer: handle subproblems with multi-step logic or many constraints, such as boundary condition analysis and trade-off decisions.
    3. Execution layer: generate code, fill templates, and call tools according to the plan. It has the highest call volume and is usually the main source of cost.
    4. Batch layer: simple tasks such as classification, extraction, and format conversion, suitable for high-volume processing with lightweight models.
    5. Review layer: validate key outputs. This layer is triggered only at critical points to avoid full review at every step.

    The key to cost calculation is “number of calls × cost per call.” The execution layer may have a low cost per call, but if it is called frequently and each output is long, total cost can still exceed that of occasionally calling an expensive model. Therefore, tiering should account for both call frequency and average tokens per call.

    5. Implementation Example

    The following code shows a basic structure for cost estimation and routing. The price parameters are placeholders and should be replaced with the real parameters of the platform in actual use.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class ModelPrice:
    4. name: str
    5. input_per_m: float # unit cost per million regular input tokens
    6. output_per_m: float # unit cost per million output tokens
    7. cached_input_per_m: float # unit cost per million cached input tokens
    8. def estimate_cost(price: ModelPrice, input_tokens: int,
    9. output_tokens: int, cached_tokens: int = 0) -> float:
    10. """Estimate the relative cost of a single request. cached_tokens are part of the total input."""
    11. fresh = max(input_tokens - cached_tokens, 0)
    12. return (
    13. fresh * price.input_per_m
    14. + cached_tokens * price.cached_input_per_m
    15. + output_tokens * price.output_per_m
    16. ) / 1_000_000
    17. # Mapping from task type to model tier
    18. ROUTES = {
    19. "plan": "tier_high", # planning and review
    20. "reason": "tier_mid", # complex reasoning
    21. "execute": "tier_low", # main execution
    22. "batch": "tier_light", # batch simple tasks
    23. }
    24. def pick_model(task_type: str) -> str:
    25. # Unknown task types default to the execution tier to avoid accidental use of expensive models
    26. return ROUTES.get(task_type, "tier_low")

    Routing should also include fallback rules. For example, when a low-cost model fails repeatedly or its output fails structural validation, automatically escalate to a higher tier for retry, and record the number of escalations as input for later optimization.

    6. Engineering Practices for Cost Reduction

    • Stable prefix: place fixed content such as system prompts and tool definitions at the beginning of the request and keep it byte-identical to improve cache hit rates.
    • Context trimming: pass only the information required for the current task at each step to avoid unbounded growth of conversation history.
    • Output constraints: require structured output, such as JSON with fixed fields, to reduce irrelevant explanatory text.
    • Result reuse: for requests with identical input, reuse existing results instead of making repeated calls.
    • Request merging: when the interface supports it, merge multiple small tasks into a single call to reduce repeated instruction overhead.

    The effects of these practices need to be validated with data. For each optimization, record the average token count, cache hit rate, and task pass rate before and after the change; keep the change only when all three meet their targets.

    7. Risks and Evaluation

    Tiered routing introduces several new risks:

    • Quality regression: low-cost models are more likely to make errors on complex tasks. Build an offline evaluation set and measure pass rates separately by task type.
    • Latency and rate limits: different tiers may have different response times and concurrency quotas. Scheduling logic needs to account for timeouts and queuing.
    • Rule changes: billing rules and model versions are updated over time. The cost model should be recalibrated regularly rather than fixed once.
    • Data flow: when tasks are split across multiple models, data passes through more services. For sensitive information, evaluate the data processing scope of each layer according to compliance requirements.

    8. Summary

    The goal of multi-model tiered routing is to match the cost of each call with its contribution to quality. Implementation can proceed in this order: first clarify the billing structure, then calibrate the cost model with actual data, then divide task tiers by role, and finally reduce total overhead through caching, trimming, and structured output. Each step should be based on evaluation data, and a recalibration mechanism should be retained.