Concept

What is LLM routing, and how does automatic model selection work?

LLM routing is the practice of deciding, for each request, which model and which provider should serve it, instead of sending every request to one fixed model. Automatic model selection is routing where a router makes that choice for you: it inspects the request, estimates what the request needs, and picks a model from a pool of candidates. In FastRouter, setting the model to fastrouter/auto turns on automatic model selection, which weighs query complexity, domain or topic, and cost-efficiency.

Last updated

Key facts

  • LLM routing chooses a model and a provider per request instead of using one fixed model.
  • Model routing picks which model answers. Provider routing picks which provider serves that model.
  • In FastRouter, setting model to fastrouter/auto delegates model selection to its routing engine.
  • FastRouter's automatic selection weighs query complexity, domain or topic, and cost-efficiency.
  • FastRouter can sort providers by price, latency or throughput through the provider object.

What is LLM routing?

LLM routing is a decision step placed in front of model calls. For each request, a router chooses which model should answer and which provider should serve that model, based on rules you set or on properties of the request such as difficulty, subject, price or speed.

Teams route because requests differ. A short classification prompt and a long multi-step reasoning task do not need the same model, and sending both to the most capable model costs more than necessary. Routing also helps with availability, because a request can be sent elsewhere when a model or provider is rate-limited or down.

What is the difference between model routing and provider routing?

Model routing decides which model answers a request. Provider routing decides which company's infrastructure serves that model, since many models are offered by more than one provider. The two decisions are independent: you can pin a model and still route between its providers, or do both automatically.

  • Model routing affects output quality, capability and token price, because different models produce different answers.
  • Provider routing keeps the model the same and changes who serves it, which mainly affects price, latency, throughput and availability.
  • Fallback is a related mechanism: an ordered list of alternatives that is tried when the first choice fails.

How does automatic model selection work?

Automatic model selection replaces a hardcoded model ID with a router that picks the model at request time. The router reads the incoming messages, estimates what the request needs, compares the candidate models available to it, and forwards the request to the one it ranks best.

The inputs a router uses vary by product. Common ones are how complex the request is, what subject it covers, and what each candidate model costs. The application still sends an ordinary chat request. The only difference is that the model field names the router instead of a specific model.

The trade-off is predictability. With a fixed model, every request runs on the same model. With automatic selection, the model can differ from one request to the next, so it helps to be able to see which model was chosen.

How does FastRouter handle model and provider routing?

FastRouter routes at both levels. Setting model to fastrouter/auto delegates model selection to its routing engine, which picks from the available pool by query complexity, domain or topic, and cost-efficiency. Separately, a provider object on the request controls which provider serves a model.

Automatic selection needs no other configuration and no model preference lists. The request is a standard chat completions call to /api/v1/chat/completions. A model selection endpoint, /api/v1/model/selection, returns the selected_model, the top_candidates considered, the assigned_tags and the selection_strategy for a prompt without running the completion.

For provider routing, the provider object accepts order, only, ignore, sort, allow_fallbacks and require_parameters. The only and ignore fields narrow the eligible providers, order sets an exact sequence, and allow_fallbacks lets the request move to the next provider when the primary is unavailable. The sort strategies are compared below.

FastRouter provider routing strategies
StrategyHow to set itWhat it selects
DefaultSend no provider objectFavors providers that meet a performance and uptime threshold, weighted by the inverse square of price
Lowest pricesort: "price" or the :price model suffixThe least expensive provider for the selected model
Lowest latencysort: "latency"The fastest responding provider
Highest throughputsort: "throughput" or the :throughput model suffixThe provider with the highest tokens-per-minute output

When should you pin a model instead of routing automatically?

Pin a model when you need the same model on every request, for example when outputs must be reproducible, when a prompt has been tuned and evaluated against one model, or when a policy names an approved model. Use automatic selection when the right model depends on the request.

  • Automatic selection suits mixed workloads where simple and complex prompts arrive at the same endpoint.
  • A pinned model suits evaluated, regulated or regression-tested workloads.
  • The two can be combined: pin the model and still route between the providers that serve it.
FAQ

Common questions

Set the model field of your chat completions request to fastrouter/auto instead of a specific model ID. FastRouter then delegates model selection to its routing engine. No other configuration is required, and you can still send a specific model ID whenever you need a fixed model.

Yes. Call the model selection endpoint at /api/v1/model/selection with model set to fastrouter/auto and your messages. It returns the recommended selected_model, the top_candidates considered, the assigned_tags for the prompt and the selection_strategy, without making the actual completion request.

It applies its default provider strategy. FastRouter gives higher priority to models and providers that meet a performance and uptime threshold and weights them by the inverse square of their price. The aim is to select cost-effective options without compromising reliability, with no configuration required.

Yes. In the provider object, only restricts the request to a set of providers and ignore excludes listed providers regardless of ordering or sorting. order sets an exact sequence of provider slugs to attempt, and require_parameters set to true limits routing to providers that support every parameter in the request.

You can list fallback models on the same request. The primary goes in the model field and backups go in the models array. FastRouter tries them in order when a model is unavailable or returns an error, and the model field of the response reports which one answered. Billing follows the model that processed the request.

Try it on your own traffic

Point your existing OpenAI-compatible client at FastRouter and send a request. Free to start, no credit card required.