Multi-Target Routing and Failover
A multi-target model exposes one caller-facing alias for several direct models. AISIX selects a target for each request and can retry or fail over without requiring the application to change model names.
Each target keeps its own provider key and upstream model name. Callers see only the routing alias, including in GET /v1/models. Grant a caller access to the alias alone when the targets should remain an implementation detail.
The routing model selects a direct target, and that target uses its provider key to call the upstream model:
Choose a Strategy
Choose a strategy based on how the caller-facing alias should distribute traffic:
| Goal | Strategy | Selection Behavior |
|---|---|---|
| Keep a primary target with ordered backups. | failover | Attempts targets in declaration order. |
| Rotate traffic across similar targets, optionally by share. | round_robin | Smooth weighted round-robin over target weights. Equal or absent weights rotate in declaration order. |
| Pin each session to one target. | consistent_hash | Hashes a per-request key over a weighted ring. See canary traffic and session-affine pools. |
| Prefer the lowest estimated price. | least_cost | Ranks eligible targets by configured prices or control-plane catalog pricing. |
| Prefer the fastest recently observed target. | least_latency | Ranks eligible targets by recent upstream latency. |
| Prefer the target with the lowest weighted concurrency. | least_busy | Ranks eligible targets by (1 + current in-flight requests) / max(weight, 1), lowest first. |
Failover is the default strategy. Two target settings refine any strategy:
| Setting | Effect |
|---|---|
weight | Controls the rotation share for round_robin, the hash-ring share for consistent_hash, and the weighted concurrency score for least_busy. The default is 1. Other strategies ignore it. |
priority | Splits targets into tiers. Higher values are preferred; use -1 for backups. The default is 0. See Pin Sessions with Pool Failover. |
AISIX applies routing tags and allowed_cidrs before it evaluates priority. A lower-priority target can serve a request when those filters exclude every higher-priority target.
Configure and Test a Failover Model
The following example builds and tests a two-target model that keeps gpt-4o-primary as its preferred target and uses gpt-4o-secondary after an eligible failure. Instructions are provided for AISIX Enterprise, AISIX Cloud, and AISIX OSS.
Prerequisites
Before starting, prepare the following:
- Two or more direct models to use as routing targets. To run the failure test, the primary and secondary models must use separate provider-key resources, although both resources can contain the same upstream credential.
- A caller API key that can call the multi-target model, or permission to create one.
- cURL for verification requests. If you use the Admin API to configure AISIX Enterprise or AISIX Cloud, or run the optional status queries, also install jq.
- For AISIX Enterprise or AISIX Cloud, an environment with an attached gateway. Dashboard users need permission to manage models and caller API keys, plus provider keys for the failure simulation. AISIX Cloud Admin API users need a write-scoped admin token.
- For the open-source AISIX gateway, access to the declarative resources file and the gateway process.
Create the Model
Create the direct target models before the multi-target model. Every management path below configures the same behavior: AISIX starts with the primary target and moves to the secondary target after a retryable failure.
- AISIX Enterprise or Cloud
- AISIX OSS
Create the model group and allow the caller in the same environment.
- Dashboard
- Admin API
Open the environment's Models page, select Create model, then choose Model group.
- Set Display name to
chat-prodand Strategy to Failover. - Under Targets, add
gpt-4o-primaryfirst andgpt-4o-secondarysecond. Drag the rows to correct the order if needed.

- Expand Reliability — retries and fallback budget (optional). Set Retries to
1and Max fallbacks to1. Select Include upstream 429 in retries + failover.

- Select Create model group and confirm that the saved row shows the intended strategy and target order.

An existing caller key with all-model access already grants the new alias. Otherwise:
- Open API keys in the same environment.
- Select Edit for an existing caller whose plaintext you have saved, or select New API key and enter a display name.
- Keep Selected models and select
chat-produnder Allowed models, retaining any other required models.

