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.
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. The Streaming and Caller Response section explains the delay.
- Tool-using or function-calling requests. These requests are not supported. See Guardrails and Request Constraints for the supported request shape.
- 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 the behavior described in 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 every sub-call:
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 reflects this real cost, 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 Cloud, an environment with an attached gateway and permission to manage models and caller API keys.
- 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. AISIX Cloud references them by model ID. The open-source AISIX gateway references them by display_name in the declarative resources file.
AISIX Cloud
Export the AISIX Cloud connection details and the direct-model IDs:
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash.
# The local On-Premises quickstart uses http://localhost:8080/api.
export AISIX_CP="YOUR_AISIX_CLOUD_ADMIN_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"
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')
Add ENSEMBLE_MODEL_ID to the caller API key's allowed_models list.
You can also create and edit ensemble models on the dashboard Models page. The form provides a panel picker, a judge selector, and controls for sampling, minimum successful responses, and timeout.
Open-Source AISIX Gateway
Add the ensemble model to the models collection. Panel and judge references use direct model display_name values:
models:
- 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.
Configure Ensemble Behavior
Each panel member requires a direct-model reference and can set temperature or seed for that call. The same direct model can appear more than once, which enables a self-ensemble with different sampling settings. The optional weight field is reserved for a future voting strategy and has no effect today.
The judge requires a direct-model reference and can set a custom synthesis_prompt. The judge always runs at a fixed low temperature for stable synthesis.
min_responses controls how many panel calls must succeed before the judge runs. When omitted, AISIX requires the smaller of two responses and the panel size. AISIX Cloud rejects a value larger than the panel. In the open-source resources file, the runtime caps a larger value at the panel size. If fewer than the effective minimum succeed, the request fails rather than synthesizing from too little evidence.
timeout_ms is an optional per-call upstream deadline for each panel member and the judge. It applies in addition to the referenced direct model's own timeout. Set it to 0 or omit it to disable the ensemble-level deadline.
Tuning
Tune an ensemble by adjusting panel size, per-member sampling, the minimum number of successful responses, and the per-call timeout.
| Goal | Adjustment |
|---|---|
| Increase answer diversity | Use different panel models, 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. |