Skip to content

Routing rules

Routing rules let you redirect incoming requests to specific providers and models based on attributes of the request. The gateway evaluates rules in descending priority order. The first rule whose conditions all match is applied — evaluation stops there. If no rule matches, the gateway uses the provider and model from the original request.

How evaluation works

  • Rules are evaluated in descending priority order — a higher number means higher priority, and is evaluated first.
  • First match wins: evaluation stops at the first rule whose conditions all match.
  • All conditions within a single rule are combined with a logical AND.
  • If no rule matches, the gateway forwards the request using the provider and model specified in the original request.

💡 Note: Priority is a whole number from 0 to 1000000; an empty field means 0. Text that is not a whole number in range (for example 1e or 1.5) is refused with a message and the rule is not saved — it is never turned into a default.

💡 Note: Priority values do not need to be contiguous. Using increments of 10 (10, 20, 30 …) leaves room to insert rules between existing ones without renumbering.

Condition fields

Field Matches against
model The model field in the request body
provider The provider name resolved for this gateway. For a model id several configured providers offer, this is the provider the gateway's EU residency and provider allowlist permit, if one is and the usual pick is not refused for a policy reason (sub-processor objection, disabled local model, EU-Gov add-on) — otherwise the usual pick (see Catalogue placement)
tenant_id The tenant's UUID (shown as Tenant ID on the organisation's Overview tab), not the tenant slug used in the request URL
header:{name} The value of HTTP header {name} (e.g. header:x-customer-tier)
meta:{key} The value of x-aig-meta-{key} header (e.g. meta:region)

Operators

Operator Description
eq Exact equality match
neq Not equal
prefix Value starts with the specified string
contains Value contains the specified string
regex Value matches the specified Lua pattern. This is not PCRE/standard regex — use %d/%w (not \d/\w), character classes with %, and note there is no | alternation. An invalid pattern fails the condition (and is logged), never matches everything.

A condition without op uses eq. An unknown operator never matches. A condition whose field is absent from the request (for example a header that was not sent) does not match eq, prefix, contains or regex, but it matches neq. A malformed condition (not an object, or a field that is not a string) never matches.

Actions

Field Type Description
provider string Route the request to this provider.
model string Replace the model name with this value when forwarding.
fallbacks array Ordered list of {provider, model} objects to try if the primary fails.
load_balance object Distribute matching requests across several weighted targets. See Load balancing.
timeout_ms integer Per-rule upstream timeout (ms) for the leg this rule routes, replacing the built-in stall budgets; a shorter platform cap (for example the tool-loop synthesis step) still applies. Positive integer, max 3600000; a legacy stored value outside that is treated as omitted. If omitted (or treated as omitted), see Gateways → Timeouts for what bounds the request. The rule dialog has no field for it; it is kept when you save the rule in the dialog, but a rule with a legacy invalid value must be fixed through the API. On a Myra-hosted model, when a rule value below 180000 is the deadline that fires, that timeout is your own budget and is not counted against the Myra circuit breakers (Circuit breaker). See the Routing rules API.

💡 Note: Anywhere a target takes a model, the model@provider shorthand sets both in one string — e.g. "model": "gpt-4o@openai" is equivalent to {"provider": "openai", "model": "gpt-4o"}.

Creating a routing rule

Before you begin, ensure the following conditions are met:

  • ☑ You have admin access.
  • ☑ A gateway exists.

Screenshot: Routing rules tab with New Rule button The routing rules list on the Models & routing tab of the gateway page.

Proceed as follows to create a routing rule:

  1. Open Organisation › AI setup › Gateways.
    • The gateway list opens.
  2. Click on the gateway you want to configure.
    • The gateway page opens.
  3. Open the Models & routing tab and locate the Routing Rules card.
    • The card is collapsed on first load; only its header is visible.
  4. Click on the expand control in the Routing Rules card header.
    • The rule list opens, showing all rules in priority order.
  5. Click on the New Rule button.
    • The New rule page opens (…/rules/new).

