What you will have at the end
A Route, assistant-api, that answers chat completions. Behind it sit two model instances: an on-premises model server as the primary and a cloud model as the fallback. When the primary answers 5xx, the engine sends the same request to the fallback and the client never notices, except in the latency. Traffic Explorer shows which instance answered each call, and the audit log keeps the change with both API keys masked. A token budget with ai-rate-limiting goes on top at the end, with one measured limit of its own: it counted the primary’s tokens and not the fallback’s.
Prerequisites
- An on-premises model server with an OpenAI-compatible chat endpoint. In this article it is
llm-onprem:8080, servingllama-3.3-70b-instruct, and it can be made to answer 503 on demand. - An API key for the cloud provider. Here it is an Anthropic key, used for
claude-haiku-5-5. - A Consumer for the client,
support_assistant, with akey-authcredential, and traffic logging turned on under Traffic Explorer › Settings.
Step 1: the Route and the Consumer
Create the Route assistant-api with the path /ai/chat, the method POST and Target › None: the Plugin calls the model providers itself, so the Route has no Upstream. Add key-auth to it, and create the Consumer support_assistant with a key-auth credential on its Credentials tab.
Step 2: two instances in ai-proxy-multi
Add ai-proxy-multi to the Route. Its Instances setting is a list of providers and is edited as JSON in the form; Use example fills in a two-instance skeleton to edit. The two instances of this article:
[
{
"name": "onprem-llama",
"provider": "openai-compatible",
"priority": 10,
"weight": 100,
"auth": { "header": { "Authorization": "Bearer …" } },
"override": { "endpoint": "http://llm-onprem:8080/v1/chat/completions" },
"options": { "model": "llama-3.3-70b-instruct" }
},
{
"name": "anthropic-haiku",
"provider": "anthropic",
"priority": 0,
"weight": 100,
"auth": { "header": { "x-api-key": "…" } },
"options": { "model": "claude-haiku-5-5", "max_tokens": 256 }
}
]
The primary has the higher priority, so it is tried first. override.endpoint points the OpenAI-compatible provider at the on-premises server. The cloud instance needs only its provider name, the key and the model: the engine knows the provider’s address and request format.
Under Behavior, tick http_5xx in Fallback strategy: a 5xx from the instance that was picked sends the request to the next one. The form notes which combinations the engine accepts, and the fields under it tune the behaviour: Fallback status codes for other statuses that should fall back, Fallback retry limit for how many more instances one request may try, and Retry failures within so that only fast failures are retried and a slow one is returned to the client instead of doubling the wait.

Save the Plugin. The Plugin’s page shows the two instances with their priorities and their auth headers as ••••.

Step 3: a call on the primary
The client sends an OpenAI-style chat completion to the Route with its API key:
curl -X POST http://localhost:9281/ai/chat -H "apikey: $ASSISTANT_KEY" \
-H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":"Where is order ord-10421?"}]}'
The answer comes from the on-premises model in about 50 ms, with "model": "llama-3.3-70b-instruct" and a usage block of 65 tokens.
Step 4: force the primary to fail
The on-premises server was switched into its restarting state, where it answers every completion with 503. The same call to the Route, unchanged, now answers 200 in about 1.6 seconds, with "model": "claude-haiku-5-5" and the cloud model’s own wording. The client sent one request and got one answer; the engine made two attempts.
What Traffic Explorer shows
Filter Traffic Explorer by the path /ai/chat. The Upstream node column is the evidence: the records before the failure name llm-onprem:8080 with latencies of tens of milliseconds, the records after it name api.anthropic.com:443 with latencies of one and a half seconds and more.

Open one of the later records. The Overview reads api.anthropic.com:443 · 2 attempts: the engine tried the on-premises instance, received the 503, and went to the fallback within the same request. The timing bar shows 1 ms in the gateway and the rest waiting for the model.

The Route’s Analytics tab counts the same calls and their backend time, so the switch is visible there too.
What the audit log keeps
The change that put the two instances on the Route is one audit record. Its diff shows every setting, and both keys are masked on the after side; the record names the two masked paths that changed.

Token limits on top with ai-rate-limiting
A fallback to a paid model needs a cap. Add ai-rate-limiting to the Route: Limit 300, Time window 60 seconds and Rejected code 429, with Limit strategy left at its default, total tokens. The limit counts the tokens the model reports in its usage, not the requests.

With the on-premises model answering again, every call cost 65 tokens and the response headers counted them down:
X-AI-RateLimit-Limit-onprem-llama: 300
X-AI-RateLimit-Remaining-onprem-llama: 40
X-AI-RateLimit-Reset-onprem-llama: 40
The next call after the budget reached zero was refused with 429, and the refusals sit in Traffic Explorer as records with gateway as their node.
One measurement to know about. While the primary was failing and the fallback answered, the headers still carried the primary’s name and Remaining stayed at 300: the tokens the fallback produced were not counted against the budget. The form offers an Instances table with a budget per instance name, which is where a separate cap for the cloud model belongs; this article did not measure it.
What to do next
- Decide what counts as a failure.
http_5xxcovers an outage; addhttp_429if the cloud provider’s own limits should also send traffic to the other instance. - Put the Consumer’s key behind the company’s identity provider instead: Keycloak and G8.
- Read how provider routing, token limits and prompt rules fit together on AI Gateway.