OtterMind/Chat2DB · error · IllegalArgumentException
model is required
Error message
model is required
What it means
Thrown as IllegalArgumentException('model is required') by AiModelConfigServiceImpl.validateRuntimeModel when runtimeModel.getModel() is blank. Like error 56 it is a raw IllegalArgumentException (not i18n-handled). It fires after the provider check passes but before the provider enum lookup.
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:361
}
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)) {
return;
}
try {View on GitHub (pinned to 5ee1e990e7)
Solutions
- Set a concrete model id (e.g. 'gpt-4o', 'claude-3-5-sonnet') on the saved config or the resolve request.
- Validate that the model field is non-blank before persisting an AiModelConfig.
- Guard resolveRuntimeModel to throw a BusinessException describing the missing model before validateRuntimeModel.
Example fix
// before
resolve.setProvider("OPENAI"); resolve.setApiKey(key); // model blank
// after
resolve.setProvider("OPENAI");
resolve.setModel("gpt-4o");
resolve.setApiKey(key); Defensive patterns
Strategy: validation
Validate before calling
AiRuntimeModel m = /* built */;
if (StringUtils.isBlank(m.getModel())) {
throw new IllegalArgumentException("model is required before validate");
} Type guard
static boolean hasModel(AiRuntimeModel m) {
return m != null && !StringUtils.isBlank(m.getModel());
} Try / catch
try {
service.validateRuntimeModel(m);
} catch (IllegalArgumentException e) {
if ("model is required".equals(e.getMessage())) {
return ResponseEntity.badRequest().body("set a concrete model id");
}
throw e;
} Prevention
- Always set a concrete model id on configs and resolve requests.
- Validate the model field before persisting a config.
- Note these are raw IllegalArgumentExceptions, not i18n BusinessException.
When it happens
Trigger: The resolved AiRuntimeModel has a null/blank model string. Reachable when both the request and the base config omitted model, or a saved config has a null model field, and validateRuntimeModel is then called.
Common situations: A model config saved with provider+apiKey but no model identifier; a request that sends provider only expecting the model to come from somewhere it did not; programmatic AiRuntimeModel construction skipping setModel.
Related errors
- provider 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/3edbb54bc9d269ec.
Report an issue: GitHub.