Skip to content

Routing Rules

Routing Rules let an AI endpoint decide its provider/model per request instead of being fixed at design time. Rules are defined as YAML on the endpoint, evaluated top-to-bottom, and the first matching rule wins. If no rule matches, the endpoint’s default provider is used (so adding rules is always safe — they only narrow behavior).

SituationRule
Cheap default model can’t handle 200k-token promptsSwitch to a long-context model when input_tokens is large
Strict JSON schema enforcement only on some providersSwitch when has_output_schema is true
You’re 90 % through your monthly budgetFall back to a cheaper provider
Off-peak rate makes a big model affordable at nightUse the bigger model between 22:00 and 06:00

Endpoints → (your endpoint) → Routing tab. Snippet templates are provided for the common cases.

rules:
- when:
input_tokens: ">= 100000"
use:
template: anthropic-claude-sonnet
credential: claude-prod
decision: "long-context"
- when:
has_output_schema: true
use:
template: openai-gpt-4o
credential: openai-prod
decision: "schema-strict"
- when:
monthly_spend_pct: ">= 90"
use:
template: openai-gpt-4o-mini
credential: openai-prod
decision: "budget-pinch"
- when:
time_of_day: "22:00-06:00"
use:
template: anthropic-claude-opus
credential: claude-prod
decision: "off-peak"
FieldTypeMatch
input_tokenscomparison">= 100000", "< 4000"
messages_countcomparison">= 10"
has_output_schemabooltrue / false
has_input_schemabooltrue / false
streamingboolrequest asked for SSE
monthly_spend_pctcomparison">= 90" (% of monthly budget consumed)
time_of_daywindow"22:00-06:00" (UTC, wraps midnight)

All conditions in a single when: block must match (logical AND).

FieldDescription
templateProvider template slug (e.g. openai-gpt-4o)
credentialCredential name in the project
modelOptional override of the template’s model
decisionFree-form label that ends up in gateway_logs.routing_decision and the live-logs modal

Every routed request stamps routing_decision on its gateway_logs row, and the live logs UI surfaces it in the modal title. Filtering by decision label is the fastest way to verify a rule is firing.

Rules are validated server-side on save (Endpoints store/update). If the YAML is malformed or references an unknown template/credential, the form rejects with a clear error — you can’t ship a broken endpoint.


© Akyros Labs LLC. All rights reserved.