{"record":{"id":"ffe88c210205b6d2","repo":"invoke-ai/InvokeAI","slug":"external-api-models-cannot-be-loaded-from-disk","errorCode":null,"errorMessage":"External API models cannot be loaded from disk","messagePattern":"External API models cannot be loaded from disk","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/shared/invocation_context.py","lineNumber":606,"sourceCode":"        \"\"\"Move a model (and all of its submodels) from VRAM to RAM, freeing its VRAM but keeping it cached.\n\n        Use this when an invocation is done with a model for the rest of the run - e.g. a one-shot text encoder -\n        so the next, larger load does not have to compete with it for VRAM. The model stays in the RAM cache, so\n        a subsequent load only re-streams it back to VRAM rather than rebuilding it from disk.\n\n        Args:\n            identifier: The key or ModelField representing the model to offload.\n\n        Returns:\n            The number of VRAM bytes freed.\n        \"\"\"\n        key = identifier if isinstance(identifier, str) else identifier.key\n        return self._services.model_manager.load.ram_cache.offload_model_from_vram(key)\n\n    @staticmethod\n    def _raise_if_external(model: AnyModelConfig) -> None:\n        if model.base == BaseModelType.External or model.format == ModelFormat.ExternalApi:\n            raise ValueError(\"External API models cannot be loaded from disk\")\n\n    def get_config(self, identifier: Union[str, \"ModelIdentifierField\"]) -> AnyModelConfig:\n        \"\"\"Get a model's config.\n\n        Args:\n            identifier: The key or ModelField representing the model.\n\n        Returns:\n            The model's config.\n        \"\"\"\n        if isinstance(identifier, str):\n            return self._services.model_manager.store.get_model(identifier)\n        else:\n            return self._services.model_manager.store.get_model(identifier.key)\n\n    def search_by_path(self, path: Path) -> list[AnyModelConfig]:\n        \"\"\"Search for models by path.\n","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/shared/invocation_context.py#L588-L624","documentation":"Static guard _raise_if_external rejects loading models that are not local: models whose base is BaseModelType.External or whose format is ModelFormat.ExternalApi (third-party hosted API models). Such models have no files on disk or local weights to load, so loading them from disk is meaningless and blocked with a ValueError.","triggerScenarios":"Calling ctx.models.load(key) or load_by_attrs(...) on a model config representing an External/ExternalApi model (e.g. a remote API-hosted model entry).","commonSituations":"Configuring a workflow that references an external API model and then attempting a local load path; switching a model record to external format and re-running an old loader call; tests verifying external models cannot be loaded.","solutions":["Use the API-generation path for external models instead of local loading","Reference a local model (non-external base/format) in the loader call","Check model.base and model.format before calling load and skip external models"],"exampleFix":"// before\nmodel = ctx.models.load(key=field.key)\n// after\nconfig = ctx.models.get_config(field.key)\nif config.base == BaseModelType.External or config.format == ModelFormat.ExternalApi:\n    raise RuntimeError(f\"{config.name} is an external API model; use the remote API path\")\nmodel = ctx.models.load(key=field.key)","handlingStrategy":"validation","validationCode":"config = ctx.models.get_config(key)\nif config.base == BaseModelType.External or config.format == ModelFormat.ExternalApi:\n    raise RuntimeError(f\"{config.name} is an external API model and cannot be loaded locally\")","typeGuard":"def is_external_model(cfg: AnyModelConfig) -> bool:\n    return cfg.base == BaseModelType.External or cfg.format == ModelFormat.ExternalApi","tryCatchPattern":"try:\n    model = ctx.models.load(key=key)\nexcept ValueError as e:\n    if \"External API models\" in str(e):\n        logger.warning(\"Key %s is external; use the API generation path\", key)\n        model = None\n    else:\n        raise","preventionTips":["Check base/format from the model config before any local load","Keep external API models in separate workflows from local loads","Note the external flag when selecting models programmatically"],"tags":["models","external-api","unsupported-operation"],"backgroundTag":"external-model-not-loadable","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}