Ensemble Models
An ensemble model lets callers use one model alias while AISIX asks several panel models for candidate responses and then asks a judge model to synthesize the final answer. The caller sends one request and receives one answer under the requested alias. The fan-out and synthesis happen inside the gateway.
In AISIX, an ensemble is a model alias that AISIX resolves by calling multiple direct models, similar to routing groups and semantic routers. Instead of pointing to one upstream model directly, its ensemble configuration tells AISIX which direct models to call as panel members and which direct model to use as the judge.
An ensemble has two parts:
- Panel models produce independent candidate responses and are called concurrently.
- The judge model receives the successful panel responses and produces the single response returned to the caller.
Panel members and the judge must reference existing direct models. Configure provider credentials, upstream model names, health behavior, cooldown behavior, and sub-call rate limits on those direct models.
Panel members and the judge receive chat completions requests, so their provider must serve chat completions. AISIX Enterprise and AISIX Cloud reject a model whose provider does not, such as a model on a jina, runwayml, or typesafe provider key, as a member or judge. They also refuse to move a direct model that an ensemble references onto such a key. Decision models on a typesafe key are reached on /v1/systemone and /v1/decisions instead.
Use Cases and Tradeoffs
Ensembles trade extra model calls for an additional synthesis step. They can improve answer quality or consistency for some workloads, at the cost of higher latency and spend.
Use an ensemble when candidate diversity and a judging step are likely to help:
- Reduce single-model variance and surface blind spots. Independent candidates give the judge more evidence to compare.
- Cross-check hard reasoning or research prompts. Different models can reach an answer through different paths, and another candidate response can expose mistakes.
- Self-ensemble from one provider. A panel can be the same direct model repeated with different per-member
temperatureandseedvalues, so a team with a single provider key gets answer diversity without onboarding new vendors.
An ensemble does not guarantee a more accurate answer. Panel members can repeat the same error, agreement can be wrong, and the judge can select or introduce mistakes. Before using an ensemble in production, compare it with a direct-model baseline on a task-specific evaluation set. Include representative failure cases, and measure answer quality, latency, token use, and cost.
Because an ensemble sends one request to each panel member and then calls the judge, it is not a good fit for:
- Latency-critical or streaming-first paths. Time-to-first-token is high by construction. See Streaming and Caller Response.
- Tool-using or function-calling requests. These requests are not supported. See Guardrails and Request Constraints.
- High-volume, cost-sensitive traffic, where the evaluated benefit does not justify the extra spend.
- Endpoints other than chat completions. Ensembles are chat-only.
For those cases, use a direct model or a multi-target model instead. A multi-target model picks one target per request, while an ensemble calls all panel members and combines their output.
Request Flow
An ensemble request enters through one model alias. AISIX fans the request out to the configured panel, sends the successful panel responses to the judge, and returns only the judge's synthesized answer.
For each chat request, AISIX runs these phases:
- Fan out to the panel. AISIX dispatches the prompt to every panel member concurrently, applying each member's own
temperatureandseedoverride. - Collect successful responses. AISIX waits for the panel calls to finish or time out, keeps the successful answers, and checks whether their count satisfies
min_responses. Otherwise, the request follows Failure Handling. - Synthesize the final answer. AISIX builds a synthesis prompt from the original request and the collected answers, then calls the judge at a fixed low temperature. The judge's output is returned to the caller under the ensemble alias.
A single slow or failing panel member does not fail the request as long as min_responses is still met. Panel and judge calls use the retry budget configured on their referenced direct models.
Cost and Latency
An ensemble costs more and usually takes longer than a direct or multi-target model because each request can trigger several upstream calls.
Cost is the sum of the panel and judge sub-calls at their applicable prices:
ensemble cost ≈ sum(panel member costs) + judge cost
A three-member panel plus a judge processes the prompt four times, and the judge additionally processes all the panel answers. The caller-facing usage aggregates the panel and judge token counts, as described in Usage Accounting.
Latency is dominated by the slowest panel member plus the judge:
ensemble latency ≈ max(panel member latency) + judge latency
Because the judge cannot start until the panel returns, time-to-first-token is inherently high. There is no token to stream until synthesis begins.
Keep the panel small (two to four members), pick a fast judge, and set a timeout_ms so one stuck member cannot stall the whole request.
Prerequisites
Before starting, prepare the following:
- At least one direct model to use in the panel and one to use as the judge. The same direct model can fill both roles.
- A caller API key that can call the ensemble alias.
- For AISIX Enterprise or AISIX Cloud, an environment with an attached gateway. Dashboard users need permission to manage models and caller API keys. 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.
Configure an Ensemble Model
Create the direct panel and judge models before the ensemble model. The control plane references them by model ID. The open-source AISIX gateway references them by display_name in the declarative resources file.
- AISIX Enterprise or Cloud
- AISIX OSS
Create the ensemble from the prepared direct models, then grant caller access.
- Dashboard
- Admin API
Open the environment's Models page, select Create model, then choose Ensemble.
- Set Display name to
research-ensemble. - Under Panel members, add the two prepared panel models. Set their temp values to
0.7and0.9.

