alibaba/spring-ai-alibaba · error · RuntimeException
模型配置已禁用:
Error message
模型配置已禁用:
What it means
After locating the model config, createChatClient checks config.getStatus() != 1 and throws this RuntimeException when the model is disabled (any status other than 1, which means enabled). Disabled models must not be used to create chat clients, so the call is rejected.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/client/ChatClientFactoryDelegate.java:89
return createChatClient(modelConfigId, userParameters, null, observationMetadata);
}
public ChatClient createChatClient(Long modelConfigId, Map<String, Object> userParameters, List<Advisor> advisors, Map<String, String> observationMetadata) {
// 优先从桥接服务查找(从Manager层查询)
ModelConfigDO config = modelConfigBridgeService.findById(modelConfigId);
// 如果桥接服务中找不到,尝试从ModelConfigRepository查找(保持向后兼容)
if (config == null) {
log.debug("桥接服务中未找到模型配置 id={},尝试从 ModelConfigRepository 查找", modelConfigId);
config = modelConfigRepository.findById(modelConfigId);
}
if (config == null) {
throw new RuntimeException("模型配置不存在: " + modelConfigId);
}
if (config.getStatus() != 1) {
throw new RuntimeException("模型配置已禁用: " + modelConfigId);
}
String provider = config.getProvider().toLowerCase();
log.info("创建模型客户端,提供商: {}, 模型: {}", provider, config.getModelName());
ChatClientFactory factory = chatClientFactories.get(provider);
if (factory == null) {
// 如果找不到对应的 provider factory,默认使用 OpenAI
log.warn("未找到提供商 {} 对应的工厂,使用默认的 OpenAI 工厂", provider);
factory = chatClientFactories.get(OpenAiChatClientFactory.OPEN_AI_PROVIDER);
if (factory == null) {
throw new UnsupportedOperationException("不支持的模型提供商: " + config.getProvider() + ",且默认的 OpenAI 工厂也不可用");
}
}
ChatModel chatModel = factory.buildChatModel(config);
Map<String, Object> mergedParameters = mergeParameters(config, userParameters);
ChatOptions options = factory.buildChatOptions(config, mergedParameters, observationMetadata);View on GitHub (pinned to f82da0b50f)
Solutions
- Re-enable the model: set status: 1 in the models YAML or toggle it on in the admin UI
- Choose a different, enabled model config id for the session or request
- Refresh sessions that cached the disabled config so they resolve the updated status
- Add pre-checks in calling code (config.getStatus() == 1) to fail gracefully instead of at client creation
Example fix
// before (models.yml) - id: 1 name: qwen-max status: 0 // after - id: 1 name: qwen-max status: 1
Defensive patterns
Strategy: validation
Validate before calling
// Java: verify enabled status before creating a client
ModelConfigDO cfg = modelConfigRepository.findById(modelConfigId);
if (cfg == null || cfg.getStatus() == null || cfg.getStatus() != 1) {
throw new IllegalStateException("Model " + modelConfigId + " is missing or disabled");
} Type guard
boolean isEnabled(ModelConfigDO c) { return c != null && Integer.valueOf(1).equals(c.getStatus()); } Try / catch
try {
client = delegate.createChatClient(modelConfigId, params, metadata);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("模型配置已禁用")) {
// fall back to another enabled model or surface a user-facing message
}
} Prevention
- Cache-free re-check of status before each client creation; don't persist status snapshots
- Notify/refresh sessions when an admin disables a model
- Maintain at least one always-enabled fallback model per environment
When it happens
Trigger: Calling createChatClient for a modelConfigId whose config record has status set to 0 (disabled) in the YAML file or the model config store.
Common situations: An admin disabled the model in the admin UI while sessions still reference it; a YAML entry has status: 0; a model was temporarily disabled for cost/quota reasons but old code paths still use it.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- 模型缺少 apiKey
- 序列化 defaultParameters 失败
- 序列化 supportedParameters 失败
- 模型配置不存在:
- Cannot delete published version:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/9983987fca960ca9.
Report an issue: GitHub.