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 before-validator also enforces that a non-empty source_url string be an http or https URL. Any string lacking the https:// or http:// prefix raises this ValueError during model record validation.
Source
Thrown at invokeai/app/services/model_records/model_records_base.py:104
class ModelRecordChanges(BaseModelExcludeNull):
"""A set of changes to apply to a model."""
# Changes applicable to all models
source: Optional[str] = Field(description="original source of the model", default=None)
source_type: Optional[ModelSourceType] = Field(description="type of model source", default=None)
source_api_response: Optional[str] = Field(description="metadata from remote source", default=None)
source_url: Optional[str] = Field(description="Optional URL for the model (e.g. download page)", default=None)
@field_validator("source_url", mode="before")
@classmethod
def validate_source_url(cls, v: Any) -> Optional[str]:
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
name: Optional[str] = Field(description="Name of the model.", default=None)
path: Optional[str] = Field(description="Path to the model.", default=None)
description: Optional[str] = Field(description="Model description", default=None)
base: Optional[BaseModelType] = Field(description="The base model.", default=None)
type: Optional[ModelType] = Field(description="Type of model", default=None)
key: Optional[str] = Field(description="Database ID for this model", default=None)
hash: Optional[str] = Field(description="hash of model file", default=None)
file_size: Optional[int] = Field(description="Size of model file", default=None)
format: Optional[str] = Field(description="format of model file", default=None)
trigger_phrases: Optional[set[str]] = Field(description="Set of trigger phrases for this model", default=None)
default_settings: Optional[
MainModelDefaultSettings
| LoraModelDefaultSettings
| ControlAdapterDefaultSettings
| ExternalApiModelDefaultSettings
] = Field(description="Default settings for this model", default=None)View on GitHub (pinned to 0b6a024f2f)
Solutions
- Prefix the value with https:// (HuggingFace sources are https).
- Use full absolute URLs, not repo ids or file paths — use path/local model fields for files.
- Add client-side validation that the string starts with https:// or http:// before submitting.
Example fix
// before
const payload = { source_url: 'huggingface.co/stabilityai/sd-turbo' };
// after
const payload = { source_url: 'https://huggingface.co/stabilityai/sd-turbo' }; Defensive patterns
Strategy: validation
Validate before calling
function isValidSourceUrl(v) {
if (v === null || v === '') return true;
return typeof v === 'string' && /^https?:\/\//.test(v);
}
if (!isValidSourceUrl(payload.source_url)) {
payload.source_url = 'https://' + String(payload.source_url).replace(/^\/+/, '');
} Type guard
function isHttpUrl(v: unknown): v is string {
return typeof v === 'string' && v.startsWith('https://') || typeof v === 'string' && v.startsWith('http://');
} Try / catch
try {
await api.addModelRecord(payload);
} catch (e) {
if (String(e).includes('http or https URL')) {
payload.source_url = 'https://' + payload.source_url;
return api.addModelRecord(payload);
}
throw e;
} Prevention
- Always include the https:// scheme in source URLs
- Use full URLs, not bare org/repo identifiers
- For local files use the path field, not source_url
When it happens
Trigger: Submitting source_url values like 'huggingface.co/org/repo' (scheme missing), 'ftp://...', 'file:///models/x', or a bare repo id 'org/repo'.
Common situations: Users typing a repo path without the scheme in install forms; config files with shorthand URLs; copying paths from a browser address bar minus the scheme; CLI scripts concatenating host+path manually.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- source_url must be a string
- stop must be greater than start
- cfg_scale must be greater than 1
- Face IDs must be a comma-separated list of integers (e.g. "1
- cfg_scale values must be finite.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/93add9baf19e1361.
Report an issue: GitHub.