alibaba/spring-ai-alibaba · error · IllegalArgumentException

模型配置不存在: modelId=

Error message

模型配置不存在: modelId=

What it means

An IllegalArgumentException thrown by ModelConfigParser.checkAndGetModelConfigInfo when, after checking the config JSON and any ModelManager lookups (by id, by name), no matching ModelEntity can be found. The config parses fine but references a model that does not exist in the current workspace's model registry.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/utils/ModelConfigParser.java:89

                
                ModelEntity modelEntity = null;
                
                // 1. 首先尝试通过 modelId (Long) 作为 ModelEntity 的 id 查找
                if (modelConfigInfo.getModelId() != null) {
                    modelEntity = modelManager.findModelByIdOrName(modelConfigInfo.getModelId(), workspaceId);
                }
                
                // 2. 如果通过 modelId 找不到,尝试通过 modelName 查找
                if (modelEntity == null) {
                    String modelName = (String) modelConfigInfo.getParameter("modelName");
                    if (StringUtils.hasText(modelName)) {
                        modelEntity = modelManager.findModelByIdOrName(modelName, workspaceId);
                    }
                }
                
                // 3. 如果还是找不到,抛出异常
                if (modelEntity == null) {
                    throw new IllegalArgumentException("模型配置不存在: modelId=" + modelConfigInfo.getModelId() + 
                        (modelConfigInfo.getParameter("modelName") != null ? ", modelName=" + modelConfigInfo.getParameter("modelName") : ""));
                }
                
                // 如果从 ModelManager 找到了模型,更新 modelConfigInfo 的 modelId 为 ModelEntity 的 id
                log.info("从 ModelManager 找到模型: id={}, name={}, modelId={}, workspaceId={}", 
                    modelEntity.getId(), modelEntity.getName(), modelEntity.getModelId(), workspaceId);
                
                // 更新 modelId 为 ModelEntity 的 id,确保后续使用正确的 id
                modelConfigInfo.setModelId(modelEntity.getId());
            }
        } catch (Exception e) {
            log.error("解析模型配置失败: modelConfig={}", modelConfig, e);
            throw new RuntimeException("模型配置解析失败: " + e.getMessage(), e);
        }
        return modelConfigInfo;
    }
    
    /**

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Verify the modelId/modelName exists via ModelManager.findModelByIdOrName in the target workspace and correct the config.
  2. Re-select the model in the prompt/agent editor so the stored modelConfig points at an existing model.
  3. Check the workspaceId being passed — the model may exist in a different workspace.
  4. Register the referenced model in the environment before running the flow.

Example fix

// before
String cfg = "{\"modelId\":\"deleted-model-id\"}";
ModelConfigInfo info = parser.checkAndGetModelConfigInfo(cfg); // IAE
// after
if (modelManager.findModelByIdOrName("qwen-max", workspaceId) != null) {
    String cfg = "{\"modelId\":\"qwen-max\"}";
    ModelConfigInfo info = parser.checkAndGetModelConfigInfo(cfg);
}
Defensive patterns

Strategy: validation

Validate before calling

ModelEntity m = modelManager.findModelByIdOrName(modelId, workspaceId);
if (m == null) throw new BadRequestException("model " + modelId + " not found in workspace " + workspaceId);

Type guard

boolean modelExists = modelManager.findModelByIdOrName(id, workspaceId) != null;

Try / catch

try { return parser.checkAndGetModelConfigInfo(cfg); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("模型配置不存在")) { /* re-select model / fix config */ } throw e; }

Prevention

When it happens

Trigger: Calling checkAndGetModelConfigInfo(modelConfig) where modelConfigInfo.getModelId() (or modelName parameter) does not match any model registered in ModelManager for the given workspaceId — the final null check on modelEntity fails.

Common situations: Model deleted or renamed after the prompt was saved; using a modelId from another workspace; typo in modelName parameter; deploying to an environment where the model was never registered.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/7dc7848bc6bb122c. Report an issue: GitHub.