Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.
Routing Rules are -based conditions that intercept requests to the AI Gateway and redirect them to a different model when matched.
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
Intercepts support bot requests addressed to one model and silently redirects them to a cheaper one, so the calling application needs no changes to benefit from the cost saving.
Send simple and complex documents to different models
Two rules at the same priority split document traffic by complexity: simple documents go to a lighter model, complex ones go to a more capable model, all based on metadata attached to each request.
Keep file attachment requests on models that support them
Matches requests that include a file attachment and routes them through an ordered list of models that all support native file input, so the request succeeds even if the first model is unavailable.
Automatically reroute traffic when a provider goes down
A low-priority catch-all rule that redirects traffic to an alternative set of models whenever primary providers are unavailable, keeping requests flowing without manual intervention.
Spread load evenly across multiple endpoints for the same model
Distributes requests in round-robin mode across multiple endpoints serving the same model, balancing inference load across providers without any changes required on the caller side.
How routing rules work
When a request arrives at the AI Gateway, every active rule whose CEL expression matches is a candidate. The winner is chosen in two steps:
Scope. Workspace-global rules outrank project-scoped rules. When any global rule matches, the winner comes from those whatever its priority, and project-scoped rules are considered only when no global rule matches.
Priority. Within the winning scope, the lowest priority number wins, and the rule created first breaks a tie.
The winning rule supplies the target model it configures, its plugins, and its cache. The plugins and cache of the other matching rules never run, and a request that matches no rule keeps the model from its payload.
See also: Request-level load balancing
To distribute traffic across providers at the request level without organization-wide rules, use the load_balancer parameter directly in your API calls.
Creating a routing rule
From the Routing Rules list, click Routing Rule. The form opens as a full page with a back control and an unsaved-changes confirmation. It carries five sections, and the submit button reads Create Rule, or Save Changes once the rule exists.
Routing rules are visible to workspace administrators only.
AI Studio
API & SDK
CLI
Fill the five sections, then click Create Rule. The sections are described below the tabs.
The top of the Create Routing Rule form: the General fields and the Fallback load balancer with one target model.
The bottom of the Create Routing Rule form: the Plugins section and the Rule Builder with its generated CEL expression.
Create a routing rule with a Management Key that carries Write access to the Routing rules capability.
import { Orq } from '@orq-ai/node';const client = new Orq({ apiKey: process.env.ORQ_API_KEY });const rule = await client.routingRules.create({ displayName: 'route-eu-support', description: 'Send EU support traffic to two cheaper models', enabled: true, priority: 0, expression: { cel: 'metadata.region == "eu"' }, modelsConfig: { mode: 'weighted', models: [ { model: 'openai/gpt-5.4-mini', weight: 0.8 }, { model: 'anthropic/claude-sonnet-4-6', weight: 0.2 }, ], },});
import osfrom orq_ai_sdk import Orqclient = Orq(api_key=os.environ["ORQ_API_KEY"])rule = client.routing_rules.create( display_name="route-eu-support", description="Send EU support traffic to two cheaper models", enabled=True, priority=0, expression={"cel": 'metadata.region == "eu"'}, models_config={ "mode": "weighted", "models": [ {"model": "openai/gpt-5.4-mini", "weight": 0.8}, {"model": "anthropic/claude-sonnet-4-6", "weight": 0.2}, ], },)print(rule.id, rule.display_name)
display_name is the only required field. enabled defaults to false, so a rule created without it is saved and matches nothing until it is enabled. priority defaults to 0, and lower values are evaluated first within the rule’s scope.
Show models_config modes and weights
models_config.mode is fallback, latency_based, weighted, or round_robin. Each entry in models_config.models names a model; in weighted mode each entry also carries a weight, the model’s share of matching traffic as a fraction from 0.001 to 1, so 0.8 and 0.2 send 80 and 20 percent of matched requests. The API does not require the weights to sum to 1: they are normalized, as on a request-level load balancer.
The request also accepts project_id for the rule’s project scope (omit it for a workspace-wide rule), plugins as an array of plugin objects, and cache_config.ttl for the rule’s cache lifetime in seconds, up to 259200 (3 days).
Point ORQ_API_KEY at a Management Key with Write access to the Routing rules capability, then pass the fields shown here as flags.
CLI
orq routing-rules create \ --display-name route-eu-support \ --description "Send EU support traffic to two cheaper models" \ --enabled \ --priority 0 \ --expression '{"cel":"metadata.region == \"eu\""}' \ --models-config '{"mode":"weighted","models":[{"model":"openai/gpt-5.4-mini","weight":0.8},{"model":"anthropic/claude-sonnet-4-6","weight":0.2}]}'
The five form sections below map to the request fields shown in the API and CLI tabs. The API accepts additional fields, listed in the API tab.
General
Field
Description
Rule name
A descriptive name for this routing rule.
Description
Optional context for administrators.
Priority
A numeric value that orders matching rules within the same scope. Priority 0 is evaluated before priority 10, and the lowest matching value wins. Workspace-global rules outrank project-scoped rules regardless of priority.
Enable rule
Disabled rules remain saved but are not evaluated for requests.
Load Balancer
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.Load balancing strategy sets how the targets are used:
Strategy
Behavior
Fallback
Route to the primary model, and try the next model when it fails. See the status codes below.
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.
Fallback status codes appears once the rule has a target model. It overrides the default list of 408, 429, 500, 502, 503, 504, and 529; leave it empty to keep the default. The API field is models_config.fallback_on_codes, accepting up to 20 unique integers from 400 through 599, and it applies in Fallback mode only.
Choose Latency when minimizing response time matters more than a fixed traffic split. Choose Weighted or Round Robin when the split itself, such as cost control or A/B testing, is the goal.
Click Models to add a target model. The menu groups models by provider.Each target has a remove control. Fallback also gives each target a drag handle for reordering, and Weighted adds a Traffic weight slider to set that model’s share; the console requires the sliders to add up to 100%.
When a request matches this routing rule, its Load Balancer configuration completely replaces the request’s own model, load_balancer, fallbacks, and fallback_on_codes values; they are never merged. A request-level load_balancer parameter has no effect once a matching routing rule with configured models applies.
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-level cache 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.
Optional. Attach plugins that run on traffic matching this rule. Plugins can transform the request, the response, or stored traces.
Only the winning rule runs its plugins. A project-scoped rule that carries only a plugin never runs while any workspace-global rule matches. To redact per project, attach the PII Redaction plugin to the global rule and match the project in its condition.
Click Plugin to attach one of the following:
Plugin
What it does
PII Redaction
Replaces personally identifiable information with placeholders before the provider sees it, then restores the original values in the response. Configure the entities to mask, the detection threshold, and the failure behavior. See PII Redaction.
Response Healing
Repairs malformed JSON in model output before the response reaches the caller. Takes no configuration. See Response Healing.
Trace Scrubbing
Masks request and response fields in stored traces for matched traffic. Configure which fields to scrub. See Trace Scrubbing.
Conditions
Define when this routing rule should apply to a request. The Rule Builder builds the CEL expression shown read-only in the CEL Expression Preview; leaving it empty applies the rule to every request.Select Add rule to choose a condition type:
Condition
Description
Header
Match on a request header name and value.
Model
Match on the model specified in the request payload.
Identity
Match on the identity making the request.
Metadata
Match on metadata attached to the request.
Project
Match on the project scope of the request.
The CEL expression the Rule Builder generates reads the request through these variables:
Each Add rule creates a condition group titled Rule 1 · N conditions. Inside a group, select Condition to add another condition, and to remove one. Drag a condition by its handle to reorder it. Conditions in a group are joined with and by default; select the AND pill between two conditions to switch the group to or. Delete removes the whole group.Rule groups are joined with or by default; select the pill between two groups to switch them to and.
Editing and deleting a routing rule
Click a rule’s name in the Routing Rules list to open it in the same form. An existing rule exposes Delete Rule in the form footer, next to Save Changes. Deleting asks for confirmation first.The list’s row actions menu offers Edit, Enable or Disable, and Delete.
Was this page helpful?
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Orq.ai Documentation","description":"Documentation for Orq.ai, the EU-built control plane for enterprise AI: govern every LLM and MCP call with the AI Gateway, and ship backlog work with the Software Factory.","colors":{"primary":"#027f6b","light":"#00d2b5","dark":"#027f6b"},"logo":{"light":"https://mintcdn.com/orqai/OG_14djpK9Yasgfk/images/Orq_ai_Symbol_Dark.svg?fit=max\u0026auto=format\u0026n=OG_14djpK9Yasgfk\u0026q=85\u0026s=d01651850182afdbc6309808b688d470","dark":"https://mintcdn.com/orqai/BYq_L5I_ZDBWL_Pf/images/Orq_ai_Symbol_Light.svg?fit=max\u0026auto=format\u0026n=BYq_L5I_ZDBWL_Pf\u0026q=85\u0026s=3e372f93174202f20c31d2c045af92b9","href":"/ai-gateway/get-started/introduction"},"favicon":"https://mintcdn.com/orqai/rmwcfFw4PPljHRCz/favicon.svg?fit=max\u0026auto=format\u0026n=rmwcfFw4PPljHRCz\u0026q=85\u0026s=1827beca4e1fb46e074d8bda067f3fb1","api":{"openapi":"openapi.json","examples":{"languages":["curl","typescript","python"]}},"background":{"color":{"light":"#f7f6f5","dark":"#171717"}},"navbar":{"links":[],"primary":{"type":"button","label":"Get Started","href":"https://my.orq.ai/auth/signup"}},"footer":{"socials":{"github":"https://github.com/orq-ai","x":"https://x.com/orq_ai","linkedin":"https://www.linkedin.com/company/orqai","website":"https://orq.ai"}},"seo":{"metatags":{"author":"Orq.ai","og:type":"website","og:site_name":"Orq.ai Documentation","og:locale":"en_US","twitter:card":"summary_large_image","twitter:site":"@orq_ai","twitter:creator":"@orq_ai","viewport":"width=device-width, initial-scale=1.0","robots":"index, follow","language":"English"},"organization":{"id":"https://docs.orq.ai/#organization","name":"Orq.ai","legalName":"Orq.AI Holding B.V.","url":"https://orq.ai","logo":"https://docs.orq.ai/images/Orq_ai_Symbol_Dark.svg","sameAs":["https://github.com/orq-ai","https://x.com/orq_ai","https://www.linkedin.com/company/orqai/"]},"indexing":"all"},"fonts":{"heading":{"family":"ES Klarheit Kurrent Semibold","weight":600,"source":"https://framerusercontent.com/assets/HiovZWjG27S5NQhE8dyeECDMc.woff2","format":"woff2"},"body":{"family":"Inter","weight":400,"source":"fonts/inter-latin-400-normal.woff2","format":"woff2"}},"styling":{"codeblocks":{"theme":{"light":"github-light","dark":"github-dark"}},"latex":true},"contextual":{"options":["copy","download-spec","chatgpt","claude","view"],"display":"header"},"interaction":{"drilldown":true},"markdown":{"instructions":"Orq.ai is the control plane for model and MCP traffic: one key reaches the workspace's enabled models, MCP servers, and resources. The setup depends on where the agent runs.\nHosted assistant (ChatGPT, claude.ai, a hosted sandbox): install nothing. Tell the human to add https://my.orq.ai/v2/mcp as a remote MCP connector and finish the Orq.ai sign-in. With OAuth, send no Authorization header; otherwise send an API key as a bearer token.\nLocal coding agent (Claude Code, Codex, Cursor, OpenCode): run `curl -fsSL https://cli.orq.ai/install.sh | sh`. It installs the CLI and runs `orq setup`, which signs in, writes a project-scoped key to `~/.orq/env`, and wires the detected agents through the AI Gateway. It can also add the Orq MCP server and Orq Skills, the workflows for agents, evaluations, and traces: https://docs.orq.ai/ai-studio/integrations/code-assistants/orq-skills.md. Verify with `orq status`.\nHeadless or CI: read `ORQ_API_KEY` from the environment; a human creates the key at https://docs.orq.ai/ai-studio/organization/api-keys.md.\nSend model traffic to https://my.orq.ai/v3/router with `Authorization: Bearer $ORQ_API_KEY`; the Anthropic SDK uses https://my.orq.ai/v3/anthropic. New integrations go on `/v3/router`: `/v2/router` stays published for backward compatibility, and `orq.prompt` works only on `/v2/router/chat/completions`.\nEnable a model for the workspace and use its exact `provider/model` id. `POST /v2/workspace-models` enables a model, and a call fails while the workspace has neither credits nor a provider key.\nOn `/chat/completions`, a reasoning model rejects `tools` with a `reasoning_effort` other than `none`; `/responses` keeps reasoning.\nOn a failure, branch on `error.code` and follow `error.doc_url`; a budget rejection answers 429."},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"orqai","hasAudioNarration":false,"actualSubdomain":"orqai","customDomains":["docs.orq.ai"],"gitSource":{"type":"github","owner":"orq-ai","repo":"orquesta-web","deployBranch":"main","contentDirectory":"documentation/mintlify","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true,"agentFeedback":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6b076209aa6ade3866463a40","clientVersion":"0.0.4336","searchFilterCounts":[{"language":"default","tag":"API Reference","count":461},{"language":"default","tag":"Platform APIs","count":292},{"language":"default","tag":"Integrations","count":93},{"language":"default","tag":"Orq SDK","count":82},{"language":"default","tag":"Management APIs","count":79},{"language":"default","tag":"SDK Reference","count":79},{"language":"default","tag":"AI Gateway","count":71},{"language":"default","tag":"Cookbooks","count":34},{"language":"default","tag":"Administration","count":32},{"language":"default","tag":"Model Providers","count":31}],"searchSettings":{"maxResults":15}},"assistantConfig":{"enableStarterQuestions":true,"enableContextualStarterQuestions":true,"deflection":{"enabled":true,"email":"support@orq.ai","showHelpButton":true}},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"googleFontsInlined":false},"customCss":[{"filePath":"custom.css","content":".nav-anchor img{border-radius:50%}.ig-root{scroll-margin-top:6rem}.ig-search{width:100%;padding:10px 14px 10px 38px;border-radius:8px;border:1px solid rgba(0, 0, 0, 0.15);font-size:14px;outline:none;margin-bottom:20px;background:transparent;box-sizing:border-box;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' viewBox='0 0 24 24'%3E%3Cpath stroke='%23999' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m21 21-4.35-4.35M17 11A6 6 0 1 1 5 11a6 6 0 0 1 12 0Z'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:12px center}.dark .ig-search{border-color:rgba(255, 255, 255, 0.15)}.ig-search:focus{border-color:#027f6b}.ig-tabs{display:flex;border-bottom:1px solid rgba(0, 0, 0, 0.1);margin-bottom:20px;gap:0}.dark .ig-tabs{border-bottom-color:rgba(255, 255, 255, 0.1)}.ig-tab{padding:8px 16px;background:none;border:none;border-bottom:2px solid transparent;margin-bottom:-1px;cursor:pointer;font-size:14px;font-weight:500;color:#888;white-space:nowrap}.ig-tab:hover{color:#027f6b}.dark .ig-tab:hover{color:#677F78}.ig-tab-active{border-bottom-color:#027f6b!important;color:#027f6b!important}.dark .ig-tab-active{border-bottom-color:#677F78!important;color:#677F78!important}.ig-grid{display:grid;grid-template-columns:repeat(4, 1fr);gap:6px}@media (max-width: 768px){.ig-grid{grid-template-columns:repeat(3, 1fr)}}@media (max-width: 480px){.ig-grid{grid-template-columns:repeat(2, 1fr)}}.ig-card{display:flex;align-items:center;gap:8px;padding:10px 14px;border:1px solid rgba(0, 0, 0, 0.1);border-radius:6px;text-decoration:none!important;color:inherit!important;font-size:14px;font-weight:500;transition:background 0.12s, border-color 0.12s}.ig-card:hover{background:rgba(2, 127, 107, 0.05);border-color:rgba(2, 127, 107, 0.25)}.dark .ig-card{border-color:rgba(255, 255, 255, 0.1)}.dark .ig-card:hover{background:rgba(103, 127, 120, 0.1);border-color:rgba(103, 127, 120, 0.3)}.ig-card-icon{width:20px;height:20px;object-fit:contain;flex-shrink:0}.ig-tab-count{display:inline-flex;align-items:center;justify-content:center;margin-left:6px;padding:0 5px;min-width:18px;height:18px;border-radius:9px;font-size:11px;font-weight:600;background:rgba(0, 0, 0, 0.08);color:inherit}.dark .ig-tab-count{background:rgba(255, 255, 255, 0.12)}.ig-tab-active .ig-tab-count{background:rgba(2, 127, 107, 0.15)}.dark .ig-tab-active .ig-tab-count{background:rgba(103, 127, 120, 0.25)}.ig-empty{text-align:center;padding:48px 24px;color:#999;font-size:14px;grid-column:1 / -1}kbd.key,kbd.key *{color:#fff!important}kbd.key{background:#242424;border-radius:5px;padding:2px 8px;font-size:0.85em;display:inline-flex;align-items:center;gap:6px;border:1px solid #3a3a3a;font-family:inherit;white-space:nowrap}#sidebar-content .flex-1:has(>svg.flex-shrink-0){flex:none!important}#sidebar-content{width:16rem!important;min-width:16rem!important}@media (min-width: 1024px){.lg\\:pl-56{padding-left:16rem!important}}.topbar-right-container nav[aria-label=\"Main\"] .navbar-link a,.topbar-right-container nav[aria-label=\"Main\"] .navbar-link a:hover{background-color:transparent!important}@media (min-width: 1024px){.topbar-right-container nav[aria-label=\"Main\"] ul{gap:1rem!important}.topbar-right-container nav[aria-label=\"Main\"] .navbar-link a{padding-left:0!important;padding-right:0!important}#page-title{font-size:2rem!important;line-height:1.2!important}}.nav-tabs-item:has(a[href^=\"/reference\"]){display:none!important}#navbar .nav-tabs-item[href=\"/ai-studio/integrations/overview\"]{position:relative}#navbar .nav-tabs-item[href=\"/ai-studio/integrations/overview\"]::before{content:'';position:absolute;top:50%;left:-12px;transform:translateY(-50%);height:55%;width:1px;background:rgba(0, 0, 0, 0.15)}.dark #navbar .nav-tabs-item[href=\"/ai-studio/integrations/overview\"]::before{background:rgba(255, 255, 255, 0.15)}@media (min-width: 1280px){#content-container{padding-left:3rem!important;padding-right:2rem!important}#content-side-layout{max-width:20rem!important}#content-area{width:calc(100% - 20rem)!important}}.md-export-list{display:none}@font-face{font-family:'Inter';src:url('/fonts/inter-latin-400-normal.woff2') format('woff2');font-style:normal;font-weight:400;font-display:optional}"}]}
{"page":{"pagePath":"ai-gateway/configuration/routing-rules","slug":"/ai-gateway/configuration/routing-rules","pageMetadata":{"title":"Routing Rules","sidebarTitle":"Routing Rules","description":"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.","href":"/ai-gateway/configuration/routing-rules"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{Accordion,AccordionGroup,Card,CodeBlock,CodeGroup,Expandable,Frame,Heading,Icon,Note,OptimizedImage,Tab,Table,Tabs,Tip,Tooltip,Warning}=_components;if(!Accordion)_missingMdxReference(`Accordion`,true);if(!AccordionGroup)_missingMdxReference(`AccordionGroup`,true);if(!Card)_missingMdxReference(`Card`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Expandable)_missingMdxReference(`Expandable`,true);if(!Frame)_missingMdxReference(`Frame`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Icon)_missingMdxReference(`Icon`,true);if(!Note)_missingMdxReference(`Note`,true);if(!OptimizedImage)_missingMdxReference(`OptimizedImage`,true);if(!Tab)_missingMdxReference(`Tab`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Tabs)_missingMdxReference(`Tabs`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Tooltip)_missingMdxReference(`Tooltip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Routing Rules are `,_jsx(Tooltip,{tip:`Common Expression Language: the expression syntax that matches request attributes`,children:`CEL`}),`-based conditions that intercept requests to the `,_jsx(_components.a,{href:`/ai-gateway/using-the-router`,children:_jsx(_components.strong,{children:`AI Gateway`})}),` and redirect them to a different model when matched.`]}),`\n`,_jsx(Heading,{level:`2`,id:`use-cases`,children:`Use cases`}),`\n`,_jsx(_components.p,{children:`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.`}),`\n`,_jsxs(AccordionGroup,{children:[_jsx(Accordion,{title:`Swap the model for a support bot without changing any code`,icon:`headset`,id:`swap-the-model-for-a-support-bot-without-changing-any-code`,children:_jsx(_components.p,{children:`Intercepts support bot requests addressed to one model and silently redirects them to a cheaper one, so the calling application needs no changes to benefit from the cost saving.`})}),_jsx(Accordion,{title:`Send simple and complex documents to different models`,icon:`file-lines`,id:`send-simple-and-complex-documents-to-different-models`,children:_jsx(_components.p,{children:`Two rules at the same priority split document traffic by complexity: simple documents go to a lighter model, complex ones go to a more capable model, all based on metadata attached to each request.`})}),_jsx(Accordion,{title:`Keep file attachment requests on models that support them`,icon:`paperclip`,id:`keep-file-attachment-requests-on-models-that-support-them`,children:_jsx(_components.p,{children:`Matches requests that include a file attachment and routes them through an ordered list of models that all support native file input, so the request succeeds even if the first model is unavailable.`})}),_jsx(Accordion,{title:`Automatically reroute traffic when a provider goes down`,icon:`cloud`,id:`automatically-reroute-traffic-when-a-provider-goes-down`,children:_jsx(_components.p,{children:`A low-priority catch-all rule that redirects traffic to an alternative set of models whenever primary providers are unavailable, keeping requests flowing without manual intervention.`})}),_jsx(Accordion,{title:`Spread load evenly across multiple endpoints for the same model`,icon:`rotate`,id:`spread-load-evenly-across-multiple-endpoints-for-the-same-model`,children:_jsx(_components.p,{children:`Distributes requests in round-robin mode across multiple endpoints serving the same model, balancing inference load across providers without any changes required on the caller side.`})})]}),`\n`,_jsx(Heading,{level:`2`,id:`how-routing-rules-work`,children:`How routing rules work`}),`\n`,_jsx(_components.p,{children:`When a request arrives at the AI Gateway, every active rule whose CEL expression matches is a candidate. The winner is chosen in two steps:`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Scope.`}),` Workspace-global rules outrank project-scoped rules. When any global rule matches, the winner comes from those whatever its priority, and project-scoped rules are considered only when no global rule matches.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Priority.`}),` Within the winning scope, the lowest priority number wins, and the rule created first breaks a tie.`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`The winning rule supplies the target model it configures, its plugins, and its cache. The plugins and cache of the other matching rules never run, and a request that matches no rule keeps the model from its payload.`}),`\n`,_jsx(Card,{title:`See also: Request-level load balancing`,icon:`scale-balanced`,href:`/ai-gateway/features/load-balancing`,horizontal:true,children:_jsxs(_components.p,{children:[`To distribute traffic across providers at the request level without organization-wide rules, use the `,_jsx(_components.code,{children:`load_balancer`}),` parameter directly in your API calls.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`creating-a-routing-rule`,children:`Creating a routing rule`}),`\n`,_jsxs(_components.p,{children:[`From the `,_jsx(_components.strong,{children:`Routing Rules`}),` list, click `,_jsxs(`kbd`,{className:`key`,children:[_jsx(Icon,{icon:`circle-plus`,color:`#fff`}),` Routing Rule`]}),`. The form opens as a full page with a back control and an unsaved-changes confirmation. It carries five sections, and the submit button reads `,_jsx(_components.strong,{children:`Create Rule`}),`, or `,_jsx(_components.strong,{children:`Save Changes`}),` once the rule exists.`]}),`\n`,_jsx(Note,{children:_jsx(_components.p,{children:`Routing rules are visible to workspace administrators only.`})}),`\n`,_jsxs(Tabs,{children:[_jsxs(Tab,{title:`AI Studio`,icon:`https://mintcdn.com/orqai/My16MDKJXrKALEHC/images/logos/ai-studio-round.svg?fit=max\u0026auto=format\u0026n=My16MDKJXrKALEHC\u0026q=85\u0026s=ac04dd509320d58ab9701cb6d6137733`,\"data-og-width\":`100`,width:`100`,\"data-og-height\":`100`,height:`100`,\"data-path\":`images/logos/ai-studio-round.svg`,\"data-optimize\":`true`,\"data-opv\":`3`,srcset:`https://mintcdn.com/orqai/My16MDKJXrKALEHC/images/logos/ai-studio-round.svg?w=280\u0026fit=max\u0026auto=format\u0026n=My16MDKJXrKALEHC\u0026q=85\u0026s=d9df8d5b2ef07a766e62eaa0623240cd 280w, https://mintcdn.com/orqai/My16MDKJXrKALEHC/images/logos/ai-studio-round.svg?w=560\u0026fit=max\u0026auto=format\u0026n=My16MDKJXrKALEHC\u0026q=85\u0026s=3c40989d2bc47d1ec6d05f8eb3a585dd 560w, https://mintcdn.com/orqai/My16MDKJXrKALEHC/images/logos/ai-studio-round.svg?w=840\u0026fit=max\u0026auto=format\u0026n=My16MDKJXrKALEHC\u0026q=85\u0026s=2c40a18399d00e68a15d7d1262484486 840w, https://mintcdn.com/orqai/My16MDKJXrKALEHC/images/logos/ai-studio-round.svg?w=1100\u0026fit=max\u0026auto=format\u0026n=My16MDKJXrKALEHC\u0026q=85\u0026s=3e853add10f479adccee3068427de43d 1100w, https://mintcdn.com/orqai/My16MDKJXrKALEHC/images/logos/ai-studio-round.svg?w=1650\u0026fit=max\u0026auto=format\u0026n=My16MDKJXrKALEHC\u0026q=85\u0026s=71d1130736022278f4de6d95e7583c9b 1650w, https://mintcdn.com/orqai/My16MDKJXrKALEHC/images/logos/ai-studio-round.svg?w=2500\u0026fit=max\u0026auto=format\u0026n=My16MDKJXrKALEHC\u0026q=85\u0026s=41a312377a09cf0f6da1edb9b02b695c 2500w`,id:`ai-studio`,children:[_jsxs(_components.p,{children:[`Fill the five sections, then click `,_jsx(_components.strong,{children:`Create Rule`}),`. The sections are described below the tabs.`]}),_jsx(Frame,{caption:`The top of the Create Routing Rule form: the General fields and the Fallback load balancer with one target model.`,children:_jsx(OptimizedImage,{src:`https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-1-418.png?fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=392a61a947daba51c449b0feddf8448c`,alt:`Create Routing Rule form showing the rule name route-eu-support, priority 0, a disabled Enable rule switch, the Fallback strategy selected, claude-sonnet-4-6 as the only target model, and the Fallback status codes field.`,\"data-og-width\":`2400`,width:`2400`,\"data-og-height\":`1597`,height:`1597`,\"data-path\":`images/create-routing-rule-1-418.png`,\"data-optimize\":`true`,\"data-opv\":`3`,srcset:`https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-1-418.png?w=280\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=183d801713d12aa2a514b0f68635dd95 280w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-1-418.png?w=560\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=b83e9b0a2da890ffc904f7268c0e2b95 560w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-1-418.png?w=840\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=dd9ac8c19bd020da694c88ab57e53895 840w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-1-418.png?w=1100\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=2d130ee417264f1d396af314749b8fdd 1100w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-1-418.png?w=1650\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=dcdd48cc621dcba1ee88936ca9be18ae 1650w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-1-418.png?w=2500\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=764e3ba4f1486acc4f3933fa915c0377 2500w`})}),_jsx(Frame,{caption:`The bottom of the Create Routing Rule form: the Plugins section and the Rule Builder with its generated CEL expression.`,children:_jsx(OptimizedImage,{src:`https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-2-418.png?fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=a0f63066513a40d7a87f46be0b9d816f`,alt:`Create Routing Rule form bottom showing an empty Plugins section and a Conditions section with a rule group titled Rule 1 · 1 condition holding one Metadata condition on region equals eu, the Condition and Add rule buttons, and the matching CEL expression metadata region equals eu.`,\"data-og-width\":`2400`,width:`2400`,\"data-og-height\":`1486`,height:`1486`,\"data-path\":`images/create-routing-rule-2-418.png`,\"data-optimize\":`true`,\"data-opv\":`3`,srcset:`https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-2-418.png?w=280\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=9962acd791da8debfb4cbb983a7fe0fa 280w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-2-418.png?w=560\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=f89721283a6ff216abe2328ef84fd591 560w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-2-418.png?w=840\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=5ea4e2e9e05a3c76e80f362c8d91c853 840w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-2-418.png?w=1100\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=940f44768e5ccdca8293c82af53ea1dc 1100w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-2-418.png?w=1650\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=d566dd354c9cabb10488a63d5d34b4ca 1650w, https://mintcdn.com/orqai/sfKTr29e0I7JbeYB/images/create-routing-rule-2-418.png?w=2500\u0026fit=max\u0026auto=format\u0026n=sfKTr29e0I7JbeYB\u0026q=85\u0026s=ed16e777dc44434e95d8fad7a382472c 2500w`})})]}),_jsxs(Tab,{title:`API \u0026 SDK`,icon:`code`,id:`api-%26-sdk`,children:[_jsxs(_components.p,{children:[`Create a routing rule with a `,_jsx(_components.a,{href:`/ai-gateway/configuration/api-keys`,children:_jsx(_components.strong,{children:`Management Key`})}),` that carries `,_jsx(_components.strong,{children:`Write`}),` access to the `,_jsx(_components.strong,{children:`Routing rules`}),` capability.`]}),_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`cURL`,numberOfLines:`19`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`19`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`curl`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` -X`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` POST`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` https://my.orq.ai/v2/routing-rules`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` -H`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"Authorization: Bearer `}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`$ORQ_API_KEY`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` -H`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` -d`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"display_name\": \"route-eu-support\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"description\": \"Send EU support traffic to two cheaper models\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"enabled\": true,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"priority\": 0,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"expression\": {`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"cel\": \"metadata.region == \\\\\"eu\\\\\"\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"models_config\": {`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"mode\": \"weighted\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"models\": [`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` { \"model\": \"openai/gpt-5.4-mini\", \"weight\": 0.8 },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` { \"model\": \"anthropic/claude-sonnet-4-6\", \"weight\": 0.2 }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` }'`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript`,numberOfLines:`18`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` { Orq } `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`from`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` '@orq-ai/node'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`const`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` client`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` =`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` new`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:` Orq`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`({ apiKey: process.env.`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`ORQ_API_KEY`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` });`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`const`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` rule`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` =`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` await`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` client.routingRules.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`create`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` displayName: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`'route-eu-support'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` description: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`'Send EU support traffic to two cheaper models'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` enabled: `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`true`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` priority: `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`0`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` expression: { cel: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`'metadata.region == \"eu\"'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` modelsConfig: {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` mode: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`'weighted'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` models: [`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` { model: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`'openai/gpt-5.4-mini'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, weight: `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`0.8`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` { model: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`'anthropic/claude-sonnet-4-6'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, weight: `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`0.2`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` ],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`});`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,numberOfLines:`21`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`21`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`from`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` orq_ai_sdk `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`import`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` Orq`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`client `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` Orq(`}),_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-dark\":`#FFAB70`},children:`api_key`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"ORQ_API_KEY\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`])`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`rule `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` client.routing_rules.create(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-dark\":`#FFAB70`},children:` display_name`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"route-eu-support\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-dark\":`#FFAB70`},children:` description`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"Send EU support traffic to two cheaper models\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-dark\":`#FFAB70`},children:` enabled`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`True`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-dark\":`#FFAB70`},children:` priority`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`0`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-dark\":`#FFAB70`},children:` expression`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`{`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"cel\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`'metadata.region == \"eu\"'`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-dark\":`#FFAB70`},children:` models_config`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"mode\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"weighted\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"models\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`: [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` {`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"model\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"openai/gpt-5.4-mini\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"weight\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`: `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`0.8`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` {`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"model\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`: `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"anthropic/claude-sonnet-4-6\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"weight\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`: `}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`0.2`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` ],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`print`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`(rule.id, rule.display_name)`})]}),`\n`]})})})]}),_jsx(Note,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`display_name`}),` is the only required field. `,_jsx(_components.code,{children:`enabled`}),` defaults to `,_jsx(_components.code,{children:`false`}),`, so a rule created without it is saved and matches nothing until it is enabled. `,_jsx(_components.code,{children:`priority`}),` defaults to `,_jsx(_components.code,{children:`0`}),`, and lower values are evaluated first within the rule’s scope.`]})}),_jsx(Expandable,{title:`models_config modes and weights`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`models_config.mode`}),` is `,_jsx(_components.code,{children:`fallback`}),`, `,_jsx(_components.code,{children:`latency_based`}),`, `,_jsx(_components.code,{children:`weighted`}),`, or `,_jsx(_components.code,{children:`round_robin`}),`. Each entry in `,_jsx(_components.code,{children:`models_config.models`}),` names a `,_jsx(_components.code,{children:`model`}),`; in `,_jsx(_components.code,{children:`weighted`}),` mode each entry also carries a `,_jsx(_components.code,{children:`weight`}),`, the model’s share of matching traffic as a fraction from `,_jsx(_components.code,{children:`0.001`}),` to `,_jsx(_components.code,{children:`1`}),`, so `,_jsx(_components.code,{children:`0.8`}),` and `,_jsx(_components.code,{children:`0.2`}),` send 80 and 20 percent of matched requests. The API does not require the weights to sum to 1: they are normalized, as on a request-level `,_jsx(_components.a,{href:`/ai-gateway/features/load-balancing#configuration`,children:`load balancer`}),`.`]})}),_jsxs(_components.p,{children:[`The request also accepts `,_jsx(_components.code,{children:`project_id`}),` for the rule’s project scope (omit it for a workspace-wide rule), `,_jsx(_components.code,{children:`plugins`}),` as an array of `,_jsx(_components.a,{href:`#plugins`,children:`plugin`}),` objects, and `,_jsx(_components.code,{children:`cache_config.ttl`}),` for the rule’s cache lifetime in seconds, up to `,_jsx(_components.code,{children:`259200`}),` (3 days).`]})]}),_jsxs(Tab,{title:`CLI`,icon:`terminal`,id:`cli`,children:[_jsxs(_components.p,{children:[`Point `,_jsx(_components.code,{children:`ORQ_API_KEY`}),` at a `,_jsx(_components.strong,{children:`Management Key`}),` with `,_jsx(_components.strong,{children:`Write`}),` access to the `,_jsx(_components.strong,{children:`Routing rules`}),` capability, then pass the fields shown here as flags.`]}),_jsx(CodeBlock,{filename:`CLI`,numberOfLines:`7`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`orq`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` routing-rules`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` create`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` --display-name`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` route-eu-support`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` --description`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` \"Send EU support traffic to two cheaper models\"`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` --enabled`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` --priority`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` 0`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` --expression`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` '{\"cel\":\"metadata.region == \\\\\"eu\\\\\"\"}'`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` --models-config`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:` '{\"mode\":\"weighted\",\"models\":[{\"model\":\"openai/gpt-5.4-mini\",\"weight\":0.8},{\"model\":\"anthropic/claude-sonnet-4-6\",\"weight\":0.2}]}'`})]}),`\n`]})})})]})]}),`\n`,_jsx(_components.p,{children:`The five form sections below map to the request fields shown in the API and CLI tabs. The API accepts additional fields, listed in the API tab.`}),`\n`,_jsx(Heading,{level:`3`,id:`general`,children:`General`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Field`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Rule name`})}),_jsx(_components.td,{children:`A descriptive name for this routing rule.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Description`})}),_jsx(_components.td,{children:`Optional context for administrators.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Priority`})}),_jsxs(_components.td,{children:[`A numeric value that orders matching rules within the same scope. Priority `,_jsx(_components.code,{children:`0`}),` is evaluated before priority `,_jsx(_components.code,{children:`10`}),`, and the lowest matching value wins. Workspace-global rules outrank project-scoped rules regardless of priority.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Enable rule`})}),_jsx(_components.td,{children:`Disabled rules remain saved but are not evaluated for requests.`})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`load-balancer`,children:`Load Balancer`}),`\n`,_jsxs(_components.p,{children:[`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 `,_jsx(_components.a,{href:`#plugins`,children:`plugin`}),` or a `,_jsx(_components.a,{href:`#cache`,children:`cache`}),` to matched traffic, with no model routing at all.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Load balancing strategy`}),` sets how the targets are used:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Strategy`}),_jsx(_components.th,{children:`Behavior`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Fallback`})}),_jsx(_components.td,{children:`Route to the primary model, and try the next model when it fails. See the status codes below.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Latency`})}),_jsxs(_components.td,{children:[`Route to the model with the lowest recently observed latency. See `,_jsx(_components.a,{href:`/ai-gateway/features/load-balancing#latency-based-routing`,children:`Latency-based routing`}),` for the full selection algorithm.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Weighted`})}),_jsx(_components.td,{children:`Split traffic across models by percentage weights.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Round Robin`})}),_jsx(_components.td,{children:`Rotate evenly across all configured models.`})]})]})]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Fallback status codes`}),` appears once the rule has a target model. It overrides the default list of `,_jsx(_components.code,{children:`408`}),`, `,_jsx(_components.code,{children:`429`}),`, `,_jsx(_components.code,{children:`500`}),`, `,_jsx(_components.code,{children:`502`}),`, `,_jsx(_components.code,{children:`503`}),`, `,_jsx(_components.code,{children:`504`}),`, and `,_jsx(_components.code,{children:`529`}),`; leave it empty to keep the default. The API field is `,_jsx(_components.code,{children:`models_config.fallback_on_codes`}),`, accepting up to 20 unique integers from 400 through 599, and it applies in Fallback mode only.`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`Choose `,_jsx(_components.strong,{children:`Latency`}),` when minimizing response time matters more than a fixed traffic split. Choose `,_jsx(_components.strong,{children:`Weighted`}),` or `,_jsx(_components.strong,{children:`Round Robin`}),` when the split itself, such as cost control or A/B testing, is the goal.`]})}),`\n`,_jsxs(_components.p,{children:[`Click `,_jsxs(`kbd`,{className:`key`,children:[_jsx(Icon,{icon:`circle-plus`,color:`#fff`}),` Models`]}),` to add a target model. The menu groups models by provider.`]}),`\n`,_jsxs(_components.p,{children:[`Each target has a remove control. `,_jsx(_components.strong,{children:`Fallback`}),` also gives each target a drag handle for reordering, and `,_jsx(_components.strong,{children:`Weighted`}),` adds a `,_jsx(_components.strong,{children:`Traffic weight`}),` slider to set that model’s share; the console requires the sliders to add up to 100%.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`When a request matches this routing rule, its `,_jsx(_components.strong,{children:`Load Balancer`}),` configuration completely replaces the request’s own `,_jsx(_components.code,{children:`model`}),`, `,_jsx(_components.code,{children:`load_balancer`}),`, `,_jsx(_components.code,{children:`fallbacks`}),`, and `,_jsx(_components.code,{children:`fallback_on_codes`}),` values; they are never merged. A request-level `,_jsx(_components.a,{href:`/ai-gateway/features/load-balancing`,children:_jsx(_components.code,{children:`load_balancer`})}),` parameter has no effect once a matching routing rule with configured models applies.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`cache`,children:`Cache`}),`\n`,_jsxs(_components.p,{children:[`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-level `,_jsx(_components.a,{href:`/ai-gateway/features/cache`,children:_jsx(_components.code,{children:`cache`})}),` setting.`]}),`\n`,_jsxs(_components.p,{children:[`Set `,_jsx(_components.strong,{children:`Enable cache`}),` to turn the cache on, then choose `,_jsx(_components.strong,{children:`Time to live`}),` to control how long matching responses stay cached, from 5 minutes up to 3 days. The default is 1 hour.`]}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`When a rule has cache enabled, a matching request uses the rule’s cache configuration instead of the request’s own `,_jsx(_components.a,{href:`/ai-gateway/features/cache`,children:_jsx(_components.code,{children:`cache`})}),` parameter; the two are not merged.`]})}),`\n`,_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/ai-gateway/features/cache`,children:`LLM response cache`}),` for how caching works.`]}),`\n`,_jsx(Heading,{level:`3`,id:`plugins`,children:`Plugins`}),`\n`,_jsx(_components.p,{children:`Optional. Attach plugins that run on traffic matching this rule. Plugins can transform the request, the response, or stored traces.`}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Only the `,_jsx(_components.a,{href:`#how-routing-rules-work`,children:`winning rule`}),` runs its plugins. A project-scoped rule that carries only a plugin never runs while any workspace-global rule matches. To redact per project, attach the PII Redaction plugin to the global rule and match the project in its condition.`]})}),`\n`,_jsxs(_components.p,{children:[`Click `,_jsxs(`kbd`,{className:`key`,children:[_jsx(Icon,{icon:`circle-plus`,color:`#fff`}),` Plugin`]}),` to attach one of the following:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Plugin`}),_jsx(_components.th,{children:`What it does`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`PII Redaction`})}),_jsxs(_components.td,{children:[`Replaces personally identifiable information with placeholders before the provider sees it, then restores the original values in the response. Configure the entities to mask, the detection threshold, and the failure behavior. See `,_jsx(_components.a,{href:`/ai-gateway/features/plugins/pii-redaction`,children:`PII Redaction`}),`.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Response Healing`})}),_jsxs(_components.td,{children:[`Repairs malformed JSON in model output before the response reaches the caller. Takes no configuration. See `,_jsx(_components.a,{href:`/ai-gateway/features/plugins/response-healing`,children:`Response Healing`}),`.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Trace Scrubbing`})}),_jsxs(_components.td,{children:[`Masks request and response fields in stored traces for matched traffic. Configure which fields to scrub. See `,_jsx(_components.a,{href:`/ai-gateway/features/plugins/trace-scrubbing`,children:`Trace Scrubbing`}),`.`]})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`conditions`,children:`Conditions`}),`\n`,_jsxs(_components.p,{children:[`Define when this routing rule should apply to a request. The `,_jsx(_components.strong,{children:`Rule Builder`}),` builds the CEL expression shown read-only in the `,_jsx(_components.strong,{children:`CEL Expression Preview`}),`; leaving it empty applies the rule to every request.`]}),`\n`,_jsxs(_components.p,{children:[`Select `,_jsx(_components.strong,{children:`Add rule`}),` to choose a condition type:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Condition`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Header`})}),_jsx(_components.td,{children:`Match on a request header name and value.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Model`})}),_jsx(_components.td,{children:`Match on the model specified in the request payload.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Identity`})}),_jsx(_components.td,{children:`Match on the identity making the request.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Metadata`})}),_jsx(_components.td,{children:`Match on metadata attached to the request.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Project`})}),_jsx(_components.td,{children:`Match on the project scope of the request.`})]})]})]}),`\n`,_jsxs(_components.p,{children:[`The CEL expression the `,_jsx(_components.strong,{children:`Rule Builder`}),` generates reads the request through these variables:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Request`}),`: `,_jsx(_components.code,{children:`model`}),`, `,_jsx(_components.code,{children:`model_id`}),`, `,_jsx(_components.code,{children:`provider`})]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Caller`}),`: `,_jsx(_components.code,{children:`headers`}),`, `,_jsx(_components.code,{children:`metadata`}),`, `,_jsx(_components.code,{children:`identity`}),`, `,_jsx(_components.code,{children:`project`}),`, `,_jsx(_components.code,{children:`api_key`})]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Each `,_jsx(_components.strong,{children:`Add rule`}),` creates a condition group titled `,_jsx(_components.strong,{children:`Rule 1 · N conditions`}),`. Inside a group, select `,_jsx(_components.strong,{children:`Condition`}),` to add another condition, and `,_jsx(`kbd`,{children:_jsx(Icon,{icon:`xmark`})}),` to remove one. Drag a condition by its handle to reorder it. Conditions in a group are joined with `,_jsx(_components.code,{children:`and`}),` by default; select the `,_jsx(_components.strong,{children:`AND`}),` pill between two conditions to switch the group to `,_jsx(_components.code,{children:`or`}),`. `,_jsx(_components.strong,{children:`Delete`}),` removes the whole group.`]}),`\n`,_jsxs(_components.p,{children:[`Rule groups are joined with `,_jsx(_components.code,{children:`or`}),` by default; select the pill between two groups to switch them to `,_jsx(_components.code,{children:`and`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`editing-and-deleting-a-routing-rule`,children:`Editing and deleting a routing rule`}),`\n`,_jsxs(_components.p,{children:[`Click a rule’s name in the `,_jsx(_components.strong,{children:`Routing Rules`}),` list to open it in the same form. An existing rule exposes `,_jsx(_components.strong,{children:`Delete Rule`}),` in the form footer, next to `,_jsx(_components.strong,{children:`Save Changes`}),`. Deleting asks for confirmation first.`]}),`\n`,_jsxs(_components.p,{children:[`The list’s row actions menu offers `,_jsx(_components.strong,{children:`Edit`}),`, `,_jsx(_components.strong,{children:`Enable`}),` or `,_jsx(_components.strong,{children:`Disable`}),`, and `,_jsx(_components.strong,{children:`Delete`}),`.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"github-light","dark":"github-dark"}},"config":{},"pageMetadata":{"title":"Routing Rules","sidebarTitle":"Routing Rules","description":"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.","href":"/ai-gateway/configuration/routing-rules"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Use cases","slug":"use-cases","depth":2,"children":[]},{"title":"How routing rules work","slug":"how-routing-rules-work","depth":2,"children":[]},{"title":"Creating a routing rule","slug":"creating-a-routing-rule","depth":2,"children":[{"title":"General","slug":"general","depth":3,"children":[]},{"title":"Load Balancer","slug":"load-balancer","depth":3,"children":[]},{"title":"Cache","slug":"cache","depth":3,"children":[]},{"title":"Plugins","slug":"plugins","depth":3,"children":[]},{"title":"Conditions","slug":"conditions","depth":3,"children":[]}]},{"title":"Editing and deleting a routing rule","slug":"editing-and-deleting-a-routing-rule","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/orqai/41867e13ebfaa3ff/gtm.js","/_mintlify/custom/orqai/1f1a49b99957b631/commonroom-signals.js"],"subdomain":"orqai","siteName":"Orq.ai Documentation","title":"Routing Rules - Orq.ai Documentation","contextualStarterQuestions":[{"_id":"6b03f7d2543fe4ed9bbae860","deploymentId":"68c9bcd7a1b07562da8b036b","questionText":"How do routing rules work?","status":"active","generatedBy":"contextual","path":"ai-gateway/configuration/routing-rules","createdAt":"2026-11-23T08:22:42.723Z","updatedAt":"2026-11-23T08:22:42.723Z","__v":0},{"_id":"6b03f7d2543fe4ed9bbae862","deploymentId":"68c9bcd7a1b07562da8b036b","questionText":"How do I create a routing rule?","status":"active","generatedBy":"contextual","path":"ai-gateway/configuration/routing-rules","createdAt":"2026-11-23T08:22:42.723Z","updatedAt":"2026-11-23T08:22:42.723Z","__v":0},{"_id":"6b03f7d2543fe4ed9bbae861","deploymentId":"68c9bcd7a1b07562da8b036b","questionText":"What are routing rules used for?","status":"active","generatedBy":"contextual","path":"ai-gateway/configuration/routing-rules","createdAt":"2026-11-23T08:22:42.723Z","updatedAt":"2026-11-23T08:22:42.723Z","__v":0}],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-23T08:22:36.915Z","originalFileLocation":"ai-gateway/configuration/routing-rules.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Orq.ai Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003cmeta data-mint-head name=\"robots\" content=\"index, follow\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Routing Rules - Orq.ai Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Orq.ai Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.orq.ai/ai-gateway/configuration/routing-rules\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://orqai.mintlify.site/_mintlify/api/og/v2?division=Routing\u0026amp;title=Routing+Rules\u0026amp;description=Use+CEL-based+routing+rules+to+redirect+AI+Gateway+requests+to+different+models+based+on+request+attributes%2C+resolved+by+scope+then+priority.\u0026amp;theme=3624f44f3669d4325dc81433\u0026amp;signature=490bd107e3bb8864331e68454da343bd7e325f3de5bc9f3d070c7340302581d8\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Routing Rules - Orq.ai Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://orqai.mintlify.site/_mintlify/api/og/v2?division=Routing\u0026amp;title=Routing+Rules\u0026amp;description=Use+CEL-based+routing+rules+to+redirect+AI+Gateway+requests+to+different+models+based+on+request+attributes%2C+resolved+by+scope+then+priority.\u0026amp;theme=3624f44f3669d4325dc81433\u0026amp;signature=490bd107e3bb8864331e68454da343bd7e325f3de5bc9f3d070c7340302581d8\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/orqai/5zquLIiRlftT1q7X/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Orq.ai Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#027f6b\">\u003cmeta data-mint-head name=\"og:locale\" content=\"en_US\">\u003cmeta data-mint-head name=\"author\" content=\"Orq.ai\">\u003cmeta data-mint-head name=\"twitter:creator\" content=\"@orq_ai\">\u003cmeta data-mint-head name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\u003cmeta data-mint-head name=\"language\" content=\"English\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.orq.ai/ai-gateway/configuration/routing-rules\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/ai-gateway/configuration/routing-rules.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.orq.ai/#organization\",\"name\":\"Orq.ai\",\"legalName\":\"Orq.AI Holding B.V.\",\"url\":\"https://orq.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://docs.orq.ai/images/Orq_ai_Symbol_Dark.svg\"},\"sameAs\":[\"https://github.com/orq-ai\",\"https://x.com/orq_ai\",\"https://www.linkedin.com/company/orqai/\"]},{\"@type\":\"WebSite\",\"@id\":\"https://docs.orq.ai#website\",\"name\":\"Orq.ai Documentation\",\"url\":\"https://docs.orq.ai\",\"publisher\":{\"@id\":\"https://docs.orq.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules#webpage\",\"url\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules\",\"name\":\"Routing Rules\",\"description\":\"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.\",\"dateModified\":\"2026-11-23T08:22:36.915Z\",\"isPartOf\":{\"@id\":\"https://docs.orq.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Routing\",\"item\":\"https://docs.orq.ai/ai-gateway/providers-overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Routing Rules\",\"item\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules#article\",\"headline\":\"Routing Rules\",\"name\":\"Routing Rules\",\"description\":\"Use CEL-based routing rules to redirect AI Gateway requests to different models based on request attributes, resolved by scope then priority.\",\"url\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules\",\"mainEntityOfPage\":{\"@id\":\"https://docs.orq.ai/ai-gateway/configuration/routing-rules#webpage\"},\"dateModified\":\"2026-11-23T08:22:36.915Z\",\"publisher\":{\"@id\":\"https://docs.orq.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.orq.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Orq.ai Documentation\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Orq.ai\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/ai-gateway/configuration/routing-rules.md","siteName":"Orq.ai Documentation","nav":{"global":null,"tabs":[{"tab":"AI Gateway","groups":[{"group":"Overview","icon":"compass","pages":[{"title":"AI Gateway","sidebarTitle":"Quick Start","href":"/ai-gateway/get-started/introduction"},{"title":"Migrate from OpenAI, Anthropic, OpenRouter, LiteLLM","sidebarTitle":"Migrate","href":"/ai-gateway/get-started/migrate"},{"title":"API Keys and Management Keys","sidebarTitle":"API Keys \u0026 Management Keys","href":"/ai-gateway/configuration/api-keys"},{"title":"Budgets","sidebarTitle":"Budgets","href":"/ai-gateway/budgets"},{"title":"Models","sidebarTitle":"Manage Models","href":"/ai-gateway/using-the-router"},{"title":"Supported models in AI Gateway","sidebarTitle":"Supported Models","href":"/ai-gateway/supported-models"},{"title":"Model Arena","href":"/ai-gateway/model-arena"},{"title":"Request metadata","sidebarTitle":"Request Metadata","href":"/ai-gateway/request-metadata"}]},{"group":"APIs","icon":"code","pages":[{"title":"Responses API","sidebarTitle":"Responses API","href":"/ai-gateway/features/responses-api"},{"title":"OpenAI-compatible API","sidebarTitle":"OpenAI-Compatible API","href":"/ai-gateway/features/openai-compatible-api"},{"title":"Anthropic Messages API","sidebarTitle":"Anthropic Messages API","href":"/ai-gateway/features/anthropic-messages-api"},{"title":"Connect agents through the AI Gateway","sidebarTitle":"Agents Gateway","href":"/ai-gateway/features/agents-gateway"}]},{"group":"MCP Portal","icon":"plug","pages":[{"title":"MCP Servers","sidebarTitle":"MCP Servers","href":"/ai-gateway/mcp-portal/mcp-servers"},{"title":"MCP Gateway","sidebarTitle":"MCP Gateway","href":"/ai-gateway/mcp-portal/mcp-gateways"}]},{"group":"Routing","icon":"route","pages":[{"title":"BYOK","sidebarTitle":"Bring Your Own Key (BYOK)","href":"/ai-gateway/providers-overview"},{"title":"Provider integrations","sidebarTitle":"Provider integrations","href":"/ai-gateway/features/provider-integrations"},{"title":"Smart Router","sidebarTitle":"Smart Router","href":"/ai-gateway/smart-router"},{"title":"Model Fusion","sidebarTitle":"Model Fusion","href":"/ai-gateway/model-fusion"},{"title":"Auto Models","sidebarTitle":"Auto Models","href":"/ai-gateway/auto-models"},{"title":"Session Affinity","sidebarTitle":"Session Affinity","href":"/ai-gateway/session-affinity"},{"title":"Fallbacks and retries in the AI Gateway","sidebarTitle":"Fallbacks \u0026 Retries","href":"/ai-gateway/features/retries"},{"title":"Load balancing across providers","sidebarTitle":"Load Balancing","description":"Distribute LLM requests across providers using latency-based, weight-based, or round-robin routing to optimize costs, run A/B tests, and ensure redundancy.","href":"/ai-gateway/features/load-balancing"},{"title":"Routing Rules","sidebarTitle":"Routing Rules","href":"/ai-gateway/configuration/routing-rules"},{"title":"LLM response cache","sidebarTitle":"Cache","description":"Cache identical LLM requests to reduce latency and cut API costs. Configure exact match response caching with TTL for repeated queries and FAQ lookups.","href":"/ai-gateway/features/cache"},{"title":"Request timeouts","sidebarTitle":"Timeouts","href":"/ai-gateway/features/timeouts"},{"title":"Rate limits and quotas","sidebarTitle":"Rate limits \u0026 quotas","href":"/ai-gateway/features/rate-limits"},{"title":"Service tiers","sidebarTitle":"Service Tiers","href":"/ai-gateway/features/service-tiers"},{"title":"Response Healing","sidebarTitle":"Response Healing","tag":"Beta","href":"/ai-gateway/features/plugins/response-healing"},{"title":"Managed Prompts in router requests","sidebarTitle":"Using Prompts","href":"/ai-gateway/features/using-prompts"},{"title":"Knowledge bases via AI Gateway","sidebarTitle":"Knowledge Bases","href":"/ai-gateway/features/knowledge-bases"}]},{"group":"Security \u0026 Privacy","icon":"shield-halved","pages":[{"title":"EU data residency and model routing","sidebarTitle":"EU Routing \u0026 Data Residency","href":"/enterprise/eu-regions-faq"},{"title":"Sovereign AI and zero data retention (ZDR)","sidebarTitle":"Sovereign AI \u0026 ZDR","href":"/enterprise/sovereign-ai"},{"title":"Guardrails","sidebarTitle":"Guardrails","href":"/ai-gateway/configuration/guardrails"},{"title":"Guardrail Rules","sidebarTitle":"Guardrail Rules","href":"/ai-gateway/configuration/guardrail-rules"},{"title":"External Guardrails","sidebarTitle":"External Guardrails","href":"/ai-gateway/configuration/external-guardrails"},{"title":"Mask sensitive content in traces","sidebarTitle":"Trace Data Masking","href":"/ai-gateway/features/security"},{"title":"PII Redaction","sidebarTitle":"PII Redaction","tag":"Beta","href":"/ai-gateway/features/plugins/pii-redaction"},{"title":"Trace Scrubbing","sidebarTitle":"Trace Scrubbing","href":"/ai-gateway/features/plugins/trace-scrubbing"},{"title":"Bring Your Own Model","sidebarTitle":"Bring Your Own Model","href":"/ai-gateway/private-models"}]},{"group":"Model Capabilities","icon":"bolt","pages":[{"title":"LLM response streaming","sidebarTitle":"Streaming","href":"/ai-gateway/features/streaming"},{"title":"Realtime and WebSocket sessions","sidebarTitle":"Realtime","href":"/ai-gateway/features/realtime"},{"title":"Structured outputs with JSON schema","sidebarTitle":"Structured Outputs","href":"/ai-gateway/features/structured-outputs"},{"title":"Image, PDF and audio generation","sidebarTitle":"Multimodal","href":"/ai-gateway/features/multimodal"},{"title":"OCR via AI Gateway","sidebarTitle":"OCR","href":"/ai-gateway/features/ocr"},{"title":"Sending files to models","sidebarTitle":"Files","href":"/ai-gateway/features/files"},{"title":"Batches","sidebarTitle":"Batches","href":"/ai-gateway/features/batches"},{"title":"Prompt caching","sidebarTitle":"Prompt Caching","href":"/ai-gateway/features/prompt-caching"},{"title":"Context compaction for long conversations","sidebarTitle":"Context Compaction","href":"/ai-gateway/features/context-compaction"},{"title":"Tool calling and function execution","sidebarTitle":"Tool Calling","href":"/ai-gateway/features/tool-calling"},{"title":"Background Responses","sidebarTitle":"Background Responses","href":"/ai-gateway/features/background-responses"},{"title":"Reasoning models","sidebarTitle":"Reasoning","href":"/ai-gateway/features/reasoning"},{"title":"Web search in Responses API","sidebarTitle":"Web Search","href":"/ai-gateway/features/web-search"},{"title":"Dynamic inputs for runtime configuration","sidebarTitle":"Inputs","href":"/ai-gateway/features/inputs"},{"title":"Embeddings","sidebarTitle":"Embeddings","href":"/ai-gateway/features/embeddings"},{"title":"Rerank and Moderations","sidebarTitle":"Rerank \u0026 Moderations","href":"/ai-gateway/features/rerank-and-moderations"},{"title":"Decisions","sidebarTitle":"Decisions","href":"/ai-gateway/features/decisions"},{"title":"Model FAQ","sidebarTitle":"Model FAQ","href":"/ai-gateway/model-faq"}]},{"group":"Server Tools","icon":"toolbox","pages":[{"title":"Server tools","sidebarTitle":"Overview","href":"/ai-gateway/features/server-tools"},{"title":"Web search server tool","sidebarTitle":"Web Search","href":"/ai-gateway/features/server-tools/web-search"},{"title":"Web fetch server tool","sidebarTitle":"Web Fetch","href":"/ai-gateway/features/server-tools/web-fetch"},{"title":"Datetime server tool","sidebarTitle":"Datetime","href":"/ai-gateway/features/server-tools/datetime"},{"title":"Image generation server tool","sidebarTitle":"Image Generation","href":"/ai-gateway/features/server-tools/image-generation"},{"title":"Code interpreter server tool","sidebarTitle":"Code Interpreter","href":"/ai-gateway/features/server-tools/code-interpreter"},{"title":"Shell server tool","sidebarTitle":"Shell","href":"/ai-gateway/features/server-tools/shell"},{"title":"Apply patch server tool","sidebarTitle":"Apply Patch","href":"/ai-gateway/features/server-tools/apply-patch"},{"title":"Knowledge-base server tools","sidebarTitle":"Knowledge Bases","href":"/ai-gateway/features/server-tools/knowledge-bases"},{"title":"Search models server tool","sidebarTitle":"Search Models","href":"/ai-gateway/features/server-tools/search-models"},{"title":"Tool search server tool","sidebarTitle":"Tool Search","href":"/ai-gateway/features/server-tools/tool-search"},{"title":"Subagent server tool","sidebarTitle":"Subagent","href":"/ai-gateway/features/server-tools/subagent"},{"title":"Advisor server tool","sidebarTitle":"Advisor","href":"/ai-gateway/features/server-tools/advisor"},{"title":"Fusion server tool","sidebarTitle":"Fusion","href":"/ai-gateway/features/server-tools/fusion"}]},{"group":"Common Scenarios","icon":"book-open","pages":[{"title":"Multi-tenant setup","sidebarTitle":"Multi-tenant setup","href":"/ai-gateway/multi-tenant-setup"}]}]},{"tab":"AI Observability","pages":[{"title":"AI Observability","href":"/ai-studio/observability/quickstart"}]},{"tab":"Managed agents","pages":[{"title":"Managed agents","href":"/ai-studio/ai-engineering/quickstart"}]},{"tab":"Administration","pages":[{"title":"Administration","href":"/ai-studio/organization/workspace-settings"}]},{"tab":"Integrations","pages":[{"title":"Integrations","href":"/ai-studio/integrations/overview"}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/reference/client-libraries"}]},{"tab":"Cookbooks","hidden":true,"pages":[{"title":"Cookbooks","href":"/ai-studio/cookbooks/cookbooks"}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog/release-4-19"}]}]},"basePath":"","title":"Routing Rules - Orq.ai Documentation","deploymentId":"dpl_9bQLTw9nc2h9csDGYcKwWenPcQWn","buildId":"dpl_9bQLTw9nc2h9csDGYcKwWenPcQWn","dynamics":["07c022d89b","a74be98ba7"],"chunks":["Frame-D6LgX1ys.js","DynamicMarkdown-CZT_WAnN.js","zoom-image-lightbox-CIIGaZaE.js","lightbox-handle-r17bVUz3.js"]}