Model routing: balancing cost, latency and quality in production

Sending every request to the largest model is the simplest design and also the most expensive one. Routing sends each request to the cheapest model that passes your tests for that task, which means it depends on those tests existing.

By Nabil Ahmed8 minute read

The lunar surface near 30°N, 170°E, lit by a low Sun with night falling across one side.
The Moon near 30°N, 170°E. Rendered by Farside from NASA Lunar Reconnaissance Orbiter elevation data.

The first version of most AI features sends every call to one model, usually the most capable one available, because that was the model that got the prototype working. That is a reasonable start, but with real traffic the model drafting a careful reply to a complaint is also being paid to decide whether a message says "yes" or "no".

Providers sell families of models at very different prices and speeds, and the smallest model in a family can cost a small fraction of the largest per token while responding several times faster. Many tasks inside an application, such as classifying, extracting, reformatting or answering from a short passage, come out just as well on the small model, although on other tasks it is clearly worse.

Model routing means deciding for each request which model should handle it. We think it pays for any feature with meaningful volume and that the simple forms deliver most of the benefit, but no form of it is safe without a test set for each route, because without evaluation routing lowers quality unnoticed.

In brief

  • Model routing sends each request to the least expensive model that meets the quality bar for that task, and that bar has to be defined by tests rather than by impression.
  • Static routing by task type is the simplest form and captures most of the available savings, because an application already knows which step it is executing.
  • A cascade tries a small model first and escalates when the answer fails a check, which saves money only when failures can be detected by a cheap and reliable check.
  • Fallback routing for availability is a separate concern from cost routing, and a fallback model that has never been tested with your prompts cannot be relied on when the primary fails.
  • The figure to manage is the cost per successfully completed task at a given latency, because cost per token leaves out the retries and escalations a cheaper model can cause.

Why one model for everything stops working

Token charges grow in line with traffic, and an application that makes several model calls for each user action multiplies them. Large models also generate more slowly, so a user who has to wait for a classification step before anything appears on screen gains nothing from how capable the classifier was. Providers have outages and rate limits as well, which means a feature with only one model behind it has a single point of failure.

These pressures pull against each other. The cheapest model may not be the fastest for your prompt, the fastest may miss your quality bar, and the highest quality option may be rate-limited at peak. Routing lets you make that trade deliberately for each task, where a single model choice makes it once for the whole system.

Four routing patterns

Static routing by task. Each step in the application is assigned to a named route, and configuration maps that route to a model, so intent classification might go to a small model while final drafting goes to a large one. Nothing is decided at run time because the code already knows which step it is on, and this predictable, easily tested pattern is where we recommend starting.

Cascade from small to large. A request goes to a small model first and a check is applied to its output, and if the check fails the request is sent again to a larger model. Cascades suit tasks where most inputs are easy and a few are hard, with no way to tell in advance which kind a given input is.

Learned or rule-based router. Before any model answers, a classifier looks at the incoming request and predicts which model it needs. The classifier may be a set of rules (input length, presence of an attachment, language), a small trained model, or a small language model asked to rate difficulty. This avoids the double call of a cascade, at the price of adding a component that can itself be wrong.

Fallback to another provider. When the primary model returns an error, the request is retried on a different model or with a different provider, and the same happens when the call times out or is rate-limited. The purpose of this pattern is resilience rather than cost.

All four patterns are normally implemented in a model gateway, a service between your applications and the providers which resolves route names and applies timeouts and retries and records each call. With routing in the gateway, as part of your AI integration layer, applications ask for "triage" or "drafting" and never hard-code a model name. A route definition in the gateway might look like the following:

routes:
  intent-classification:
    primary:  { provider: a, model: small-v3, timeout_ms: 1500 }
    fallback: { provider: b, model: small-x,  timeout_ms: 2000 }
    eval_suite: evals/intent
    min_pass_rate: 0.97

  order-answer:
    cascade:
      - model: small-v3
        accept_if: [schema_valid, cites_order_record, no_refund_language]
      - model: large-v3
    fallback: { provider: b, model: large-x }
    eval_suite: evals/order-answers
    min_pass_rate: 0.95

  complaint-draft:
    primary:  { provider: a, model: large-v3, timeout_ms: 20000 }
    fallback: { provider: b, model: large-x }
    eval_suite: evals/complaints
    min_pass_rate: 0.90

Each route names its own evaluation suite and pass threshold, and that link is the most important part of the design.

Where routing goes wrong

The escalation check is weak. A cascade depends on the check that decides whether to accept the small model's answer. Asking the model how confident it is works poorly, because stated confidence is not a calibrated probability and wrong answers often sound sure of themselves. Good checks are ones the system can verify without trusting the model, for example that the output parses against a schema, that every cited record identifier exists, that a calculated total matches, that required fields are present and that a forbidden phrase is absent. Where no such check exists, a cascade will pass weak answers through, and routing the task statically to the larger model is the safer choice.

