invoke-ai/InvokeAI · error · HTTPException

Model ' ' not found

Error message

Model '{body.model_key}' not found

What it means

HTTP 404 raised by the expand_prompt endpoint when UnknownModelException bubbles up from the model manager — no model is registered under body.model_key. The endpoint also emits an llm_task_error event ('Model not found') if a task_id was supplied.

Solutions

  1. Fetch valid keys from the models listing endpoint and use one of those
  2. Reinstall/re-import the model so it exists in the model store
  3. Fix the model_key format in the request body or client default
  4. Verify the server is using the expected models directory/database

Example fix

// before
{"model_key": "llm/my-model"}
// after
{"model_key": "text_llm/my-model@hash"}  // key from GET /api/v1/models
Defensive patterns

Strategy: try-catch

Validate before calling

const models = await api.listModels();
if (!models.some(m => m.key === body.model_key)) {
  throw new Error(`Model ${body.model_key} is not installed; choose from: ${models.map(m => m.key).join(', ')}`);
}

Type guard

function isKnownModel(models, key) {
  return typeof key === 'string' && models.some(m => m.key === key);
}

Try / catch

try {
  const res = await api.expandPrompt(body);
} catch (e) {
  if (e.status === 404 && e.detail?.startsWith('Model')) {
    const fresh = await api.listModels();
    console.error(`Model missing. Available: ${fresh.map(m => m.key).join(', ')}`);
  } else throw e;
}

Prevention

When it happens

Trigger: POST expand_prompt with body.model_key that model_manager.store.get_model cannot resolve: uninstalled model, malformed key (missing base/type hash components), or key from a different installation.

Common situations: Typo or stale default model_key in client config; model removed by garbage collection; switching between installs/databases where the model key differs; version changes that altered the model key format.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/177d422238d70f39. Report an issue: GitHub.

Appendix: source

Thrown at invokeai/app/api/routers/utilities.py:210

    events = ApiDependencies.invoker.services.events
    try:
        expanded, seed = await asyncio.to_thread(
            _run_expand_prompt,
            body.prompt,
            body.model_key,
            body.max_tokens,
            body.system_prompt,
            body.seed,
            body.task_id,
            current_user.user_id,
        )
        if body.task_id is not None:
            events.emit_llm_task_complete(task_id=body.task_id, user_id=current_user.user_id)
        return ExpandPromptResponse(expanded_prompt=expanded, seed=seed)
    except UnknownModelException:
        if body.task_id is not None:
            events.emit_llm_task_error(task_id=body.task_id, user_id=current_user.user_id, error="Model not found")
        raise HTTPException(status_code=404, detail=f"Model '{body.model_key}' not found")
    except ValueError as e:
        if body.task_id is not None:
            events.emit_llm_task_error(task_id=body.task_id, user_id=current_user.user_id, error=str(e))
        raise HTTPException(status_code=422, detail=str(e))
    except Exception as e:
        if body.task_id is not None:
            events.emit_llm_task_error(task_id=body.task_id, user_id=current_user.user_id, error=str(e))
        logger.error(f"Error expanding prompt: {e}")
        raise HTTPException(status_code=500, detail=str(e))


# --- Image to Prompt ---


class ImageToPromptRequest(BaseModel):
    image_name: str
    model_key: str
    instruction: str = "Describe this image in detail for use as an AI image generation prompt."

View on GitHub (pinned to 0b6a024f2f)