The direct answer
Use a routing layer to send each request to the cheapest eligible model that meets the task’s quality, latency, context, and data-policy requirements. If that model fails, the layer should move the request to a tested fallback or degrade the feature in a controlled way.
That sounds simple, but the important distinction is between routing and blind failover. Routing chooses where a request should go before execution. Failover reacts when a provider or model cannot complete it. A production system needs both, plus limits that prevent one bad response from becoming a large bill.
For a founder, the payoff is operational rather than cosmetic: more of the product remains available during provider incidents, routine requests stop consuming premium-model budgets, and the team can see why each request was sent where it went.
Start with work, not models
Do not begin by listing every available model. Begin by separating the work your product performs.
A support assistant might contain several distinct task classes:
- classify the incoming request;
- retrieve relevant context;
- answer a routine question;
- analyze a long or ambiguous case;
- rewrite the answer for a particular tone;
- escalate to a human.
Those tasks have different requirements. The classification path may need speed, predictable structure, and low cost. The long analysis path may need deeper reasoning and a larger context window. The escalation path may need to be conservative rather than clever.
Create a task inventory with at least four columns:
| Requirement | Questions to answer |
|---|---|
| Quality | What must the output contain, and how will a weak result be detected? |
| Latency | Is this customer-facing, background, or batch work? What is the deadline? |
| Context | How much input must fit, and does the task require source documents? |
| Risk | Is the output customer-facing, regulated, financial, or allowed to make operational changes? |
Split any class whose answers differ substantially. “All support requests” is too broad. “Routine policy questions requiring a grounded answer under five seconds” is routeable.
This task-first approach prevents a common mistake: selecting a model because it is popular or cheap, then discovering that the product needs a different latency, quality, or data boundary.
Build a route matrix
For each task class, define the policy before choosing providers. A practical route matrix looks like this:
| Task class | Primary route | Escalation route | Failure response |
|---|---|---|---|
| Classification | Low-cost, fast, structured-output model | Another compatible fast model | Queue for retry or use a deterministic parser |
| Routine answer | Approved general model with retrieval | Higher-quality model | Return a safe “I need more information” response |
| Complex analysis | Strong reasoning model | Alternate provider with equivalent capability | Save the job and notify operations |
| Data transformation | Private or policy-approved endpoint | Second approved endpoint | Pause the workflow; do not expose raw data |
The matrix should be versioned. Record the exact model or endpoint, its provider, the policy version, and the reason for selection. Avoid relying only on a moving alias such as a general “latest” model when reproducibility matters.
Use hard gates before cost scoring
A weighted score is useful only among models that are already eligible. Start with gates:
- Data-policy gate: the endpoint and region must be approved for the request’s data.
- Capability gate: the model must support the required input and output format.
- Context gate: the request and expected output must fit the context and output limits.
- Quality gate: the model must pass the task’s minimum evaluation threshold.
- Deadline gate: the model and provider must be capable of meeting the workflow’s latency requirement.
Then rank the remaining candidates by cost, expected latency, reliability, or a weighted combination for that task class. A simple expression can make the trade-off explicit:
eligible candidates → lowest expected cost → selected model
For a live customer feature, latency may outrank cost. For a scheduled report, cost may outrank latency. For a regulated workflow, policy eligibility should not compete with price at all; it is a gate.
Do not build a dynamic router merely because sophisticated routing is available. Rule-based routes are easier to explain, test, and debug. Move to per-request classification or predictive routing only when you have representative traffic, labeled examples, and evidence that the extra decision step produces more value than its latency and maintenance cost.
Route by cost without making cost the only objective
Token price is visible, but it is not the whole unit economics of an AI request. A nominally cheaper model can cost more if it:
- produces longer answers;
- fails a required format and needs a retry;
- requires more retrieval or context;
- causes escalation to an expensive model;
- adds latency that interrupts the customer flow.
The meaningful measure is the cost of an acceptable completed request, including retries and fallback. Track it by task class rather than looking only at average price per token.
Keep a per-request and per-tenant budget. A maximum token count is useful, but a spending limit is also necessary because retries, tool loops, and long outputs can multiply usage. For background work, add concurrency limits and backpressure so a fallback provider is not overwhelmed when the primary path fails.
For applications with many repeated requests, caching may remove traffic before routing occurs. Review LLM Response Caching Guide: Save Inference Cost Without Serving the Wrong Answer before adding that layer; a stale or cross-tenant answer can cost more than the inference it saves.
Design fallback around failure classes
Not every failure should trigger the same action. Separate at least these categories:
Transient provider failures
Examples include timeouts, temporary unavailability, or rate limiting. Retry only when the operation is safe to repeat. Use bounded attempts, exponential backoff with jitter, and a total time budget. After that, move to the approved fallback.
Capacity and rate-limit failures
Do not immediately send the entire backlog to one fallback. Route only eligible traffic, apply the fallback’s own concurrency cap, and preserve backpressure. Otherwise a primary-provider incident can become a secondary-provider incident.
Invalid or incomplete outputs
A response that arrives but violates a schema, omits required evidence, or fails a deterministic validator should be retried or escalated according to the task class. This is a quality cascade, not a transport failover.
Policy and safety failures
Do not route around a safety or data-policy rejection by trying another provider that has weaker controls. Escalate to a human, use a deterministic fallback, or stop the workflow.
Task-level capability failures
If the model lacks the required context, tool support, or reasoning depth, use a stronger eligible model. Keep this distinct from an outage: the first model worked; it simply was not appropriate.
A fallback is safe only when it can consume the same request and produce an acceptable result. A different model may require a different schema, tool protocol, context format, or prompt. Test those differences in production-like conditions rather than assuming API compatibility means behavioral compatibility.
Make safe degradation explicit
A fallback is not automatically better than an error. It may be slower, more expensive, less accurate, or subject to different data controls.
Define the degradation level for each feature. For example:
- Full service: the primary model returns an accepted result.
- Reduced quality: a fallback model returns a less detailed but still valid result, and the product labels the limitation where appropriate.
- Limited service: retrieval or deterministic templates provide a partial answer.
- No completion: the job remains queued, the user receives a clear status, and operations are alerted.
Do not silently replace a carefully reviewed answer with a weaker model in a high-stakes workflow. If degradation is acceptable, state the conditions in the product contract and telemetry.
Background jobs often have an advantage: the request can wait for a healthy provider. Customer-facing work may instead prefer a fast partial answer. These workloads should not share identical fallback rules. For a broader view of separating interactive and background inference, see How to Isolate Synchronous, Asynchronous, and Agent-Driven AI Workloads.
Put the router between the product and providers
Your application should call a stable internal or gateway interface rather than hard-coding provider SDKs throughout the codebase. That does not require adopting a particular vendor. A small internal service can provide the same architectural boundary.
The router should own or coordinate:
- route selection by task class;
- eligibility checks and provider health;
- retry and fallback execution;
- timeouts and cancellation;
- token and spend limits;
- response validation;
- structured routing telemetry.
Keep business-specific logic outside it. The router should know that “billing analysis” requires model B, but it should not decide whether a customer deserves a discount.
A simplified request flow is:
application → task classification → eligible routes → primary attempt → validation → fallback or degraded result
Every attempt should carry the same internal request ID. The final response may come from a different provider than the first attempt, but users should not have to understand the failover to receive useful service.
Prevent fallback loops and duplicate side effects
Idempotency matters as soon as a model can call tools or update business systems. A timeout does not prove that the first call failed; the provider may have completed it after the client gave up.
For each attempt, attach an idempotency key to tool and workflow operations where supported. Record which operations already succeeded. Never blindly replay a non-idempotent action after an uncertain timeout.
Also enforce:
- a maximum total attempt count;
- a maximum fallback depth;
- one policy revision per request, preventing a failed route from re-entering the original route;
- a deadline that includes retries;
- cancellation propagation to queued and running work.
Without these controls, a provider slowdown can multiply requests and costs while also corrupting downstream state.
Evaluate routing as a system, not just model quality
Offline evaluation should use representative, versioned examples for every task class. Include normal traffic, difficult edge cases, policy-sensitive inputs, and outputs that should be rejected.
Measure more than answer accuracy:
| Metric | What it reveals |
|---|---|
| Accept rate by route | Whether the selected model produces usable results |
| Escalation rate | How often the primary route is insufficient |
| Retry rate | Whether transient or validation failures are being absorbed |
| Fallback rate | How often providers fail or outputs fail validation |
| Duplicate side effects | Whether retries or failover are unsafe |
| P50 and P95 latency | Whether the route meets user expectations |
| Cost per accepted request | The true economic outcome of routing |
| Completion rate | Whether the feature delivers useful work |
A cheap route with a high escalation rate may be more expensive than a moderately priced primary route. Conversely, a strong model may be unnecessary for tasks whose outputs are easy to validate deterministically.
Run offline evaluations before changing a route. After deployment, compare production metrics by task class and policy version. Quality can drift because customer language changes, retrieval inputs change, or a provider updates behavior beneath a stable alias. Alert on changes in acceptance, escalation, latency, and spend—not only on total request volume.
A rollout plan that preserves delivery speed
Do not begin by replacing every model call with an ML-driven router. Use a staged rollout:
Stage 1: One internal routing boundary
Move direct provider calls behind one interface. Keep the current model as the default route. This creates a seam for future changes and gives you a place to record request metadata.
Stage 2: Split obvious task classes
Separate background, customer-facing, and high-risk paths. Apply hard limits to each. Establish an alert before adding automated failover.
Stage 3: Add one cheap route and one fallback
Choose a bounded task with deterministic validation, such as classification. Compare the primary and fallback models offline, then shadow production traffic. If both pass, enable controlled failover.
Stage 4: Add quality cascades
Introduce escalation based on validation or confidence signals. Do not treat a model’s own confidence as ground truth; test whether the signal predicts acceptance on your workload.
Stage 5: Automate selection where evidence supports it
Add per-request complexity classification or learned routing only after rule-based routing has measurable limits. Preserve manual overrides and an emergency route.
The operating checklist
Before declaring the architecture production-ready, verify that you can answer “yes” to these questions:
- Every request has a named task class and an owner.
- Each class has quality, latency, context, and risk requirements.
- Data-policy and capability rules exclude ineligible models before price is considered.
- The primary and fallback routes have both passed representative offline evaluations.
- Retries are bounded, idempotent where possible, and included in one deadline.
- Fallbacks cannot create loops or bypass safety rules.
- A failed request can degrade into a defined partial result or queued job.
- Per-request, tenant, and workload budgets exist.
- Routing decisions record policy version, model, provider, attempt, latency, usage, and outcome.
- Alerts cover sustained fallback rates, latency, cost per accepted request, and validation failures.
- You can disable a provider or change a route without redeploying the entire product.
Frequently asked questions
Should every product use multiple models?
No. Multiple models create integration, testing, and operational complexity. A single model may be the right choice when one workload has uniform requirements and low commercial volume. Add routing when you have a clear pain: premium cost on routine work, unacceptable latency on a distinct class, provider lock-in, or a business requirement to remain available during an outage.
Is a gateway the same as a router?\n
Not exactly. A gateway generally provides a unified API and cross-cutting controls such as authentication, logging, and rate limiting. A router decides which model should handle a request. Products often combine both, but neither label guarantees good routing policy; the policy and its evaluation still belong to your team.
Should fallback always be a different provider?\n
Different providers reduce correlated infrastructure risk, but they can introduce behavioral or data-handling differences. Another model from the same provider may be easier to qualify but may share the same outage domain. Choose fallbacks based on tested independence, policy eligibility, compatibility, and cost—not geography of the logo alone.
How often should routing policies change?\n
Change them when traffic, evaluation results, provider health, or commercial constraints change. Do not change routes because a new model launched. Require a versioned policy, an offline comparison, a staged rollout, and a rollback path.
The central principle is simple: route by requirement, price only after eligibility, and treat every fallback as a different operating mode that needs its own limits and evidence. That is how model routing becomes an infrastructure discipline rather than an occasional cost-saving trick.







