Use cases
Routing rules are most useful when traffic needs to be redirected or distributed at the gateway level based on request attributes, without modifying any calling application.Swap the model for a support bot without changing any code
Swap the model for a support bot without changing any code
Send simple and complex documents to different models
Send simple and complex documents to different models
Keep file attachment requests on models that support them
Keep file attachment requests on models that support them
Automatically reroute traffic when a provider goes down
Automatically reroute traffic when a provider goes down
Spread load evenly across multiple endpoints for the same model
Spread load evenly across multiple endpoints for the same model
How routing rules work
When a request arrives at the AI Gateway, the AI Gateway evaluates all active routing rules in ascending priority order. The first rule whose CEL expression matches the request determines the target model. If no rule matches, the model from the original request payload is used. Example: A request arrives withmodel: "openai/gpt-5.6-sol". A routing rule with condition model.contains("gpt-5.6-sol") and target openai/gpt-5.4-mini is the highest-priority matching rule. The AI Gateway redirects the request to gpt-5.4-mini, regardless of what the caller specified. In CEL expressions, model refers to the model value from the request payload.
See also: Request-level load balancing
load_balancer parameter directly in your API calls.Visibility
- Global rules: visible to workspace administrators only.
- Project rules: visible to all members of the scoped project.
Creating a routing rule
From the Routing Rules list, click Add New Rule. A panel opens on the right with the following fields.
The top of the Create Routing Rule form with the General fields, a Latency strategy under Load Balancer, and the Cache section.

The bottom of the Create Routing Rule form with the Plugins and Conditions sections.
General
Providers and traffic weight
Optional. Defines the target model or models to route matching requests to. Leave this section empty to build a rule that exists only to apply a plugin or a cache to matched traffic, with no model routing at all. Models sets the distribution strategy for the target:- Fallback: Route to the primary model. If it fails, try the next in the list.
- Latency: Route to the model with the lowest recently observed latency. See Latency-based routing for the full selection algorithm.
- Weighted: Split traffic across models by percentage weights.
- Round Robin: Rotate evenly across all configured models.
Cache
Optional. Give the rule its own response cache for matching requests. Exact-match requests reuse a cached response instead of hitting a model. Leaving this section disabled adds no cache of its own, so matched requests keep using their request-levelcache setting.
Set Enable cache to turn the cache on, then choose Time to live to control how long matching responses stay cached, from 5 minutes up to 3 days. The default is 1 hour.
When a rule has cache enabled, a matching request uses the rule’s cache configuration instead of the request’s own cache parameter; the two are not merged. See LLM response caching for how caching works.
Plugins
Optional. Attach plugins that run on traffic matching this rule. Plugins can transform the request, the response, or stored traces. Click Add Plugin to attach one of the following:Priority
A numeric value that sets the evaluation order for this rule. Rules are evaluated in ascending order: priority0 is evaluated before priority 10. The first matching rule wins.
Rule Builder
The Rule Builder constructs the CEL expression that determines whether this rule applies to a given request. Conditions are built from values present in the request headers and body. Clicking Add opens a dropdown with the following condition types:and. Groups themselves can be joined with either and or or. Select the operator between groups to control how they combine. Each condition can be removed with .
The generated CEL expression is shown read-only in the CEL Expression Preview below the builder.