{"record":{"id":"93769b91ca3b8c86","repo":"invoke-ai/InvokeAI","slug":"model-model-key-is-not-a-textllm-model-got-m","errorCode":null,"errorMessage":"Model '{model_key}' is not a TextLLM model (got {model_config.type})","messagePattern":"Model '(.+?)' is not a TextLLM model \\(got (.+?)\\)","errorType":"http","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"invokeai/app/api/routers/utilities.py","lineNumber":152,"sourceCode":"    return progress_callback\n\n\ndef _run_expand_prompt(\n    prompt: str,\n    model_key: str,\n    max_tokens: int,\n    system_prompt: str | None,\n    seed: int | None,\n    task_id: str | None,\n    user_id: str,\n) -> tuple[str, int]:\n    \"\"\"Run text LLM inference synchronously (called from thread).\"\"\"\n    model_manager = ApiDependencies.invoker.services.model_manager\n    events = ApiDependencies.invoker.services.events\n    model_config = model_manager.store.get_model(model_key)\n\n    if model_config.type != ModelType.TextLLM:\n        raise ValueError(f\"Model '{model_key}' is not a TextLLM model (got {model_config.type})\")\n\n    if task_id is not None:\n        events.emit_llm_task_progress(task_id=task_id, user_id=user_id, phase=\"loading_model\", message=\"Loading model\")\n\n    with _model_load_lock:\n        loaded_model = model_manager.load.load_model(model_config, user_id=user_id)\n\n    with torch.no_grad(), loaded_model.model_on_device() as (_, model):\n        model_abs_path = _resolve_model_path(model_config.path)\n        tokenizer = AutoTokenizer.from_pretrained(model_abs_path, local_files_only=True)\n\n        pipeline = TextLLMPipeline(model, tokenizer)\n        model_device = next(model.parameters()).device\n\n        progress_callback = _make_progress_callback(events, task_id, user_id)\n\n        effective_seed = seed if seed is not None else get_random_seed()\n        output = pipeline.run(","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/utilities.py#L134-L170","documentation":"ValueError raised by _run_expand_prompt when the model identified by model_key exists in the model store but its configured type is not ModelType.TextLLM. It is surfaced by expand_prompt as HTTP 422 with the same message. This is a caller-supplied model_key mismatch against the type-strict inference path.","triggerScenarios":"POST expand_prompt (or the test path test_expand_prompt_uses_fresh_seed) with a model_key whose model_config.type is e.g. Main, LlavaOnevision, or Embedding instead of TextLLM.","commonSituations":"Selecting a diffusion/LLaVA model in a UI dropdown that doesn't filter by TextLLM; config/env pointing prompt expansion at the wrong model key; older installers/models predating the TextLLM type.","solutions":["Pass a model_key whose model type is TextLLM (check via the model manager store or /api/v1/models listing)","Fix the default model_key in configuration used by the prompt-expansion feature","Install/convert a TextLLM model if none is present","Upgrade InvokeAI if your model's type string isn't recognized as TextLLM"],"exampleFix":"// before\nexpand_prompt(model_key=\"main:stablediffusion-xl\")\n// after\nexpand_prompt(model_key=\"text_llm:my-llm-model\")","handlingStrategy":"type-guard","validationCode":"const models = await api.listModels();\nconst cfg = models.find(m => m.key === modelKey);\nif (!cfg || cfg.type !== 'text_llm') {\n  throw new Error(`model_key must reference a TextLLM model (got ${cfg ? cfg.type : 'unknown'})`);\n}","typeGuard":"function isTextLlmModel(config) {\n  return config != null && config.type === 'text_llm' && typeof config.key === 'string';\n}","tryCatchPattern":"try {\n  await api.expandPrompt({ modelKey, prompt });\n} catch (e) {\n  if (e.status === 422 && /not a TextLLM model/.test(e.detail)) {\n    console.error('Wrong model type; pick a TextLLM model');\n  } else throw e;\n}","preventionTips":["Filter model dropdowns to type text_llm for prompt expansion","Store the model key from an API listing, never hand-written","Validate model type at startup if the key comes from config/env"],"tags":["valueerror","model-type","textllm","invokeai"],"backgroundTag":"model-type-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}