Multi-Model Routing and Orchestration: Engineering Practices for Cost and Context Management
Multi-model routing solves three core problems: matching tasks to model capabilities, meeting response time targets, and keeping per-task costs under control. This article walks through routing rules, cost calculation formulas, context handoff across model switches, when multi-model orchestration is worth adopting, and practical rollout steps for engineering teams.
Multi-model routing mainly addresses three questions: whether a task matches a model’s capabilities, whether response times meet requirements, and whether the cost of a single task stays under control. This article covers routing rules, cost calculation, context management, and adoption boundaries. Throughout this article, the “orchestration layer” refers to the Harness orchestration layer, which is responsible for invoking models, persisting context, and coordinating tools.
1. Write Routing Rules First, Then Decide Whether to Enable Auto-Routing
Routing rules can be based on input length, task type, and failure scenarios. Here is a set of examples:
| Condition | Assigned Model | Rationale |
|---|---|---|
| Input exceeds 60k tokens (example threshold) | Long-context flagship model | Exceeds the context window of lightweight models; long-document reasoning is more stable |
| Single-turn Q&A or polishing, with a 2-second response requirement | Lightweight Flash model | Low latency, low per-request cost |
| Code generation or multi-tool invocation | Strong instruction-following model | Lower formatting error rate in tool-call parameters |
| Primary model times out or returns an error | Backup model of the same tier | Task continues without interruption |
These thresholds are examples only—rely on your own evaluation data. The matching order of rules must be explicit. Handle failure fallback first, then match by task type; otherwise a single request may match multiple rules, producing unpredictable results.
Auto-routing is executed by the platform gateway. The gateway typically estimates input token length, identifies request intent, and selects a model based on current model load, response latency, and billing multipliers. It suits general users and tasks without fixed requirements. However, intent classification can be wrong. Tasks involving compliance review, fixed output formats, or reproducible results should be pinned to a specific model rather than delegated to auto-routing.
2. Calculate Costs with Formulas and Compare Multipliers
Platforms usually convert each call into credits. A common calculation method:
Credits per call = base credits × model multiplier
Base credits = input tokens × input coefficient + output tokens × output coefficient
The input and output coefficients are defined by each platform and should be found in the billing documentation. Multipliers vary by model.
The following numbers are hypothetical and do not represent any platform’s real pricing. A call with 2,000 input tokens and 500 output tokens yields a base credit of 10 points. If the flagship model has a 1x multiplier, the call costs 10 points. If a lightweight model has a 0.2x multiplier, it costs 2 points. If the lightweight model meets quality requirements for that task, the same work costs only one-fifth of the credits.
Bills may differ from estimates for common reasons, including:
- Limited-time discounts or multiplier adjustments: multipliers may change over time; always verify against actual call records.
- Cache hits: some platforms bill cached input portions differently.
- Retries and failed requests: timed-out or errored calls may still consume credits; confirm the platform’s rules.
- Context accumulation: in multi-turn conversations, each turn re-bills the full conversation history, so long conversations grow in cost faster than single-turn usage.
When comparing models, use A/B testing: select 50 to 100 representative tasks, run them on candidate models, and record token counts, credit consumption, latency, and human ratings. Filter out models that fail quality requirements first, then compare costs. This avoids sacrificing output quality for a lower multiplier.
3. Persist Context Through the Orchestration Layer When Switching Models
The main difficulty in switching models is context continuity. Model B cannot read Model A’s internal state—it only sees what the orchestration layer passes in. Therefore, context should be stored in tiers:
- Session cache: stores recent conversation turns and the current step’s state. Fast to read and write, but should have an expiration time.
- Context window: the content actually sent to the model on each call, constrained by the model’s window limit. The orchestration layer decides what goes into it.
- Vector database: stores long-term material such as documents and past conclusions, retrieved on demand. Retrieval can miss relevant content, so key facts should also be saved as structured fields rather than relying on retrieval alone.
When switching models, pass a structured handoff document instead of the full chat history. Its fields fall into three categories:
- Must persist: task objectives, constraints, confirmed facts, reference IDs of tool-call results, and incomplete steps.
- Can be truncated: intermediate reasoning, repeated pleasantries, and details of past errors.
- Failure fallback: if the target model errors out because the context exceeds its limit, compress the history into a summary and retry. If a tool call fails, mark that step and hand it to a backup model or ask the user to confirm.
After a switch, output style may change. Use a fixed version of the system prompt and specify output format requirements in the handoff document.
4. Adoption Boundaries and Selection Checklist
Multi-model routing suits three scenarios: a task contains multiple steps of varying difficulty; a significant portion of high request volume could be handled by lightweight models; or costs need to be accounted per task type.
Skip it in these cases: single task type with low request volume, where routing maintenance may cost more than it saves; compliance scenarios requiring long-term reproducibility from the same model version; or when lightweight models clearly fail evaluation.
When choosing a model gateway or cloud platform, check the following:
- Whether it offers a unified API, so switching models only requires changing one parameter.
- Whether the billing documentation publicly lists multipliers, base credits, and discount rules, and supports exporting per-call details.
- Whether the data retention and training-use policies meet your requirements.
- Whether the platform gives advance notice of model deprecations or multiplier changes.
- Migration cost: whether prompts, evaluation sets, and call logs can be exported.
5. Rollout Steps
- Build an evaluation set by task type and define quality acceptance thresholds.
- Set a default model and a fallback model for each task type.
- Log the model name, input/output tokens, multiplier, latency, and rating for every call.
- Review routing rules and cost data monthly, and re-review promptly after multiplier changes.
