LLM Cost Reduction: Practical Multi-Model Routing and Its Limits

    This article explains how to reduce large language model (LLM) application costs with multi-model intelligent routing. It covers when routing is appropriate, how to validate whether a model is good enough using business data, what actually drives cost, the core routing components, a sample implementation, risk controls, and common pitfalls. The emphasis is on measuring per-task total cost and quality before and after routing.

    LLM Cost Reduction: Practical Multi-Model Routing and Its Limits

    1. Introduction: Cost Pressure and Applicability Boundaries

    Many teams begin by calling the most capable flagship model directly. This usually protects output quality, but as call volume grows, the bill rises quickly. For tasks with relatively clear rules, such as information extraction, field filling, and format conversion, the flagship model’s extra capabilities are often unnecessary.

    The approach discussed here is suitable for routine tasks such as structured extraction, summarization, translation, and format conversion. For multi-step mathematical derivation, complex code generation, and tasks that require long-chain reasoning, high-spec models should still be preferred. Sending every task to a low-cost model introduces quality risk.

    2. How to Verify Whether Different Models Are “Good Enough”

    Before choosing a model, evaluate it against your own business data. A reliable evaluation usually includes the following elements:

    • Test set: samples drawn from real business traffic, covering common inputs and edge cases.
    • Sample size: more samples produce more stable conclusions. With too few samples, a single deviation can change the ranking.
    • Scoring rules: define what counts as correct, such as whether fields are complete, values are consistent, and JSON can be parsed.
    • Model identifier: record the model name, version number, and call date, because providers may update models.
    • Evaluation results table: record quality score, tokens per task, and cost per task for each model.

    The original test report mentioned that “all models achieved full scores” and reported an approximately 85% reduction in tokens. Those conclusions did not include the test set, sample size, or billing basis, so they cannot be directly applied to another business. Readers should re-measure on their own data and use the measured results to decide the routing strategy.

    3. What Determines Cost

    Many people confuse token count with call cost. In practice, the basic cost formula is:

    Call cost = input tokens × input unit price + output tokens × output unit price

    Therefore, even if two models use the same number of tokens, their costs may differ because their unit prices differ. In addition, the following factors affect the final bill:

    • Tokenizer differences: the same text may be split into different token counts by different models, especially for Chinese text.
    • Output length: when a model is asked to output complete JSON or a long table, output tokens increase significantly, and output unit prices are usually higher than input unit prices.
    • Prompt length: longer system instructions and examples increase input tokens on every call.
    • Retries and fallback: retrying after a quality check failure or switching to a more expensive model adds extra cost.

    When calculating cost savings, measure “total cost per task” and include the cost of retries and fallback.

    4. Core Components of Multi-Model Intelligent Routing

    Intelligent routing sits between the application and model APIs and selects the appropriate model for each request. A usable routing system usually includes three components.

    a. Complexity Assessment

    The router first classifies the request. Rules can be used, such as whether the task type is on a whitelist or whether the prompt contains keywords like “prove” or “derive.” Beyond rules, a small model or vector similarity can also be used for classification. Simpler rules are easier to explain, but usually have a higher misclassification rate.

    b. Model Pool and Cost Optimization

    The model pool usually contains lightweight, standard, and flagship versions. The router needs to read each model’s error rate, latency, and unit price, and choose the lowest-cost model that meets the quality floor.

    c. Fallback and Circuit Breaking

    When a model’s error rate rises, latency exceeds a threshold, or rate limiting occurs, the router should automatically switch to a backup model and temporarily stop calling the failing model. After the circuit recovers, traffic can be ramped up gradually. This mechanism helps maintain service availability, but switching to a backup model also increases cost, so it should be tracked separately in reports.

    5. Example Implementation

    The following code shows the basic structure of a router. The unit prices are example values and should be replaced with the provider’s real prices. call_fn and validate_fn need to be implemented according to the SDK and business format actually used.

    1. import re
    2. from dataclasses import dataclass
    3. LONG_PROMPT_CHARS = 8000
    4. SIMPLE_TASKS = {"extract", "format", "summarize", "translate"}
    5. COMPLEX_PATTERN = re.compile(r"证明|推导|多步|代码生成|数学|prove|derive", re.I)
    6. @dataclass
    7. class Model:
    8. name: str
    9. price_per_1k_tokens: float # Example value; use the provider's bill as the source of truth
    10. timeout_s: float
    11. class ModelRouter:
    12. def __init__(self, cheap, standard, flagship, metrics):
    13. self.cheap = cheap
    14. self.standard = standard
    15. self.flagship = flagship
    16. self.metrics = metrics # Must provide error_rate(name) and p95_latency(name)
    17. def choose_model(self, prompt, task_type):
    18. # Use the flagship model directly for non-whitelisted tasks or requests with complex reasoning features
    19. if task_type not in SIMPLE_TASKS or COMPLEX_PATTERN.search(prompt):
    20. return self.flagship
    21. # Use the standard model for long-context requests to avoid quality degradation from the lightweight model
    22. if len(prompt) > LONG_PROMPT_CHARS:
    23. return self.standard
    24. if self._healthy(self.cheap):
    25. return self.cheap
    26. return self.standard
    27. def _healthy(self, model):
    28. return (self.metrics.error_rate(model.name) < 0.05
    29. and self.metrics.p95_latency(model.name) < model.timeout_s)
    30. def run(self, prompt, task_type, call_fn, validate_fn):
    31. first = self.choose_model(prompt, task_type)
    32. order = [first] + [m for m in (self.standard, self.flagship) if m.name != first.name]
    33. last_error = None
    34. for model in order:
    35. try:
    36. result = call_fn(model.name, prompt, timeout=model.timeout_s)
    37. except Exception as exc:
    38. last_error = exc
    39. continue
    40. # If output fails format or field validation, treat it as a failure and switch models
    41. if validate_fn(result):
    42. return model.name, result
    43. last_error = ValueError(f"{model.name} output failed validation")
    44. raise RuntimeError("All candidate models failed") from last_error

    There are several points to note in this code. First, the validation function is the last line of defense for quality and should at least check that JSON is parseable, required fields exist, and enum values are valid. Second, falling back to the flagship model significantly raises per-call cost, so fallback counts need to be monitored. Third, timeouts and retry counts should be capped to prevent runaway costs during failures.

    6. Risks and Monitoring

    The main routing risk is misclassification: a complex request is sent to a lightweight model and output quality drops. The following measures can help control this risk.

    • Quality sampling: sample a percentage of lightweight model outputs, review them manually or with a stronger model, and record the pass rate.
    • Quality regression testing: rerun the evaluation set whenever a model version changes or routing rules are modified.
    • A/B testing and canary release: first send a small share of traffic through the new route, compare quality and cost, and then switch fully after confirming the results.
    • Cost and fallback monitoring: track call counts, cost per task, fallback ratio, and retry counts for each model.

    Recommended metrics include quality score, error rate, p95 latency, cost per task, fallback ratio, and routing distribution for each model. These metrics should be viewable daily and have alert thresholds.

    7. FAQ

    How should complexity thresholds be set?
    Start by finding samples where the lightweight model failed in business data, then analyze their common features, such as input length, field count, or keywords, and set thresholds accordingly. Thresholds should be adjusted regularly based on quality sampling results rather than fixed once and left unchanged.

    What are common mistakes?
    First, tracking only token counts without unit prices and retry costs. Second, looking only at average latency and not tail latency. Third, launching routing rules without quality regression testing. Fourth, having no cap on fallback logic, which can cause costs to rise quickly during failures.

    Does a lightweight model always save money?
    Not necessarily. If the lightweight model has a high failure rate, the total cost of retries and fallback may exceed the cost of using the standard model directly. Therefore, judge based on the final cost per task together with the quality score.

    8. Conclusion

    Multi-model intelligent routing can reduce model call costs on routine tasks, but the savings depend on task type, evaluation basis, and routing quality. Developers should first validate each model’s quality on their own data, then design routing rules around total cost per task. After launch, quality sampling, regression testing, and cost monitoring are still needed to keep quality above the agreed threshold. With that foundation, the routing strategy can continue to reduce costs.