Skip to content
AI GatewayAI Gateway Manual

Project routing

Configure a project's routing rules, conditions, and priorities, and manage default behavior for requests that match no rule.

Project routing lets a project choose the Provider and model that process a request. A policy can change the actual destination while keeping the model name requested by an app, reducing the need to update each app’s settings when destinations change. For example, it can select different destinations based on the requested model name or budget usage.

Select a project under Organization → Projects in the admin console.

Rule-based routing after selecting a project. Callout 1 marks the current Platform project, 2 marks Project settings, and 3 marks Rule-based under Routing

  1. Check the current project in the project selector (1) at the top. This example shows the Platform project.
  2. Click Project settings (2) in the top navigation.
  3. Click Rule-based (3) under Routing on the left to open Rule-based routing.

Managing the policy requires the organization administrator (org-admin) role or the project administrator (project-admin) role for that project.

Register the Provider and model you want to use, and check that the Provider is visible to the project. See Provider project visibility and Allow models in projects for these settings. Selecting a routing destination does not grant model access, so the requester must also be allowed to use the model.

Without a saved routing policy, requests select a destination by splitting the requested provider/model at the first slash. The part before it identifies the Provider, and the remainder is the model ID. A model name without a Provider cannot be resolved. Save default behavior before adding routing rules.

Routing page without a policy, with callout 1 marking Set up default behavior

  1. Click Set up default behavior (1) to open the form.
  2. Choose the behavior for When no rule matches. If you choose Specified destination, select a Provider and model as well.
  3. Click Save default to save the policy and default behavior.

Default behavior form with callout 1 marking Specified destination, 2 marking the OpenAI Provider, and 3 marking the GPT-5 model

The Specified destination (1), Provider (2), and Model (3) above are example settings. Replace OpenAI and GPT-5 with a registered destination available to your project.

Default behavior applies only when no active rule matches. The available choices are:

BehaviorHandling of requests that match no rule
Specified destinationUses the selected Provider and model regardless of the requested model name.
Requested Provider ModelSplits the requested provider/model at the first slash. The entire remainder is the model ID, including any additional slashes. Returns an HTTP 404 model-not-found error if the Provider is missing.
Reject unmatched requestsReturns an HTTP 404 model-not-found error for unmatched requests, including those in provider/model format.

For this HTTP 404 error, OpenAI-compatible APIs return NOT_FOUND, while the Anthropic Messages API returns error.type: not_found_error.

If access to the selected destination is denied or its call fails, routing does not switch to a later rule or the default destination.

Click Edit default in the Default row of the Rule-based routing list. Change the behavior in the form and click Save default to save it.

After saving default behavior, click Add rule to open the rule panel on the right. Each rule defines its conditions and a direct destination.

  1. Enter an integer in Priority that no other rule uses. Both active and inactive rules must have unique values.
  2. Select a field and operator in Rule Builder, then enter a value. Click Add condition to add another comparison.
  3. For multiple conditions, select AND or OR under Group operator.
  4. Select the Provider and Model under Direct Target.
  5. Set Rule status to active or inactive, then click Save rule. A successful save returns you to the list.

Priority 10 and AND conditions in the rule form, with callout 1 marking the model field, 2 marking the support value, and 3 marking read-only CEL

This image shows the priority and condition inputs. Selecting field model (1), operator ==, and value support (2) displays (model == "support") in Condition (3). The Provider and model selectors are outside this image.

A policy can have at most 15 active rules. If 15 are already active, save the new rule as inactive or deactivate another rule first. The server performs final validation of priorities, conditions, and destinations. If saving displays an error, check the corresponding values.

Conditions compare request values before destination selection. model and provider do not refer to the model and Provider selected by routing.

FieldValue to compareExample use
modelThe complete model value in the request. If it includes a Provider, such as openai/gpt-5, the entire string is compared.Check whether it equals the alias support.
providerThe name before the first slash in the requested model. It is populated only for a registered Provider name; otherwise it is an empty string.Check whether the request specifies a particular Provider.
request_typeThe request type determined by the API and whether streaming is enabled.Select streaming requests only.
headersThe string value of the request header specified by Header key. Keys are case-insensitive.Check whether x-team equals support.
budget_usedThe percentage of the project budget used by committed costs. Uses the highest percentage across configured periods, or 0 if no budget is active. Excludes the current request’s unsettled cost.Check whether budget usage meets or exceeds a threshold.

Conditions cannot use the authentication headers Authorization, Proxy-Authorization, X-API-Key, API-Key, Cookie, or Set-Cookie. If condition evaluation fails, for example when comparing a missing header, routing skips that rule and evaluates the next active rule.

