invoke-ai/InvokeAI · critical · RuntimeError
Failed to load config file {config_path}: {e}
Error message
Failed to load config file {config_path}: {e} What it means
load_and_migrate_config wraps any failure while reading, parsing, validating, or schema-migrating the InvokeAI YAML config file (or validating the resulting InvokeAIAppConfig model, including schema-version mismatch) in a RuntimeError. It is a catch-all so callers get one consistent error naming the offending config_path. The original cause is chained via `from e`.
Source
Thrown at invokeai/app/services/config/config_default.py:636
if migrated:
shutil.copy(config_path, config_path.with_suffix(".yaml.bak"))
try:
# load and write without environment variables
migrated_config = DefaultInvokeAIAppConfig.model_validate(loaded_config_dict)
migrated_config.write_file(config_path)
except Exception as e:
shutil.copy(config_path.with_suffix(".yaml.bak"), config_path)
raise RuntimeError(f"Failed to load and migrate v3 config file {config_path}: {e}") from e
try:
# Meta is not included in the model fields, so we need to validate it separately
config = InvokeAIAppConfig.model_validate(loaded_config_dict)
assert config.schema_version == CONFIG_SCHEMA_VERSION, (
f"Invalid schema version, expected {CONFIG_SCHEMA_VERSION}: {config.schema_version}"
)
return config
except Exception as e:
raise RuntimeError(f"Failed to load config file {config_path}: {e}") from e
def load_external_api_keys(api_keys_file_path: Path) -> dict[str, str]:
"""Load external provider config (API keys and base URLs) from a dedicated YAML file."""
if not api_keys_file_path.exists():
return {}
with open(api_keys_file_path, "rt", encoding=locale.getpreferredencoding()) as file:
loaded_api_keys: Any = yaml.safe_load(file)
if loaded_api_keys is None:
return {}
if not isinstance(loaded_api_keys, dict):
raise RuntimeError(f"Failed to load api keys file {api_keys_file_path}: expected a mapping")
parsed_api_keys: dict[str, str] = {}
for field_name in EXTERNAL_PROVIDER_CONFIG_FIELDS:View on GitHub (pinned to 0b6a024f2f)
Solutions
- Read the chained cause message to see whether the problem is YAML syntax, pydantic field validation, or schema version
- Fix the YAML syntax or field type at the path/line reported in the cause
- If schema_version is stale, back up invokeai.yaml and let the migration run (or manually migrate fields to the current schema)
- If irrecoverable, delete or rename the config file and let InvokeAI regenerate defaults, then re-apply settings
Example fix
// before (invokeai.yaml) generation: threads: "four" // after generation: threads: 4
Defensive patterns
Strategy: try-catch
Validate before calling
from pathlib import Path
import yaml
def config_file_ok(p: str) -> bool:
f = Path(p)
if not f.is_file():
return False
try:
data = yaml.safe_load(f.read_text())
return isinstance(data, dict)
except yaml.YAMLError:
return False Type guard
def is_valid_config(data: object) -> bool:
return isinstance(data, dict) and isinstance(data.get("schema_version", 0), int) Try / catch
try:
config = load_and_migrate_config(conf_path)
except RuntimeError as e:
logger.error(f"config load failed: {e.__cause__}")
raise SystemExit(1) Prevention
- Validate invokeai.yaml with yaml.safe_load after every manual edit
- Keep schema_version in sync when upgrading InvokeAI; read release migration notes
- Back up the config file before upgrades
- Prefer env vars/CLI over hand-editing complex nested YAML
When it happens
Trigger: Calling load_and_migrate_config(conf_path, ...) when the file does not exist or is unreadable, contains invalid YAML, fails pydantic validation against InvokeAIAppConfig, or asserts schema_version != CONFIG_SCHEMA_VERSION.
Common situations: Hand-edited invokeai.yaml with a typo or wrong type (e.g. string where int expected), stale config from an older InvokeAI version whose schema_version is below CONFIG_SCHEMA_VERSION, malformed env-var interpolation, or a corrupted/empty config file.
Related errors
- Invalid regex: {e}
- Invalid generation_devices value '{v}'. Use 'auto' or a list
- generation_devices cannot be an empty list. Use 'auto' or a
- base_url must not start with reserved path segment '/{first_
- Failed to load and migrate v3 config file {config_path}: {e}
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/b971633f0f0c568d.
Report an issue: GitHub.