alibaba/spring-ai-alibaba · error · IllegalArgumentException
重复的模型 id:
Error message
重复的模型 id:
What it means
validateYamlModel enforces that every model entry in the YAML file has a unique id, using an ids Set: if Set.add(m.id) returns false, the id was already used and this IllegalArgumentException is thrown. Duplicate ids would make id-based lookups (findById) ambiguous, so loading is aborted.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/FileModelConfigRepository.java:132
private void validateYamlModel(YamlModel m, Set<Long> ids, Set<String> names) {
if (m.id == null) {
throw new IllegalArgumentException("模型缺少 id");
}
if (m.name == null || m.name.isBlank()) {
throw new IllegalArgumentException("模型缺少 name");
}
if (m.provider == null || m.provider.isBlank()) {
throw new IllegalArgumentException("模型缺少 provider");
}
if (m.modelName == null || m.modelName.isBlank()) {
throw new IllegalArgumentException("模型缺少 modelName");
}
// if (m.baseUrl == null || m.baseUrl.isBlank()) throw new IllegalArgumentException("模型缺少 baseUrl");
if (m.apiKey == null || m.apiKey.isBlank()) {
throw new IllegalArgumentException("模型缺少 apiKey");
}
if (!ids.add(m.id)) {
throw new IllegalArgumentException("重复的模型 id: " + m.id);
}
if (!names.add(m.name)) {
throw new IllegalArgumentException("重复的模型 name: " + m.name);
}
if (m.status == null) {
m.status = 1;
}
}
private ModelConfigDO toEntity(YamlModel m) {
ModelConfigDO.ModelConfigDOBuilder b = ModelConfigDO.builder().id(m.id).name(m.name)
.provider(m.provider.toLowerCase()).modelName(m.modelName).baseUrl(m.baseUrl)
.apiKey(environment != null ? environment.resolvePlaceholders(m.apiKey) : m.apiKey).status(m.status)
.createTime(LocalDateTime.now()).updateTime(LocalDateTime.now());
if (m.defaultParameters != null) {
try {
b.defaultParameters(new ObjectMapper().writeValueAsString(m.defaultParameters));View on GitHub (pinned to f82da0b50f)
Solutions
- Open the models YAML and give each entry a distinct numeric id
- Search the file for the duplicated id reported in the message and rename/remove one occurrence
- If generating entries programmatically, ensure the id generator/increment is applied per entry
- Restart or trigger reload after fixing so startWatchService picks up the corrected file
Example fix
// before (models.yml)
models:
- id: 1
name: qwen-max
- id: 1
name: deepseek-v3
// after
models:
- id: 1
name: qwen-max
- id: 2
name: deepseek-v3 Defensive patterns
Strategy: validation
Validate before calling
// Java: pre-validate ids before writing the YAML
Set<Object> seen = new HashSet<>();
for (var m : models) {
if (!seen.add(m.getId())) {
throw new IllegalStateException("Duplicate model id in config: " + m.getId());
}
} Type guard
boolean isUniqueId(m, Set<Object> seen) { return m != null && m.getId() != null && seen.add(m.getId()); } Try / catch
try {
repository.loadFromFile(path);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("重复的模型 id")) {
log.error("Fix duplicate model id in {}: {}", path, e.getMessage());
}
} Prevention
- Generate ids programmatically with an auto-increment or UUID instead of hand-editing
- When copy-pasting model blocks, always update id first
- Lint the models YAML in CI for duplicate ids/names before deployment
When it happens
Trigger: Calling loadFromFile when two or more model entries in the YAML share the same id value.
Common situations: Copy-pasting an existing model block to add a new model and forgetting to change the id; merging config files from two environments; a bad manual edit or a file watcher reload picking up a partially merged file.
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
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/1fd5af451f5c422b.
Report an issue: GitHub.