- Select the direct judge under Judge model.
- Set Min responses to
2and Per-call timeout (seconds) to30. These fields are visible in the main form.

- Select Create ensemble. Confirm the panel size and judge on the saved row.

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
research-ensembleunder 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.
Select Edit on the ensemble to change its configuration while retaining its identity and caller grant. Select Delete to remove it, then confirm the action.
Export the control-plane connection details and the direct-model IDs:
# 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 PANEL_A_MODEL_ID="YOUR_FIRST_PANEL_MODEL_ID"
export PANEL_B_MODEL_ID="YOUR_SECOND_PANEL_MODEL_ID"
export JUDGE_MODEL_ID="YOUR_JUDGE_MODEL_ID"
export API_KEY_ID="YOUR_CALLER_API_KEY_RESOURCE_ID"
Create the ensemble model and capture its ID:
ENSEMBLE_MODEL_ID=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/models" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"kind": "ensemble",
"display_name": "research-ensemble",
"ensemble": {
"panel": [
{
"model_id": "'"$PANEL_A_MODEL_ID"'",
"temperature": 0.7
},
{
"model_id": "'"$PANEL_B_MODEL_ID"'",
"temperature": 0.9
}
],
"judge": {
"model_id": "'"$JUDGE_MODEL_ID"'"
},
"min_responses": 2,
"timeout_ms": 30000
}
}' | jq -r '.model.id')
If the caller key uses all-model access, it already grants the new ensemble. Otherwise, read its current allowlist, append the ensemble ID, and write the complete list back:
curl -sS "$AISIX_CP/environments/$ENV_ID/api_keys" \
-H "Authorization: Bearer $AISIX_TOKEN" \
| jq -ec --arg key_id "$API_KEY_ID" --arg id "$ENSEMBLE_MODEL_ID" '
.data[] | select(.id == $key_id)
| {allowed_models: ((.allowed_models // []) + [$id] | unique)}' \
| curl -sS -X PATCH "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
--data-binary @- | jq
Add the ensemble model to the models collection. Panel and judge references use direct model display_name values:
models:
- id: 62aeffcf-1e2b-47ef-8cc5-8af013690615
display_name: research-ensemble
ensemble:
panel:
- model: gpt-4o-panel
temperature: 0.7
- model: claude-panel
temperature: 0.9
judge:
model: gpt-4o-judge
min_responses: 2
timeout_ms: 30000
The complete resources file must also contain the referenced direct models and their provider keys. Add research-ensemble to the caller key's allowed_models, then validate and reload the file.
Verify the Ensemble
Export the gateway URL and caller API key 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"
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
Call research-ensemble on the chat-completions endpoint:
curl -sS -X POST "$AISIX_PROXY/v1/chat/completions" \
-H "Authorization: Bearer $AISIX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "research-ensemble",
"messages": [
{
"role": "user",
"content": "In one sentence, what is an API gateway?"
}
]
}' \
| jq '{model, choices: (.choices | length), total_tokens: .usage.total_tokens}'
A successful response contains one synthesized answer under the ensemble alias:
{
"model": "research-ensemble",
"choices": 1,
"total_tokens": 508
}
The total_tokens value is the aggregate for the panel and judge calls.
Tune the Ensemble
Adjust the panel, sampling, success threshold, and timeout based on the outcome you need:
| Goal | Adjustment |
|---|---|
| Increase answer diversity | Use models from different providers, or spread panel temperature values such as 0.5, 0.7, and 0.9. |
| Reproducible runs | Set a per-member seed with the chosen temperature. |
| Diversity with one provider | Repeat the same model two or three times with different temperature and seed values. |
| Tolerate panel failures | Add one or two panel members and keep min_responses below the panel size, so one failed member does not fail the request. |
| Bound tail latency | Set timeout_ms to the acceptable per-call ceiling. Slow members are dropped, and the run proceeds if min_responses is still met. |
| Lower cost | Shrink the panel and choose a cheaper judge. Re-evaluate answer quality after either change. |
Each panel member can set temperature and seed. The same direct model can appear more than once. The optional weight field is reserved for a future voting strategy and has no effect today.
When min_responses is omitted, AISIX requires the smaller of two responses and the panel size. The Admin API rejects a value larger than the panel; AISIX OSS caps it at the panel size. If fewer responses succeed, the request fails without calling the judge.
timeout_ms sets a per-call deadline for every panel member and the judge, in addition to each direct model's own timeout. Set it to 0 or omit it to disable this ensemble-level deadline.
Judge Synthesis
The judge receives the original request and the successful panel answers as one message. Candidate answers are labeled neutrally (Answer 1, Answer 2, and so on) and do not include panel model names. This keeps the operator's provider and model choices out of the synthesized response.
Each candidate answer is capped before it reaches the judge, so a long panel cannot overflow the judge's context window. Oversized answers are truncated, not dropped.
The default synthesis instructions tell the judge to treat the candidates as evidence, favor consensus, resolve contradictions by reasoning, discard unsupported claims, and return only the final answer. These are generation instructions, not an independent check of whether a claim is correct. The response uses the same language and format the user asked for and does not mention that multiple models were involved.
Customize the Judge Prompt
A custom synthesis prompt replaces the default instructions and can include the same {original_request} and {labeled_candidates} substitutions.
- AISIX Enterprise or Cloud
- AISIX OSS
The dashboard has no synthesis-prompt editor, but it retains a prompt configured through the Admin API during later dashboard edits. When creating or updating the ensemble through the Admin API, add synthesis_prompt beside the judge's model_id:
{
"ensemble": {
"judge": {
"model_id": "YOUR_JUDGE_MODEL_ID",
"synthesis_prompt": "Review the candidates for correctness, security, and edge cases. Return only the final answer.\n\nRequest:\n{original_request}\n\nCandidates:\n{labeled_candidates}"
}
}
}
Add synthesis_prompt beside the judge's model name in the ensemble entry:
{
"ensemble": {
"judge": {
"model": "model-a",
"synthesis_prompt": "Review the candidates for correctness, security, and edge cases. Return only the final answer.\n\nRequest:\n{original_request}\n\nCandidates:\n{labeled_candidates}"
}
}
}
A custom synthesis prompt that omits {original_request} or {labeled_candidates} does not receive that content. Include both placeholders when the judge needs the original request and the candidate answers.
Next Steps
See Ensemble Runtime Behavior for streaming, accounting, limits, and failure rules. Use Proxy Errors and Retries to understand caller-facing failures.