iflytek/astron-agent · error · BusinessException

MODEL_NOT_EXIST

MODEL_NOT_EXIST

Error message

BusinessException(ResponseEnum.MODEL_NOT_EXIST)

What it means

ModelService.validateModel throws MODEL_NOT_EXIST when the caller indicates the stored (masked) API key should be reused — id != null and apiKeyMasked == false — but getById(id) finds no Model row. It means the model record the request refers to does not exist in the database.

Solutions

  1. Confirm the id exists (SELECT from model table) and that the caller has access to it before calling validateModel
  2. Refresh the model list on the client after deletions so stale ids are not submitted
  3. If the caller intends to provide a new key, send apiKeyMasked=true (or true-by-default) with the plaintext/encrypted apiKey instead of referencing a stored one
  4. Check for tenant/space scoping filters in getById lookups that may hide an existing row

Example fix

// before
req.setId(999L); req.setApiKeyMasked(false); // model deleted
// after
if (modelService.getById(999L) == null) { req.setId(null); req.setApiKey(newKey); req.setApiKeyMasked(true); }
Defensive patterns

Strategy: validation

Validate before calling

if (req.getId() != null && Boolean.FALSE.equals(req.getApiKeyMasked())) {
    Model m = modelService.getById(req.getId());
    if (m == null) throw new IllegalStateException("model " + req.getId() + " no longer exists; supply a fresh apiKey");
}

Type guard

boolean modelExistsForMaskedReuse(ModelValidationRequest r) { return r.getId() == null || !Boolean.FALSE.equals(r.getApiKeyMasked()) || modelService.getById(r.getId()) != null; }

Try / catch

try { modelService.validateModel(req); } catch (BusinessException e) { if (ResponseEnum.MODEL_NOT_EXIST.equals(e.getResponseEnum())) { reloadModelList(); return 404-model-gone; } throw e; }

Prevention

When it happens

Trigger: Calling validateModel with request.id set and apiKeyMasked explicitly false, while the id does not match any row in the model table (deleted model, wrong id, other tenant's model, stale id in the frontend).

Common situations: User opens an old edit page after the model was deleted elsewhere; frontend passes an id from another workspace/tenant; ids mistyped in API integrations; DB restored/reset while clients kept old ids.

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 iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/6bad95909786fbbc. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/model/ModelService.java:142

    private final SparkBotMapper sparkBotMapper;
    private final ModelCategoryService modelCategoryService;
    private final ModelCommonService modelCommonService;
    private final LocalModelHandler modelHandler;
    private final EnterpriseSpaceService enterpriseSpaceService;

    // ======== Environment Variables ========
    @Value("${spring.profiles.active}")
    String env;


    @Transactional(rollbackFor = Exception.class)
    public String validateModel(ModelValidationRequest request) {
        // 1) Parse apiKey (use encrypted value from database when updating unchanged; otherwise decrypt)
        final String decryptedApiKey;
        if (request.getId() != null && Boolean.FALSE.equals(request.getApiKeyMasked())) {
            Model byId = this.getById(request.getId());
            if (byId == null) {
                throw new BusinessException(ResponseEnum.MODEL_NOT_EXIST);
            }
            decryptedApiKey = byId.getApiKey();
        } else {
            decryptedApiKey = decryptApiKey(request.getApiKey());
        }

        // 2) Construct/validate URL + request body/headers
        final String provider = normalizeProvider(request.getProvider(), true);
        final String url = buildModelApiUrlNew(request.getEndpoint(), provider, request.getDomain());
        final Map<String, Object> requestBody =
                buildValidationPayload(request.getDomain(), provider);
        final HttpHeaders headers = buildAuthHeaders(decryptedApiKey, provider);

        try {
            String responseBody = doPostModelApi(url, requestBody, headers);
            if (isValidModelResponse(responseBody, provider)) {
                log.info("Model validation passed, domain={}, endpoint={}", request.getDomain(), url);
                request.setApiKey(decryptedApiKey);

View on GitHub (pinned to 5e758547a8)