alibaba/spring-ai-alibaba · critical · RuntimeException
All models failed after ${fallbackModels.size() + 1} attempt
Error message
All models failed after ${fallbackModels.size() + 1} attempts What it means
ModelFallbackInterceptor tried the primary model (the intercepted handler) and every configured fallback ChatModel, and all of them threw. It exhausts the chain and rethrows a RuntimeException whose message reports the total attempt count (fallbackModels.size() + 1) with the last failure as the cause. The real root cause is in the suppressed cause chain of the last model's exception.
Source
Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/interceptor/modelfallback/ModelFallbackInterceptor.java:100
for (int i = 0; i < fallbackModels.size(); i++) {
ChatModel fallbackModel = fallbackModels.get(i);
try {
log.info("Trying fallback model {} of {}", i + 1, fallbackModels.size());
// Call the fallback model directly
Prompt prompt = new Prompt(request.getMessages(), request.getOptions());
var response = fallbackModel.call(prompt);
return ModelResponse.of(response.getResult().getOutput());
}
catch (Exception e) {
log.warn("Fallback model {} failed: {}", i + 1, e.getMessage());
lastException = e;
}
}
// All models failed
throw new RuntimeException("All models failed after " + (fallbackModels.size() + 1) + " attempts", lastException);
}
@Override
public String getName() {
return "ModelFallback";
}
public static class Builder {
private final List<ChatModel> fallbackModels = new ArrayList<>();
public Builder addFallbackModel(ChatModel model) {
this.fallbackModels.add(model);
return this;
}
public Builder fallbackModels(List<ChatModel> models) {
this.fallbackModels.addAll(models);
return this;View on GitHub (pinned to f82da0b50f)
Solutions
- Inspect the cause chain (getCause()/lastException) of this RuntimeException to find the actual per-model failure and fix that root issue first.
- Verify each fallback model's credentials, base URL, model name, and quota independently — test each ChatModel with a trivial 'ping' call at startup.
- Add fallbacks from a different provider or deployment region so a single outage does not take down the whole chain.
- Check the intercepted response text: if it contains 'Exception:' it is treated as failure — make sure the primary handler is not returning error text for benign reasons.
Example fix
// before: all fallbacks share one key/provider
ModelFallbackInterceptor.builder()
.addFallbackModel(dashScopeMini)
.addFallbackModel(dashScopeTurbo)
.build();
// after: diversify providers
ModelFallbackInterceptor.builder()
.addFallbackModel(openAiGpt4oMini)
.addFallbackModel(deepseekChat)
.build(); Defensive patterns
Strategy: fallback
Validate before calling
List<ChatModel> fallbacks = builderModels;
if (fallbacks.isEmpty()) throw new IllegalStateException("Configure at least one fallback model");
fallbacks.forEach(m -> {
try { m.call(new Prompt("ping")); } catch (Exception e) { throw new IllegalStateException("Fallback model unhealthy: " + e.getMessage(), e); }
}); Try / catch
try {
return agentCall();
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("All models failed after")) {
log.error("All models exhausted; root cause: {}", e.getCause(), e.getCause());
return degradedResponse(); // serve cached/stub answer, alert ops
}
throw e;
} Prevention
- Diversify fallback models across providers/regions, not just model names on one provider.
- Health-check every configured ChatModel at application startup.
- Monitor per-model failure rates so you see degradation before full exhaustion.
When it happens
Trigger: Calling ModelFallbackInterceptor.interceptModel(request, handler) when handler.call(request) throws (or returns text containing 'Exception:') and every fallbackModel.call(prompt) also throws — e.g. all endpoints down, all API keys invalid/quota-exhausted, or a shared network outage.
Common situations: Provider-wide outages or rate limiting hitting primary and fallbacks from the same account; misconfigured base URLs or expired API keys shared across all configured models; fallback models pointing at the same unavailable cluster as the primary; regional network blocking of all provider endpoints.
Related errors
- Model call failed, maximum number of retries reached:${excep
- Model call failed, maximum number of retries reached.
- Model call failed, maximum number of retries reached. ${maxA
- Failed to subscribe
- Oauth2CallError
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/a881c619430ba410.
Report an issue: GitHub.