invoke-ai/InvokeAI · error · ValueError

source_url must be an http or https URL

Error message

source_url must be an http or https URL

What it means

The same validate_source_url validator raises ValueError when the string does not start with 'https://' or 'http://'. InvokeAI requires source_url to be an absolute HTTP(S) URL.

Source

Thrown at invokeai/backend/model_manager/configs/base.py:93

    )
    source_api_response: str | None = Field(
        default=None,
        description="The original API response from the source, as stringified JSON.",
    )
    source_url: str | None = Field(
        default=None,
        description="Optional URL for the model (e.g. download page or model page).",
    )

    @field_validator("source_url", mode="before")
    @classmethod
    def validate_source_url(cls, v: Any) -> str | None:
        if v is None or v == "":
            return None
        if not isinstance(v, str):
            raise ValueError("source_url must be a string")
        if not v.startswith(("https://", "http://")):
            raise ValueError("source_url must be an http or https URL")
        return v

    cover_image: str | None = Field(
        default=None,
        description="Url for image to preview model",
    )

    CONFIG_CLASSES: ClassVar[set[Type["Config_Base"]]] = set()
    """Set of all non-abstract subclasses of Config_Base, for use during model probing. In other words, this is the set
    of all known model config types."""

    model_config = ConfigDict(
        validate_assignment=True,
        json_schema_serialization_defaults_required=True,
        json_schema_mode_override="serialization",
    )

    @classmethod

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Prefix the value with 'https://' (e.g. 'https://huggingface.co/...') before saving the config.
  2. Strip whitespace: v.strip() and re-check the scheme.
  3. Use None instead of a path if the model came from disk and has no web source.

Example fix

// before
config = {'source_url': 'huggingface.co/black-forest-labs/FLUX.1-schnell'}
// after
config = {'source_url': 'https://huggingface.co/black-forest-labs/FLUX.1-schnell'}
Defensive patterns

Strategy: validation

Validate before calling

def ensure_url(v: str | None) -> str | None:
    if v is None or v == '':
        return None
    v = v.strip()
    if not v.startswith(('https://', 'http://')):
        v = 'https://' + v
    return v

Type guard

def is_http_url(v: object) -> TypeGuard[str]:
    return isinstance(v, str) and v.startswith(('https://', 'http://'))

Try / catch

try:
    config = ModelConfigBase(**cfg)
except ValueError as e:
    if 'http or https URL' in str(e):
        cfg['source_url'] = 'https://' + str(cfg['source_url']).lstrip()
        config = ModelConfigBase(**cfg)
    else:
        raise

Prevention

When it happens

Trigger: Assigning source_url like 'huggingface.co/repo/model', 'file:///path', a bare local path, or a URL with leading whitespace so startswith() fails.

Common situations: Storing a local file path as the source; forgetting the scheme on a HF/Civitai URL; copying a URL with a leading space or markdown artifact.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/9e4dda922981ef0b. Report an issue: GitHub.