alibaba/spring-ai-alibaba · error · UnsupportedOperationException
不支持的模型提供商:
Error message
不支持的模型提供商:
What it means
createChatClient resolves a ChatClientFactory from chatClientFactories by provider name; if absent it logs a warning and falls back to the OpenAI factory. If even the OpenAI factory bean is missing, it throws this UnsupportedOperationException naming the provider. This indicates the Spring context lacks the fallback factory bean.
Solutions
- Check the provider value in the model config for typos and match it exactly to a registered factory (e.g., 'openai', 'dashscope')
- Ensure the OpenAI chat client factory bean is registered (include the corresponding dependency/starter and verify auto-configuration)
- Register a ChatClientFactory for the custom provider before creating clients
- Inspect chatClientFactories contents (via logs/debug) to confirm which providers are available at runtime
Example fix
// before (models.yml) provider: open-ai # no factory, and OpenAI fallback missing // after provider: openai # matches OpenAiChatClientFactory.OPEN_AI_PROVIDER
Defensive patterns
Strategy: fallback
Validate before calling
// Java: ensure a factory exists for the provider (or OpenAI fallback) before building
// (exposed via logs: '未找到提供商 {} 对应的工厂') — verify provider string matches a registered factory Type guard
boolean providerSupported(String provider, Map<String, ChatClientFactory> factories) {
return provider != null && (factories.containsKey(provider.toLowerCase())
|| factories.containsKey(OpenAiChatClientFactory.OPEN_AI_PROVIDER));
} Try / catch
try {
client = delegate.createChatClient(modelConfigId, params, metadata);
} catch (UnsupportedOperationException e) {
if (e.getMessage().startsWith("不支持的模型提供商")) {
log.error("Provider missing factory and OpenAI fallback unavailable: {}", e.getMessage());
}
} Prevention
- Keep the OpenAI factory dependency/starter on the classpath so the fallback always exists
- Validate the provider field against the supported provider list at config load time
- Register a ChatClientFactory for every custom provider used in the environment
When it happens
Trigger: Calling createChatClient with a config whose provider string has no registered ChatClientFactory AND the OpenAiChatClientFactory (OPEN_AI_PROVIDER) is not present in chatClientFactories — e.g., the OpenAI starter/auto-configuration is not on the classpath or the factory bean failed to register.
Common situations: Typo in the provider field of the model config (e.g., 'openAi ' with whitespace/case issues after toLowerCase); OpenAI factory excluded from the Spring context; running a trimmed deployment without the OpenAI client dependency while configs still reference non-OpenAI providers.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- 未找到提供商 对应的工厂,使用默认的 OpenAI 工厂
- 模型缺少 apiKey
- AppNotFound
- At least one fallback model must be specified
- At least one limit must be specified (threadLimit or…
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/3198eefff986fdfe.
Report an issue: GitHub.
Appendix: 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:101
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);
if (advisors != null) {
return ChatClient.builder(chatModel,observationRegistry,customObservationConvention,
new DefaultAdvisorObservationConvention()).defaultOptions(options).defaultAdvisors(advisors)
.build();
} else {
return ChatClient.builder(chatModel,observationRegistry,customObservationConvention
,new DefaultAdvisorObservationConvention()).defaultOptions(options).defaultAdvisors().build();
}
}
/**View on GitHub (pinned to f82da0b50f)