Finish the key according to the path you chose:
- For an existing key, select Save changes.
- For a new key, select Create API key, copy its plaintext from One-time view, then select I've saved it.
Export the caller credential for verification:
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
To adjust the group later, select Edit on its row. Saving strategy, target, order, or reliability changes keeps the resource and its caller grant. To retire the alias, select Delete and confirm the action.
Set the control-plane URL, admin token, and environment ID for your AISIX organization:
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash
# The local AISIX Enterprise quickstart uses http://localhost:8080/api
export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"
export AISIX_TOKEN="YOUR_ADMIN_TOKEN"
export ENV_ID="YOUR_ENVIRONMENT_ID"
Export the IDs of the direct target models:
export PRIMARY_MODEL_ID="YOUR_PRIMARY_MODEL_ID"
export SECONDARY_MODEL_ID="YOUR_SECONDARY_MODEL_ID"
Create a failover model that starts with the primary target and falls back to the secondary target:
ROUTING_MODEL_ID=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/models" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"kind": "routing",
"display_name": "chat-prod",
"routing": {
"strategy": "failover",
"targets": [
{"model_id": "'"$PRIMARY_MODEL_ID"'"},
{"model_id": "'"$SECONDARY_MODEL_ID"'"}
],
"retries": 1,
"max_fallbacks": 1,
"retry_on_429": true
}
}' | jq -r '.model.id')
With this configuration, AISIX can retry the primary target once, then fail over once to the secondary target.
The captured model ID supports later grants, updates, inspection, and deletion. To grant an existing caller access, append the ID to the caller key's complete allowlist.
For a quick check, create a caller API key that can call only chat-prod:
KEY_RESPONSE=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"display_name": "routing-guide-caller",
"allowed_models": ["'"$ROUTING_MODEL_ID"'"]
}')
export AISIX_API_KEY=$(echo "$KEY_RESPONSE" | jq -r '.plaintext')
API_KEY_ID=$(echo "$KEY_RESPONSE" | jq -r '.api_key.id')
The plaintext caller key is returned only once. The commands save it for the verification request and save the key ID for later allowlist updates. The model and caller key configurations are projected to attached gateways automatically.
Add two provider keys, their direct models, and the routing model to the complete resources file. Keeping the provider keys separate lets you test one target without changing the other:
provider_keys:
- id: 3f17e0b9-0e22-429c-a865-648fa08d3547
display_name: openai-primary
provider: openai
adapter: openai
api_key: ${OPENAI_API_KEY}
- id: a31c8d13-0ced-4215-bd0c-b545e0032199
display_name: openai-secondary
provider: openai
adapter: openai
api_key: ${OPENAI_API_KEY}
models:
- id: 37df1690-9e1a-4742-84bf-423c8e1930b9
display_name: gpt-4o-primary
provider: openai
model_name: gpt-4o
provider_key_id: 3f17e0b9-0e22-429c-a865-648fa08d3547
- id: afd377e7-aeab-432e-844f-9ac7dd7822da
display_name: gpt-4o-secondary
provider: openai
model_name: gpt-4o-mini
provider_key_id: a31c8d13-0ced-4215-bd0c-b545e0032199
- id: 44e74cd2-b929-456f-812b-fea3124fc945
display_name: chat-prod
routing:
strategy: failover
targets:
- model: gpt-4o-primary
- model: gpt-4o-secondary
retries: 1
max_fallbacks: 1
retry_on_429: true
Add the routing alias to the caller key's allowlist, then validate and reload the assembled file.
Verify Primary Routing
Export the gateway URL for the deployment you configured:
# Use the gateway origin without a trailing slash or endpoint path.
# The local quickstarts use http://127.0.0.1:3000
export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
For AISIX Enterprise or AISIX Cloud, continue using the AISIX_API_KEY exported or created earlier. For the open-source AISIX gateway, export the caller API key:
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
Send a request to the multi-target alias:
curl -sSi -X POST "$AISIX_PROXY/v1/chat/completions" \
-H "Authorization: Bearer ${AISIX_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "chat-prod",
"messages": [
{"role": "user", "content": "Hello from AISIX routing."}
]
}'
A successful request starts with HTTP/1.1 200 OK. The response body retains chat-prod as the caller-facing model name, so by default the response does not tell the caller which target served it. To see the target, copy the x-aisix-request-id response header value and find the request's line in the gateway's access log. Its served_by_model field reports gpt-4o-primary. With the open-source quickstart container:
docker logs aisix-quickstart 2>&1 | grep "YOUR_REQUEST_ID"
On a test gateway, you can instead set proxy.expose_debug_headers to true in its startup configuration and restart it. The response then also includes x-aisix-served-by: gpt-4o-primary. The header identifies the direct model that served the request and is not present on cache hits, single-target model responses, error responses, or endpoints other than /v1/chat/completions.
Streaming requests can resolve multi-target aliases, but they do not fail over after a stream has started.
Simulate a Primary Failure
After the normal request reaches gpt-4o-primary, make that target unreachable and repeat the request. For this test, the primary and secondary direct models must use different provider keys so changing the primary endpoint does not also affect the fallback.
Use a dedicated non-production provider key for the primary target. In AISIX Enterprise and AISIX Cloud, a provider key is organization-scoped, and changing its endpoint affects every model that references it.
- AISIX Enterprise or Cloud
- AISIX OSS
Change only the dedicated primary provider key so the secondary target remains available.
- Dashboard
- Admin API
- Open Provider keys and select Edit on the test key used only by
gpt-4o-primary. - Record the existing API base, then replace it with
https://api.openai.invalid/v1.

