Routing API
Choose the model for each request from what the request contains, such as keeping confidential requests on a model you host.
Enterprise: this feature is gated behind a separate software license.
Get access
The Routing API is an Enterprise feature, gated behind a separate software license; contact founders@experientiallabs.ai to request access.
Manage routing policies with a provisioning key. Your API key determines the organization. Without access, every route answers 404.
| Term | Meaning |
|---|---|
| Tag | A yes or no question the gateway answers about a request, as a probability from 0 to 1 |
| Rule | A tag, a threshold and a model. A match sends the request to that model |
| Routing policy | Rules tried in order, a default model, and an alias you call like a model |
A routing policy picks the model. Each model keeps its own provider waterfall.
GET/v1/routingcurl --fail-with-body https://api.experientiallabs.ai/v1/routing \
-H "Authorization: Bearer <YOUR_API_KEY>"{
"routing_policies": []
}Create a routing policy
Rules use tags. Pick a platform tag or create your own, and test it first.
POST/v1/routing| Field | Meaning |
|---|---|
alias | The model name callers send |
rules | Tried in order. The first match picks the model |
default_model | Serves a request when the whole request was read and no rule matched |
fallback_model | Serves a request the check could not finish or could not read. Leave out to refuse the request instead |
max_wait_ms | The longest a request waits for the check. Default 2,000, at most 5,000 |
Every model is a slug your organization can call: a catalog model, a custom model, or your own endpoint. It cannot be another routing policy or an uncensored model.
{
"alias": "acme-auto",
"description": "Keep confidential requests on our own model",
"rules": [
{ "tag": "internalConfidential", "threshold": 0.5, "model": "my-local-model" },
{ "tag": "personalData", "threshold": 0.7, "model": "my-local-model" }
],
"default_model": "gpt-6-luna",
"fallback_model": "my-local-model"
}curl --fail-with-body -X POST https://api.experientiallabs.ai/v1/routing \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
--data @policy.jsonSend requests to the policy
Send the alias as model on Chat Completions, Responses, Messages or Gemini, with any key of your organization. The check runs before the request is sent to any model and reads every message in it: see What a check reads.
/v1/responses| Response header | Value |
|---|---|
x-gateway-canonical-model | The model that served the request |
x-gateway-routing-decision | rule, default or fallback |
x-gateway-routing-tag | The tag of the rule that matched |
The request is billed as the model that served it. Guardrails are compared with that model, not with the alias.
from openai import OpenAI
client = OpenAI(base_url="https://api.experientiallabs.ai/v1", api_key="<YOUR_API_KEY>")
response = client.responses.with_raw_response.create(
model="acme-auto",
input="Rewrite this note for the board: we are pausing the Atlas launch until Q2.",
)
print(response.headers["x-gateway-canonical-model"]) # my-local-model
print(response.parse().output_text)Cover requests that skip the policy
Calling the policy is the caller's choice. A request that names another model directly is not routed. To keep those requests off other models too, add a guardrail that covers every model except yours.
POST/v1/guardrailsThe policy sends a confidential request to your model, and the guardrail refuses one that names any other model. One check serves both.
{
"name": "Keep confidential data off external models",
"mode": "enforce",
"timing": "before_dispatch",
"rules": [
{ "tag": "internalConfidential", "threshold": 0.5 }
],
"exclude_models": ["my-local-model"],
"on_error": "block"
}Preview a decision
See which model the policy would pick for sample text, with the score of every rule. The text is checked like one message of a request. It is not sent to any model in the policy.
POST/v1/routing/{policy_id}/previewcurl --fail-with-body -X POST https://api.experientiallabs.ai/v1/routing/00000000-0000-4000-8000-000000000012/preview \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"input": "Draft the board update. Revenue was 4.2M against a 5M plan and we are pausing the Atlas launch."}'{
"decision": "rule",
"model": "my-local-model",
"tag": "internalConfidential",
"results": [
{ "tag": "internalConfidential", "probability": 0.96, "threshold": 0.5, "matched": true },
{ "tag": "personalData", "probability": 0.02, "threshold": 0.7, "matched": false }
]
}When the check cannot decide
A request reaches default_model only when the whole request was read and no rule matched. You choose what happens otherwise.
| Situation | Result |
|---|---|
| A rule matches | That rule's model. If it cannot serve the request, the request fails. The policy never moves it to default_model |
| The whole request was read and no rule matches | default_model |
The check does not finish within max_wait_ms | fallback_model, or 503 gateway_unavailable when there is none |
| The request carries content the check cannot read (images, audio, files) | fallback_model, or 400 content_filter when there is none |
To keep data on models you host, set fallback_model to one of them or leave it out.
{
"error": {
"message": "...",
"type": "api_error",
"param": null,
"code": "gateway_unavailable"
}
}A conversation stays on its model
A conversation resends its history, and the check reads all of it. Once a message matches a rule, every later request that still carries that message matches too, so the conversation stays on that rule's model.
Nothing is stored to make this work, and it does not expire.
| Turn | The request carries | Served by |
|---|---|---|
| 1 | No message that matches | default_model |
| 2 | No message that matches | default_model |
| 3 | A new message that matches a rule | The rule's model |
| 4 and later | The same history | The rule's model |
Update or delete
Send only the fields to change. rules replaces the whole list, so send every rule you want to keep. The alias cannot change. Send null to remove fallback_model. A change applies to new requests within a minute.
/v1/routing/{policy_id}DELETE/v1/routing/{policy_id}After a delete, requests that name the alias are refused like any unknown model.
curl --fail-with-body -X PATCH https://api.experientiallabs.ai/v1/routing/00000000-0000-4000-8000-000000000012 \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"rules": [
{ "tag": "internalConfidential", "threshold": 0.4, "model": "my-local-model" },
{ "tag": "personalData", "threshold": 0.7, "model": "my-local-model" }
]
}'Errors
| Status / code | Action |
|---|---|
401 | Check the key |
403 | Use a provisioning key |
404 | Check the id and your access to the API |
409 alias_unavailable | The alias is already a model or an alias you can call. Choose another |
422 | Fix the body. unknown_tag and unknown_model name what does not exist. model_not_allowed names another routing policy or an uncensored model |
503 check_unavailable | The check could not run on a preview call. Retry |
503 gateway_unavailable on inference | The check did not finish and the policy has no fallback_model. Retry |
400 content_filter on inference | The request carries content the check cannot read and the policy has no fallback_model. Retrying does not help |
{
"error": "The alias acme-auto is already in use",
"code": "alias_unavailable"
}