How can an AI gateway automatically route requests across models?
Summary
- An AI gateway routes requests across models automatically by putting a named service in front of several model destinations and applying rules on every request: weighted splits, ordered fallbacks and session pinning.
- Fallbacks catch failures such as rate-limit or server errors and retry against backup destinations in a fixed order, so applications keep working when one provider has trouble.
- Task-aware routing goes further: a classifier reads the task and picks the lowest-cost model that can handle it, ideally per task rather than per turn so prompt caching still pays off.
- Automatic routing still has to respect governance. The caller must be allowed to use each destination, and rate limits and budgets apply on top.
- On Databricks, Unity Gateway model services handle splits and fallbacks across Databricks-hosted and external models, and Smart Routing (Beta) does task-aware selection for supported coding agents.
How can an AI gateway automatically route requests across models?
An AI gateway routes requests automatically by giving applications one stable endpoint and deciding, request by request, which model behind it should answer. The decision comes from rules you configure, such as splitting traffic by weight, retrying on errors and keeping a session on one model, or from a router that classifies the task and chooses a capable, lower-cost model. The application never changes. It calls the same name while the platform team adjusts the destinations underneath.
How automatic routing works
Each request goes through the same steps:
- Resolve the service. The client calls a named service, not a specific model.
- Check access. The gateway confirms the caller may use the service and applies rate limits.
- Pick a destination. Weighted rules, session affinity or a task classifier selects a model.
- Call and watch. If the destination fails, the gateway moves down an ordered fallback list.
- Record. Usage, latency and the destination used are logged for later analysis.
Routing mechanisms
| Mechanism | Trigger | What the gateway does |
|---|---|---|
| Weighted split | Every request | Sends it to a destination at random, weighted by configured percentages |
| Session affinity | A session-identifying header | Pins the conversation to one destination |
| Ordered fallback | An error such as a 429 or 5xx | Retries the request against backups in priority order |
| Task-aware routing | A new task or subagent | Classifies the task and selects a capable, lower-cost model |
| Rate limiting | Per-user, group or service thresholds | Returns HTTP 429 once a limit is exceeded |
Two design points matter in practice. Weighted routing converges on your configured shares over time, not within every handful of requests. And switching models in the middle of a conversation can waste prompt caching: a Databricks blog post on Smart Routing explains that "at scale, costs are dominated by cache hit rate," which is why that router works per task.
How Databricks approaches automatic model routing
Unity Gateway, the generally available governance layer built on Unity Catalog, routes through model services.
One name, many models. A model service is "an endpoint that translates and routes inference requests to one or more models". Destinations can be Databricks-served models, on pay-per-token or provisioned throughput, or external models through a model provider, and "You can mix these destinations in one service." Callers invoke it by catalog.schema.name for real-time requests, or through ai_query for batch inference.
Splits, affinity and fallbacks. Traffic splitting "distributes requests across multiple model backends behind a single model service", with a traffic percentage per destination and "a maximum of 5 destinations". Session affinity is automatic for requests with a session header. Fallbacks retry a failed request against backup destinations "in a priority order you define". They work independently of splitting, and you can't configure traffic splitting on fallback destinations. Everything is configurable through the UI, REST API, Databricks SDKs, CLI or Terraform.
Task-aware routing (Beta). Smart Routing "selects the lowest-cost model capable of handling your task" for supported coding agents launched with the ug CLI.
- An account admin enables the Enhanced Unity Gateway preview first. Users can toggle routing per launch with
--enable-smart-routingor--disable-smart-routing. - It needs
EXECUTEon every candidate model and chooses only amongsystem.aimodel services. - The main session stays on its default model, and subagents are routed independently.
Governed routing. Rate limits and budgets apply to routed traffic, and system.ai_gateway.usage records the requester, tokens and latency for every request (usage tracking).
Use cases
- Model rollout: send a small share of traffic to a new model, watch usage and quality, then raise its percentage.
- Provider resilience: keep an external model as primary with a Databricks-hosted fallback, or the reverse.
- Agent cost control: let subagents on routine work run on lower-cost models while the main session keeps its default.
FAQs
Does the application need to know which model answered?
No. It calls the service name, and the gateway's usage records show which destination served each request.
What triggers a fallback?
On Databricks, a failed request, for example a 429 or 5xx error, is retried against fallback destinations in the exact order you set.
Can I route between a hosted model and an external provider?
Yes. A Unity Gateway model service can mix Databricks-served and external destinations in one service.
Does task-aware routing work for every application?
No. Smart Routing is in Beta and works with supported coding agents. Use splits and fallbacks for other workloads.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.