- Select Save. Confirm that the gateway has applied the latest configuration revision before repeating the request. See Resource Projection.
Export the ID of the provider key used only by the primary target, then save its current endpoint:
export PRIMARY_PROVIDER_KEY_ID="YOUR_PRIMARY_PROVIDER_KEY_ID"
PRIMARY_API_BASE=$(curl -sS \
"$AISIX_CP/provider_keys/$PRIMARY_PROVIDER_KEY_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" \
| jq -r '.provider_key.api_base // ""')
Point the provider key to a reserved, unreachable domain:
curl -sS -X PATCH \
"$AISIX_CP/provider_keys/$PRIMARY_PROVIDER_KEY_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{"api_base":"https://api.openai.invalid/v1"}'
The control plane projects the update to every environment allowed to use the provider key. Before sending the test request, confirm that the target gateway has applied the latest configuration. See Resource Projection for the control-plane revision and gateway-status checks.
In the complete resources.yaml, replace the existing openai-primary provider key entry with the following block to change only its endpoint. Preserve the other entries and collections:
provider_keys:
- id: 3f17e0b9-0e22-429c-a865-648fa08d3547
display_name: openai-primary
provider: openai
adapter: openai
api_key: ${OPENAI_API_KEY}
api_base: https://api.openai.invalid/v1
If you followed the open-source quickstart, validate and reload the file with its existing container:
docker exec aisix-quickstart \
/usr/local/bin/aisix validate --resources /etc/aisix/resources.yaml
docker kill --signal=HUP aisix-quickstart
Use your gateway container name and resources-file path if they differ from the quickstart. If the reload fails, the gateway keeps serving the last valid configuration. Confirm that GET /status/config reports a successful reload before sending the test request.
Verify Failover
Repeat the request from Verify Primary Routing. It should still return HTTP/1.1 200 OK, but the access log should now report served_by_model as gpt-4o-secondary. With debug headers enabled, the response also includes:
x-aisix-served-by: gpt-4o-secondary
The response body still identifies the caller-facing routing alias.
Restore Primary Routing
- AISIX Enterprise or Cloud
- AISIX OSS
- Dashboard
- Admin API
Edit the primary test provider key and restore its recorded API base. Clear the field if it was originally empty, then select Save.

Restore the saved endpoint:
jq -n --arg api_base "$PRIMARY_API_BASE" '{api_base: $api_base}' \
| curl -sS -X PATCH \
"$AISIX_CP/provider_keys/$PRIMARY_PROVIDER_KEY_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
--data-binary @-
Confirm that the restored configuration reaches the gateway.
Restore or remove the test api_base override, then validate and reload the complete resources file again.
Repeat the request and confirm that served_by_model, or x-aisix-served-by when it is enabled, identifies gpt-4o-primary again. If you enabled cooldown on the primary target, it stays out of rotation until its current cooldown period expires, so wait for it to report healthy again first.
Next Steps
Use Multi-Target Routing Patterns for cost-aware selection, canary traffic, session-affine pools, and request tags. See Multi-Target Runtime Behavior for endpoint support and retry rules. Continue with Semantic Routing when target selection should depend on request meaning.