invoke-ai/InvokeAI · error · Exception
Unknown model: {model_key}
Error message
Unknown model: {model_key} What it means
The SDXL main-model loader raises this when the ModelField's key (`self.model.key`) does not exist in the model manager's record store at invoke time. The TODO comment notes proper not-found exceptions were intended; a generic Exception is used as a placeholder. It means the referenced model was deleted, never installed, or the queue item references stale model state.
Source
Thrown at invokeai/app/invocations/sdxl.py:43
@invocation("sdxl_model_loader", title="Main Model - SDXL", tags=["model", "sdxl"], category="model", version="1.0.4")
class SDXLModelLoaderInvocation(BaseInvocation):
"""Loads an sdxl base model, outputting its submodels."""
model: ModelIdentifierField = InputField(
description=FieldDescriptions.sdxl_main_model,
ui_model_base=BaseModelType.StableDiffusionXL,
ui_model_type=ModelType.Main,
)
# TODO: precision?
def invoke(self, context: InvocationContext) -> SDXLModelLoaderOutput:
model_key = self.model.key
# TODO: not found exceptions
if not context.models.exists(model_key):
raise Exception(f"Unknown model: {model_key}")
unet = self.model.model_copy(update={"submodel_type": SubModelType.UNet})
scheduler = self.model.model_copy(update={"submodel_type": SubModelType.Scheduler})
tokenizer = self.model.model_copy(update={"submodel_type": SubModelType.Tokenizer})
text_encoder = self.model.model_copy(update={"submodel_type": SubModelType.TextEncoder})
tokenizer2 = self.model.model_copy(update={"submodel_type": SubModelType.Tokenizer2})
text_encoder2 = self.model.model_copy(update={"submodel_type": SubModelType.TextEncoder2})
vae = self.model.model_copy(update={"submodel_type": SubModelType.VAE})
return SDXLModelLoaderOutput(
unet=UNetField(unet=unet, scheduler=scheduler, loras=[]),
clip=CLIPField(tokenizer=tokenizer, text_encoder=text_encoder, loras=[], skipped_layers=0),
clip2=CLIPField(tokenizer=tokenizer2, text_encoder=text_encoder2, loras=[], skipped_layers=0),
vae=VAEField(vae=vae),
)
@invocation(View on GitHub (pinned to 0b6a024f2f)
Solutions
- Install the referenced SDXL model (or fix its path/scan) so the key exists, then reopen the workflow and reselect the model in the Model Loader node.
- Re-select the model in the SDXL Main Model Loader node so the graph stores a fresh valid key.
- If the model exists, rescan the models directory or restart so the model records rebuild.
- Do not hand-edit workflow JSON model keys; export/import via the UI instead.
Example fix
// before
raise Exception(f"Unknown model: {model_key}")
// after
from invokeai.app.services.shared.exceptions import UnknownModelException
if not context.models.exists(model_key):
raise UnknownModelException(f"Unknown model: {model_key}") Defensive patterns
Strategy: validation
Validate before calling
if not context.models.exists(model_loader.model.key):
raise LookupError(f"Model {model_loader.model.key} is not installed") Type guard
def model_exists(context, model) -> bool:
return context.models.exists(model.key) Try / catch
try:
output = graph_executor.invoke(context)
except Exception as e:
if str(e).startswith("Unknown model:"):
# re-select models in the graph and requeue
requeue_with_valid_models(graph)
else:
raise Prevention
- Re-select models in the UI after reinstalling or moving model files
- Never hand-edit model keys in workflow JSON
- Rescan the models directory before running imported workflows
- Keep one model-manager database per install
When it happens
Trigger: context.models.exists(model_key) returns False because the model record was deleted between enqueue and execution, the model was never installed/converted, a workflow JSON was shared across installs with different model IDs, or the main-model invocation's `model` field points at a nonexistent/invalid key.
Common situations: Running old saved graphs after clearing the models directory; switching between SQLite databases; renaming/moving models outside the app; importing workflows from other users; partial model downloads failing to register.
Related errors
- Admin privileges required
- Expected LlavaOnevisionForConditionalGeneration, got {type(m
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- Expected AutoencoderKLWan or FluxAutoEncoder for Anima VAE,
- Expected PreTrainedModel for text encoder, got {type(text_en
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/122ea0830500d809.
Report an issue: GitHub.