OtterMind/Chat2DB · error · IllegalArgumentException
provider is required
Error message
provider is required
What it means
Thrown as IllegalArgumentException('provider is required') by AiModelConfigServiceImpl.validateRuntimeModel when runtimeModel.getProvider() is null. This is a raw IllegalArgumentException, not a BusinessException, so it bypasses the i18n BusinessException handler. It indicates the resolved AiRuntimeModel was constructed without a provider.
Source
Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ai/AiModelConfigServiceImpl.java:358
runtimeModel.setBaseUrl(defaultValue(trimToNull(runtimeModel.getBaseUrl()), trimToNull(System.getenv("MINIMAX_BASE_URL"))));
runtimeModel.setBaseUrl(defaultValue(trimToNull(runtimeModel.getBaseUrl()), DEFAULT_MINIMAX_BASE_URL));
return;
}
if (provider == AiProviderEnum.CLAUDE) {
runtimeModel.setApiKey(defaultValue(trimToNull(runtimeModel.getApiKey()), trimToNull(System.getenv("ANTHROPIC_API_KEY"))));
runtimeModel.setBaseUrl(defaultValue(trimToNull(runtimeModel.getBaseUrl()), trimToNull(System.getenv("ANTHROPIC_BASE_URL"))));
return;
}
if (provider == AiProviderEnum.GEMINI) {
runtimeModel.setProjectId(defaultValue(trimToNull(runtimeModel.getProjectId()), trimToNull(System.getenv("GOOGLE_CLOUD_PROJECT"))));
runtimeModel.setLocation(defaultValue(trimToNull(runtimeModel.getLocation()), trimToNull(System.getenv("GOOGLE_CLOUD_LOCATION"))));
runtimeModel.setLocation(defaultValue(runtimeModel.getLocation(), DEFAULT_GEMINI_LOCATION));
}
}
private void validateRuntimeModel(AiRuntimeModel runtimeModel) {
if (Objects.isNull(runtimeModel.getProvider())) {
throw new IllegalArgumentException("provider is required");
}
if (StringUtils.isBlank(runtimeModel.getModel())) {
throw new IllegalArgumentException("model is required");
}
AiProviderEnum provider = AiProviderEnum.from(runtimeModel.getProvider());
if (provider == null) {
throw new IllegalArgumentException("Unsupported provider: " + runtimeModel.getProvider());
}
if (provider == AiProviderEnum.OPENAI || provider == AiProviderEnum.CLAUDE) {
return;
}
if (provider == AiProviderEnum.GEMINI) {
}
}
private synchronized void loadFromDisk() {
if (!Files.exists(storagePath)) {View on GitHub (pinned to 5ee1e990e7)
Solutions
- Ensure the saved model config (or the resolve request) has a non-null provider (OPENAI, CLAUDE, GEMINI, or MINIMAX).
- Audit the AiModelConfig record that produced the null provider and fix its provider field.
- Guard resolveRuntimeModel to fail with a clearer BusinessException before reaching validateRuntimeModel.
Example fix
// before: config saved with null provider
AiModelConfig cfg = new AiModelConfig();
cfg.setModel("gpt-4o"); cfg.setApiKey(key); // provider missing
configService.save(cfg);
// after
AiModelConfig cfg = new AiModelConfig();
cfg.setProvider(AiProviderEnum.OPENAI.name());
cfg.setModel("gpt-4o"); cfg.setApiKey(key);
configService.save(cfg); Defensive patterns
Strategy: validation
Validate before calling
AiRuntimeModel m = /* built */;
if (m.getProvider() == null) {
throw new IllegalArgumentException("provider is required before validate");
} Type guard
static boolean hasProvider(AiRuntimeModel m) {
return m != null && m.getProvider() != null;
} Try / catch
try {
service.validateRuntimeModel(m);
} catch (IllegalArgumentException e) {
if ("provider is required".equals(e.getMessage())) {
return ResponseEntity.badRequest().body("set a provider (OPENAI/CLAUDE/GEMINI/MINIMAX)");
}
throw e;
} Prevention
- Always set provider when building or saving an AiModelConfig/AiRuntimeModel.
- Validate provider presence before persisting a config.
- Treat a null provider in a saved config as corrupt data and fix it.
When it happens
Trigger: validateRuntimeModel receives an AiRuntimeModel whose provider is null. Reachable when resolveRuntimeModel built a runtimeModel from a config/request that left provider null after defaultValue merging, or when validateRuntimeModel is called directly with an incomplete model.
Common situations: A saved AiModelConfig has a null provider (corrupt or hand-built config); the resolve request and the base config both lacked a provider so defaultValue(null,null)=null; programmatic construction of AiRuntimeModel without setting provider.
Related errors
- model is required
- ai.model.config.required
- Unsupported provider:
- The baseURL is not valid!
- The baseURL is not valid!
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/14cf6451e807bc3d.
Report an issue: GitHub.