Skip to main content Skip to content

AI routing policies

How the AI Gateway chooses between a cheaper and a stronger model for each request sent to chat-auto, how to force a choice, how to test a prompt, and what the AI Routing page on Governance → Policies is for.

5 min read

The AI Gateway can choose the model for you. Send a request to the model chat-auto (or its alias zn-auto) and the gateway sends it to one of two tiers: Efficient, a cheaper model for short chats, summaries, and classification, or Frontier, a stronger model for hard reasoning, code, and long content. Sending simple prompts to the cheaper model can lower your AI spend.

AI routing policies page with traffic split, cache savings, and requests routed counters, the Cost-saver, Balanced, and Quality-first routing postures, and the Memory and cache settings

Governance → Policies → AI Routing: routing posture, memory and cache, and where requests go.

Routing only happens when you ask for it. A request that names a specific model goes to that model and is never re-routed.

How the gateway chooses

For a request to chat-auto or zn-auto, the gateway checks these rules in order and uses the first one that matches:

#If the request…It goes to
1has an X-ZN-Tier header set to strong or cheapFrontier for strong, Efficient for cheap
2asks for a long answer: max_tokens of 2,000 or moreFrontier
3is long: about 1,500 tokens or more (roughly 6,000 characters) across all its messagesFrontier
4contains analyse, analyze, prove, step by step, or reason anywhere, in any messageFrontier
matches none of theseEfficient

A few things to know:

  • Every message counts, including the system message and earlier turns of the chat, not just the latest question.
  • Rule 4 matches inside longer words, so “improve”, “approve”, and “reasoning” also go to Frontier.
  • Any other header value is ignored, and the other rules apply.
  • The choice is made by these fixed rules, not by calling another model, so routing adds no extra cost.

Choose the tier yourself

When you already know a request needs the stronger model, or never does, add the X-ZN-Tier header. It overrides the other rules.

Terminal window
curl "$GATEWAY_URL/chat/completions" \
-H "Authorization: Bearer $INFERENCE_KEY" \
-H "X-ZN-Tier: strong" \
-H "Content-Type: application/json" \
-d '{"model": "chat-auto", "messages": [{"role": "user", "content": "Review this contract clause"}]}'

Your gateway address and key are shown in the usage guide when you create an inference key under AI Estate → Inference Keys. Use them in place of $GATEWAY_URL and $INFERENCE_KEY.

Test where a prompt would go

To see which tier a prompt would get without sending it to a model, use the dry run:

Terminal window
curl -X POST "$ZOPNIGHT_API/orgs/$ORG_ID/ai/routing/evaluations" \
-H "Authorization: Bearer $ZOPNIGHT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"prompt": "Summarise this ticket", "maxTokens": 300}'

It answers with a tier (cheap means Efficient, strong means Frontier) and the gateway’s model name (chat-cheap or chat-strong). It looks only at the prompt and maxTokens you send. Add "tier": "strong" to see the effect of the header. GET /orgs/$ORG_ID/ai/routing shows the rules; they’re the same for every organisation. Every built-in role can call both. See Authentication for tokens.

The AI Routing page

Governance → Policies → AI Routing is a planning view for routing:

  • Routing posture: Cost-saver (Efficient by default; only the hardest, image, or document requests reach Frontier), Balanced (route by how complex the task is; code, analysis, images, and documents go to Frontier), or Quality-first (Frontier by default; only simple chat and low-budget requests go to Efficient). All three also send requests with personal data to Frontier, and Balanced sends long answers (max_tokens of 2,000 or more) there too. Changing a routing condition or a tier’s model switches the posture to Custom; changing Memory & cache keeps it.
  • Memory & cache: reuse answers to similar questions, and connect a knowledge base.
  • Where requests go: which model would serve Efficient and which would serve Frontier.
  • Conditions: how complex the task is, a cost cap per request, requests that need a fast answer, images, documents, long answers, sensitive data, fitting the model’s context window, falling back to another provider, and task types (coding, analysis, extraction, chit-chat).
  • Test routing: type a prompt (optionally attach a file or mark it as containing personal data) and see which tier these settings would pick.

Only the built-in Admin role (or a custom role that can update AI models) can change the page’s settings. Everyone else sees it read-only.

Multi-cloud automation· Production-ready in 30 min· SOC 2 · ISO 27001· 20–60% off the bill, first month· 4 platforms · 1 console· Multi-cloud automation· Production-ready in 30 min· SOC 2 · ISO 27001· 20–60% off the bill, first month· 4 platforms · 1 console·