Latency gets worse for the hard cases. An escalated request pays for both calls in sequence, so if a significant share of requests escalate, tail latency ends up worse than sending everything to the large model. Track the escalation rate and high-percentile latency alongside the average.

Prompts are not portable. A prompt tuned for one model often behaves differently on another, even inside the same family. The differences grow across providers, because models vary in formatting conventions and tool-calling behavior and in how well they handle long instructions. Each model on a route needs its prompt validated and sometimes a prompt variant of its own, and that includes fallbacks, since a fallback that has never run against the test suite is likely, on the day it is needed, to return output in a shape the downstream code does not expect.

Prompt caching is fragmented. Provider-side prompt caching applies per model, so spreading traffic for the same long prompt across several models reduces the cache hits on each, which can cancel part of the saving routing was meant to deliver.

The router becomes a hidden model. A learned router is one more thing that drifts. When the mix of incoming requests changes, a router trained on last quarter's traffic misjudges difficulty without anything failing visibly, so it needs its own test set and monitoring, which is why we would adopt it last.

Savings are measured per token. A small model that needs two retries, or whose answer leads to a person handling the case anyway, has saved nothing. The useful figure is cost per task completed correctly, and we break it down in what an AI feature actually costs to run.

A retailer's service assistant

Consider a mid-size online retailer whose assistant handles customer messages. Every message triggers three model calls, one to classify the intent, one to compose an answer from order data and, for complaints, one to draft a longer reply for an agent to review. All three use the provider's largest model, so monthly spend rises with volume, and customers wait several seconds for the first word because classification must finish before anything else starts.

The team already has a test set for each step built from real past conversations. They run each step's set against the small, medium and large models.

Intent classification scores the same on the small model as on the large one, so it moves to the small model through a static route and the user sees a response sooner.

Order answers are mixed, because the small model handles "where is my order" well but makes mistakes on messages that involve partial shipments and returns in the same order. The team builds a cascade in which the small model's answer is accepted only if it validates against the response schema, cites an order line that exists in the order record and contains no language about refunds, a topic policy reserves for the larger model and stricter instructions. Anything else escalates, and the team runs the test set through the cascade as a whole to confirm that the combined pass rate matches the large model alone.

Complaint drafts are clearly better on the large model, and because their volume is low, that route stays where it is.

Finally, each route gets a fallback on a second provider. Its prompts are adjusted and the same test suites are run against it, and in the first of those runs the second provider's model wraps its JSON output in explanatory text, which would have broken the parser. The team fixes it with a prompt change and stricter output handling during testing, before an outage could expose it.

What the team reports is cost per resolved conversation, latency to first response at the ninety-fifth percentile, the escalation rate of the cascade and the pass rate for each route, tracked weekly, rather than a token price.

Evaluation is the precondition

Every routing decision is a claim that model X is good enough for task Y, and that claim is only as strong as the test behind it. This is why routing belongs with AI evaluation and assurance as well as with cost management, and in practice it means the following four things:

  • Each route has its own test set drawn from real inputs for that task, and each case has an agreed correct output or grading criteria.
  • A cascade is tested as one unit, because its quality depends on the acceptance check as much as on either model.
  • The suites run on a schedule and on every change to a prompt, a route or a model version, as described in the test set that runs every night.
  • Model upgrades are treated as changes, so when a provider releases a new version or retires an old one, the route is tested again before it is switched.

Routing can also be pushed too far. Every route, cascade stage and fallback is another configuration to test and keep current, and a feature with modest traffic may save less from routing than it costs in engineering attention. Two or three static routes are easy to justify, whereas a learned router across six models rarely is outside very high volumes.

What to do next

  1. List every model call your application makes by task, together with its volume, latency and average input and output tokens.
  2. Sort the list by total spend and take the top few tasks as candidates.
  3. Confirm that each candidate has a test set, and if one is missing, build it before changing anything.
  4. Run each candidate task against a smaller model with its prompt adjusted, and where the pass rate holds, move the task with a static route.
  5. Where results are mixed, look for a cheap acceptance check that can be verified, test a cascade as a whole if one exists, and otherwise leave the task on the larger model.
  6. Add a fallback for each route on a second model or provider, and run the same suite against it.
  7. Keep route definitions in version control behind a gateway, as part of how you run AI in production, and report cost per completed task, tail latency and the pass rate for each route.

Related services

Start a conversation.

A short paragraph is enough. A principal reads every message and replies within one working day.

Or email hello@farside.works. We use what you send only to reply. Privacy