The available operators depend on the field. For in, use Add value to list the values to compare.

Field typeOperatorsComparison
String: model, provider, request_type, headers==, !=, inEquality, inequality, or membership in a list.
StringstartsWith, endsWith, contains, matchesPrefix, suffix, substring, or regular expression.
Number: budget_used==, !=, in, <, <=, >, >=Equality, list membership, or numeric comparison. Enter finite numbers.

The rule builder offers the following six values for request_type with the ==, !=, and in operators. The request’s stream value determines whether it is a streaming request.

APINon-streaming requestStreaming request
POST /v1/chat/completionschat_completionchat_completion_streaming
POST /v1/responsesresponsesresponses_streaming
POST /anthropic/v1/messagesanthropic_messagesanthropic_messages_streaming

The policy also applies to the following non-streaming requests. These two request types are currently absent from the builder’s value lists for the operators above.

APIRequest type
POST /v1/embeddingsembeddings
POST /v1/images/generationsimages_generations

Rules without conditions and default behavior also affect embedding and image-generation requests. Check that the selected destination supports the request.

Access control and routing policies also apply to token counting. POST /anthropic/v1/messages/count_tokens is evaluated as anthropic_messages, and POST /v1/responses/input_tokens as responses. Each uses the destination that a non-streaming request to the corresponding entry point would select. These calls do not consume the project’s request-rate limit. They also skip usage-limit admission and token/cost settlement.

GET /v1/models lists allowed provider/model references without adding routing aliases. This policy does not apply to MCP requests.

AND matches when all comparisons are true; OR matches when at least one is true. The builder supports a single level of AND or OR. It cannot create subgroups, mix AND and OR, or negate an entire group. You can use != to compare individual values.

The CEL shown in Condition is always read-only. Only completed builder conditions appear in the preview, so complete every row’s field, operator, and values before saving. An incomplete row prevents saving even if a preview is visible.

If the builder cannot represent previously saved CEL, it displays the original text as read-only. You can still edit priority, destination, and status; saving preserves the original condition text. The server checks that the CEL is valid and evaluates to a boolean.

Active rules are evaluated in ascending numeric priority, and the first matching rule selects the destination. Inactive rules are skipped. Labels such as ‘Rule 1’ and ‘Rule 2’ do not determine evaluation order.

A rule with no conditions matches every request covered by the policy. If it is active, requests never reach rules with larger priority numbers or default behavior, so check its position. Default behavior applies only when no active rule matches.

After destination selection, requests undergo checks for model access, Provider availability, request support, and any budget and usage limits that apply to the operation. A denial at this stage or a failed Provider call does not select another destination from a later rule or default behavior.

Click a rule row’s Edit icon to open its form. Update the priority, condition, direct destination, or status, then click Save rule. After a successful save, the list shows the updated values.

Rule list with callout 1 marking Edit for Rule 2, 2 marking its inactive status switch, and 3 marking the Default row's read-only active switch

Above, Rule 2 has priority 10 and is inactive. Use Edit (1) to change it or the Status switch (2) to reactivate it. Only Rule 1, with priority 20, is active, so the page shows Active 1 / 15.

Clicking a status switch immediately requests a save, with no separate save button or confirmation dialog. A successful save updates the active/inactive label and active-rule count. The Default row’s status (3) is read-only and always appears active. Its switch cannot deactivate it.

To delete one rule, click its row’s Delete icon. Review the target in Delete routing rule?, then click Delete to remove the rule from the list. Click Cancel to keep it.

Deleting the last rule retains the policy and default behavior. All requests covered by the policy then use default behavior.

To remove the entire policy, select Delete policy from the menu at the top of the list. Click Delete policy in Delete routing policy? to delete all rules and default behavior together. Click Cancel to keep the policy.

Delete routing policy confirmation explaining that all rules and the default will be deleted, with Cancel and Delete policy buttons

After successful policy deletion, the initial default setup page appears. Subsequent requests select destinations by directly resolving provider/model; model names without a Provider cannot be resolved.

Each example uses an independent policy with no other active rules. Set the shared default behavior to Specified destination, Provider openai, and model gpt-5. Each example rule is active, with priority 10 and direct destination openai/gpt-5-mini. These two destinations make the results distinguishable. For your configuration, substitute different models that are registered, visible to the project, allowed for the requester, and support the request. The example names do not guarantee pricing or availability.