Screenshot: Routing rule page with conditions and actions filled in The routing rule page.

  1. Enter a value in the Priority text field (use increments of 10 to leave room for future insertions).
    • The priority value is set.
  2. Click on the Add button to add one or more conditions.
    • A condition row appears.
  3. Select the field from the Field drop-down list.
    • The field is set.
    • The Field drop-down list offers model, provider, tenant_id, header, and meta.
  4. If you select header or meta, enter the header name or the metadata key in the name text field that appears beside the Field drop-down list.
    • The composed condition field reads header:<name> or meta:<key>.
  5. Select the operator from the Operator drop-down list.
    • The operator is set.
  6. Enter the match value in the Value text field.
    • The condition is complete.
  7. Select the target provider from the Provider drop-down list in the Actions section.
    • The provider is set.
  8. If required, select a model from the Model drop-down list to rewrite the model name when forwarding.
    • The model rewrite is set.
    • The list offers a model only after a provider is chosen, and then only the models that provider serves. Without a provider the list holds only Any model and a hint asks you to choose a provider first. The same applies to every load-balance target: choose its provider first. A fallback left on Any provider uses the rule's provider, so its list offers that provider's models. Changing the provider clears a model the new provider does not serve.
  9. Toggle the Enabled toggle on.
    • The rule is marked active.
  10. Click on the Create Rule button.

-> The routing rule is created and appears in the rule list in priority order.

Saving a rule whose model the provider cannot serve

The server also checks the pair on save. If the provider cannot serve the model (for example a model id that belongs to a different provider, a Myra model id that is not in the model catalog, or a retired id with no successor), the save is refused with model_not_servable and the dialog shows a message naming the model and provider; nothing is stored. If the model catalog cannot be read at that moment, the dialog asks you to try again. A disabled rule is not checked, so you can always disable or delete a rule. Enabling a disabled rule checks it with its stored values.

If an older rule already holds a pair the provider cannot serve, every request it matches fails with model_not_found and a message that names the model and provider. Disable or edit the rule; the change takes effect within 30 seconds.

Editing a routing rule

Proceed as follows to edit a routing rule:

  1. Open Organisation › AI setup › Gateways.
    • The gateway list opens.
  2. Click on the gateway that contains the rule.
    • The gateway page opens.
  3. Open the Models & routing tab and locate the Routing Rules card.
    • The card is collapsed on first load; only its header is visible.
  4. Click on the expand control in the Routing Rules card header.
    • The rule list opens.
  5. In the row of the rule you want to edit, click on Edit in the row actions.
    • The rule's edit page opens with the current values (…/rules/<rule>/edit).
  6. Edit the required fields.
    • The fields are updated.
  7. Click on the Save Rule button.

-> The routing rule is updated with the new values.

To change the evaluation order without editing a rule, use Move up (evaluate earlier) or Move down (evaluate later) in the rule's row actions.

Deleting a routing rule

Proceed as follows to delete a routing rule:

  1. Open Organisation › AI setup › Gateways.
    • The gateway list opens.
  2. Click on the gateway that contains the rule.
    • The gateway page opens.
  3. Open the Models & routing tab and locate the Routing Rules card.
    • The card is collapsed on first load; only its header is visible.
  4. Click on the expand control in the Routing Rules card header.
    • The rule list opens.
  5. In the row of the rule you want to delete, click on Del in the row actions.
    • A confirmation dialogue appears: "Delete this routing rule?"
  6. Click on the Confirm button.

-> The routing rule is deleted and removed from the rule list.

Common patterns

Route by model prefix

Send all gpt-* requests to OpenAI and all claude-* requests to Anthropic:

[
  {
    "priority": 10,
    "conditions": [{"field": "model", "op": "prefix", "value": "gpt-"}],
    "actions": {"provider": "openai", "model": "gpt-4o"},
    "enabled": true
  },
  {
    "priority": 20,
    "conditions": [{"field": "model", "op": "prefix", "value": "claude-"}],
    "actions": {"provider": "anthropic", "model": "claude-sonnet-4-6"},
    "enabled": true
  }
]

Route by tenant

Send a specific tenant's traffic to a dedicated provider account:

{
  "priority": 5,
  "conditions": [{"field": "tenant_id", "op": "eq", "value": "<tenant-uuid>"}],
  "actions": {
    "provider": "openai",
    "model": "gpt-4o"
  },
  "enabled": true
}

Route by custom header

Use a customer tier header to select a model:

{
  "priority": 15,
  "conditions": [
    {"field": "header:x-customer-tier", "op": "eq", "value": "premium"}
  ],
  "actions": {
    "provider": "openai",
    "model": "gpt-4o"
  },
  "enabled": true
}

Route by metadata

Route requests tagged with a region metadata header:

{
  "priority": 20,
  "conditions": [
    {"field": "meta:region", "op": "eq", "value": "eu"}
  ],
  "actions": {
    "provider": "azure",
    "model": "gpt-4o"
  },
  "enabled": true
}

Attach the metadata with x-aig-meta-region: eu on the inference request.

API

Routing rules are fully manageable via the Admin API. See Routing Rules API for endpoint reference and request/response examples.

See also