{"record":{"id":"177d422238d70f39","repo":"invoke-ai/InvokeAI","slug":"model-body-model-key-not-found","errorCode":null,"errorMessage":"Model '{body.model_key}' not found","messagePattern":"Model '(.+?)' not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"invokeai/app/api/routers/utilities.py","lineNumber":210,"sourceCode":"    events = ApiDependencies.invoker.services.events\n    try:\n        expanded, seed = await asyncio.to_thread(\n            _run_expand_prompt,\n            body.prompt,\n            body.model_key,\n            body.max_tokens,\n            body.system_prompt,\n            body.seed,\n            body.task_id,\n            current_user.user_id,\n        )\n        if body.task_id is not None:\n            events.emit_llm_task_complete(task_id=body.task_id, user_id=current_user.user_id)\n        return ExpandPromptResponse(expanded_prompt=expanded, seed=seed)\n    except UnknownModelException:\n        if body.task_id is not None:\n            events.emit_llm_task_error(task_id=body.task_id, user_id=current_user.user_id, error=\"Model not found\")\n        raise HTTPException(status_code=404, detail=f\"Model '{body.model_key}' not found\")\n    except ValueError as e:\n        if body.task_id is not None:\n            events.emit_llm_task_error(task_id=body.task_id, user_id=current_user.user_id, error=str(e))\n        raise HTTPException(status_code=422, detail=str(e))\n    except Exception as e:\n        if body.task_id is not None:\n            events.emit_llm_task_error(task_id=body.task_id, user_id=current_user.user_id, error=str(e))\n        logger.error(f\"Error expanding prompt: {e}\")\n        raise HTTPException(status_code=500, detail=str(e))\n\n\n# --- Image to Prompt ---\n\n\nclass ImageToPromptRequest(BaseModel):\n    image_name: str\n    model_key: str\n    instruction: str = \"Describe this image in detail for use as an AI image generation prompt.\"","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/utilities.py#L192-L228","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fetch valid keys from the models listing endpoint and use one of those","Reinstall/re-import the model so it exists in the model store","Fix the model_key format in the request body or client default","Verify the server is using the expected models directory/database"],"exampleFix":"// before\n{\"model_key\": \"llm/my-model\"}\n// after\n{\"model_key\": \"text_llm/my-model@hash\"}  // key from GET /api/v1/models","handlingStrategy":"try-catch","validationCode":"const models = await api.listModels();\nif (!models.some(m => m.key === body.model_key)) {\n  throw new Error(`Model ${body.model_key} is not installed; choose from: ${models.map(m => m.key).join(', ')}`);\n}","typeGuard":"function isKnownModel(models, key) {\n  return typeof key === 'string' && models.some(m => m.key === key);\n}","tryCatchPattern":"try {\n  const res = await api.expandPrompt(body);\n} catch (e) {\n  if (e.status === 404 && e.detail?.startsWith('Model')) {\n    const fresh = await api.listModels();\n    console.error(`Model missing. Available: ${fresh.map(m => m.key).join(', ')}`);\n  } else throw e;\n}","preventionTips":["Always source model_key from a live models listing, not cached config","Handle llm_task_error events ('Model not found') when using task_id-based async flows","Re-sync model lists after installing/removing models or switching environments"],"tags":["http-404","model-not-found","invokeai","model-manager"],"backgroundTag":"model-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}