For the OpenAI-compatible Chat Completions API, with only this default and no rules, even a request with model set to support selects openai/gpt-5. If you change the default to Requested Provider Model, a request for openai/gpt-5 selects that destination, but the Providerless alias support returns NOT_FOUND. Reject unmatched requests returns NOT_FOUND for both requests.

The CEL below is the read-only value shown in Condition after completing the builder inputs. A request that does not match the example rule selects the shared default destination, openai/gpt-5. If access to the selected destination is denied or its call fails, routing does not select another rule or the default destination.

Set Group operator to AND and enter these two conditions.

FieldOperatorValue
model==support
request_type==chat_completion_streaming

Displayed condition: (model == "support" && request_type == "chat_completion_streaming")

A POST /v1/chat/completions request with model: "support" and stream: true matches both conditions and selects openai/gpt-5-mini. The same model with stream: false has request type chat_completion and selects the default destination. model is the original requested value; the API and streaming setting determine request_type.

Set Group operator to OR and enter these two conditions.

FieldHeader keyOperatorValue
modelNot applicable==support
headersx-team==support

Displayed condition: (model == "support" || headers["x-team"] == "support")

A request with model: "support" and HTTP header x-team: other selects openai/gpt-5-mini because the first condition is true. With model: "openai/gpt-5" and x-team: other, both conditions are false and the default destination is selected. A different model can also match the second condition with header x-team: support. Headers are not arbitrary fields in the request body. A missing header can cause a comparison error, and authentication headers are unavailable to conditions.

In Rule Builder, enter budget_used, operator >=, and value 80.

Displayed condition: (budget_used >= 80.0)

At server-calculated usage of 80%, the request selects openai/gpt-5-mini; at 79%, it selects the default destination. Usage is the highest committed estimated-cost percentage across active budget periods, or 0.0 if no budget is active. It excludes the current request’s unsettled cost. See Model pricing and budgets for budget settings. Selecting a destination with this condition does not bypass budget or usage-limit checks.

After saving the policy, send a representative request with a Gateway Key issued for the project and check its model log. See Gateway Keys to prepare a key. Organization administrators (org-admin) and project administrators (project-admin) for that project can also read model logs. Users with audit-viewer at the organization or project scope can read them as well.

  1. With only the Model and request type: AND example active, send a request to AI Gateway’s POST /v1/chat/completions. Authenticate with the Gateway Key and include model: "support", stream: true, and the messages required by the API. These inputs match the example rule and select openai/gpt-5-mini. The actual call result depends on destination availability, access permissions, and other checks.
  2. In the admin console, open the project’s Activity → Model Logs, find the request, and open its log details.
  3. Check Requested model, Resolved model, Outcome, Provider error message, and Request ID. The requested model is support; if selection was recorded, the resolved model is openai/gpt-5-mini from the example. For a failure, inspect the outcome and error message, and record the request ID to investigate.

The list combines requested and resolved models when they are identical. Identical values alone do not establish that no rule matched. Some values may be absent in older logs or denied requests. Logs do not show which rule matched or the evaluation sequence, so also check the policy’s conditions and priorities.

SymptomChecks and action
The condition cannot be saved.Complete every builder row’s field, operator, and values, then correct the displayed errors. CEL in Condition cannot be entered or edited directly. Existing CEL outside builder support remains read-only; the server checks that it is a valid boolean condition.
Priorities conflict or the active-rule limit is reached.Use an integer that no other rule uses, including inactive rules. A policy supports at most 15 active rules, excluding the Default row. Deactivate another rule or save the new rule as inactive.
Routing settings or model logs are inaccessible.Routing management requires the org-admin role or the project-admin role for that project. These roles can also read model logs, as can audit-viewer at the organization or project scope. Ask an administrator for the required role binding.
Destinations fail to load or none are available.Check Provider and model registration and project visibility, then retry. Direct-destination rules and the Specified destination default need an available destination. For default behavior, you can also choose Requested Provider Model or Reject unmatched requests as appropriate.
The policy cannot be loaded or saved.A read failure does not mean the policy is absent. Check connectivity and permissions, then retry. A failed save retains form input. If a conflict appears, click Reload policy and review the current policy and retained input. Saving can overwrite another editor’s changes.
The selected destination is unavailable, hidden, disallowed, or does not support the request.Check Provider status and project visibility, the requester’s model access, and the destination’s request support. Routing does not automatically switch to another rule or the default destination.
Budget or usage limits deny the request, or the Provider call fails.Check the outcome, error message, and request ID in the log details. Review budget settings in Model pricing and budgets and check Provider status. A failed destination does not cause routing to select another rule or the default destination.