---
title: AI Gateway Routing Rules
description: Define team-wide rules that rewrite requests from one model to another or deny specific models in AI Gateway.
url: "https://vercel.com/docs/ai-gateway/models-and-providers/routing-rules"
last_updated: 2026-09-17
related:
  - /docs/cli/ai-gateway
  - /docs/ai-gateway/models-and-providers/virtual-models
  - /docs/ai-gateway/models-and-providers/model-fallbacks
  - /docs/ai-gateway/models-and-providers/provider-options
  - /docs/ai-gateway
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# AI Gateway Routing Rules

Routing rules let you control how AI Gateway handles your team's requests at the model level. You define team-wide rules that either rewrite a request from one model to another, or deny a model so requests for it are blocked. Rules apply to every request made with your team's AI Gateway credentials, so you can change routing behavior without editing application code.

## How routing rules work

Each rule has a type and matches requests by model:

- **Rewrite**: AI Gateway serves requests for the source model with a destination model instead. Use this to standardize on a model, roll out a replacement, or route an expensive model to a cheaper one.
- **Deny**: AI Gateway blocks requests for the matched model. Use this to stop your team from using a model you have not approved.

Each rule is scoped to a single team. You can attach an optional reason to a rule, which AI Gateway surfaces when the rule applies, and a description to document why the rule exists.

## Manage rules with the CLI

You manage routing rules with the [`vercel ai-gateway rules`](/docs/cli/ai-gateway#rules) command. Target a team with the global `--scope` flag, or use your currently selected team. Every subcommand supports `--json` for scripting.

```bash filename="terminal"
vercel ai-gateway rules list --scope your-team
```

## Rewrite a model

Create a rewrite rule with a source model (`--source`) and a destination model (`--destination`):

```bash filename="terminal"
vercel ai-gateway rules add --type rewrite --source anthropic/claude-opus-5 --destination anthropic/claude-haiku-4.5
```

Once the rule is active, AI Gateway serves any request for `anthropic/claude-opus-5` with `anthropic/claude-haiku-4.5`. Your application keeps requesting the source model and AI Gateway substitutes the destination.

## Deny a model

Create a deny rule with the model to block:

```bash filename="terminal"
vercel ai-gateway rules add --type deny --source openai/gpt-6-astra
```

A request for a denied model returns a `403`:

```json
{
  "error": {
    "message": "Request denied by a routing rule.",
    "param": { "ruleId": "rule_123" },
    "type": "forbidden"
  }
}
```

## Edit or disable a rule

Update a rule by its ID. You can change the destination, reason, or description, or toggle the rule on and off:

```bash filename="terminal"
vercel ai-gateway rules update rule_123 --destination anthropic/claude-sonnet-5
```

```bash filename="terminal"
vercel ai-gateway rules update rule_123 --no-enable
```

A disabled rule stays in your configuration but stops applying to requests. To include disabled rules in the list, pass `--include-disabled`.

## Remove a rule

Delete a rule by its ID:

```bash filename="terminal"
vercel ai-gateway rules remove rule_123
```

## How rules apply

Routing rules apply to every request made with your team's AI Gateway credentials. Rule changes can take a short time to propagate. In-flight requests finish under the previous configuration, and new requests respect the updated rules once the change has propagated.

### Virtual models

A deny rule also prevents the matched model from executing through a [virtual model](/docs/ai-gateway/models-and-providers/virtual-models).

Rewrites apply before virtual model resolution, so a rewrite can send direct callers to a virtual model:

```bash filename="terminal"
vercel ai-gateway rules add --type rewrite --source openai/gpt-6-astra --destination vmc/abc-123
```

The destination virtual model must be active: a missing or archived one is rejected with a `400`. AI Gateway does not apply rewrites again to the model inside the virtual model, so rewriting a model to a virtual model that points back at it does not loop.

For example, if `vmc/abc-123` points at `openai/gpt-6-astra`, that rewrite sends callers through the virtual model's configuration. A deny on `openai/gpt-6-astra` would also block its use through `vmc/abc-123`. Use the rewrite without the deny when you want callers to use the virtual model.

### Model fallbacks

Each [fallback](/docs/ai-gateway/models-and-providers/model-fallbacks) selection goes through routing rules before AI Gateway tries it. Rewrites change the fallback destination. Deny rules prevent the matched fallback from executing, including when a virtual model resolves to it.

AI Gateway skips denied fallback candidates and can continue to another allowed model. If every candidate is denied, the request returns `403`. If a deny matches the model you request directly, AI Gateway skips that model and tries your configured fallbacks. Without fallbacks, the request returns `403`. A deny that matches only the model behind a requested virtual model skips that attempt and continues to the next fallback.

When an allowed model reaches a provider and fails, and every remaining candidate is denied, the request returns that failure. A candidate that never reaches a provider, for example when no provider matches its `only` filter, leaves the deny as the most specific result, so the request returns `403`.

A fallback rewrite can itself point at a model that another rule rewrites. A chain that cycles back to an earlier model, or exceeds ten rewrites, is a configuration error. On the model you request, it fails the request with a `400`. On a fallback, it skips that candidate the way a deny does, so an earlier failure or a later allowed candidate decides the response.

## Provider options

A rule only changes which model serves a request. Everything else you send is preserved and applied to the destination model, including [`providerOptions`](/docs/ai-gateway/models-and-providers/provider-options), the `only` filter, fallbacks, and BYOK.

One caveat: `providerOptions` are namespaced per provider and are not translated across providers. If a rewrite routes to a different provider, options for the original provider no longer apply (for example, `providerOptions.anthropic` has no effect on an `openai` destination). Keep rewrites within the same provider, or set the destination provider's options.

## Permissions

Routing rules are managed per team, so your access depends on your role in the team that owns the rules:

- **Owners** and **Members** can create, edit, and remove rules.
- **Developers** can view rules but not change them.
- Other roles have no access to routing rules.

## Related

- [`vercel ai-gateway rules` CLI reference](/docs/cli/ai-gateway#rules)
- [AI Gateway overview](/docs/ai-gateway)
- [Provider allowlist](/docs/ai-gateway/security-and-compliance/provider-allowlist)

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
