unslothai/unsloth · error · ValueError

Provider base URL must use http or https.

Error message

Provider base URL must use http or https.

What it means

The URL parsed successfully but its lowercased scheme is neither http nor https. The backend only issues plain HTTP requests to provider endpoints, so any other scheme (ftp, file, websocket, or a missing scheme making the host parse as one) is refused.

Source

Thrown at studio/backend/core/inference/providers.py:885

    before), so validating an already-validated URL returns it unchanged.
    """
    if not isinstance(base_url, str) or not base_url.strip():
        raise ValueError("Provider base URL is required.")

    raw = base_url.strip()
    if any(char.isspace() or ord(char) < 32 or ord(char) == 127 for char in raw) or "\\" in raw:
        raise ValueError("Provider base URL contains invalid characters.")

    try:
        parts = urlsplit(raw)
        port = parts.port
        hostname = parts.hostname
    except ValueError as exc:
        raise ValueError("Provider base URL is malformed.") from exc

    scheme = parts.scheme.lower()
    if scheme not in ("http", "https"):
        raise ValueError("Provider base URL must use http or https.")
    # Userinfo stays allowed for gateways behind basic auth; the checks below read
    # the parsed hostname, so http://api.openai.com@169.254.169.254/ is caught.
    if not hostname:
        raise ValueError("Provider base URL must contain a hostname.")

    hostname = hostname.rstrip(".")
    if _metadata_host(hostname) or _resolves_to_metadata(hostname, port, scheme):
        raise ValueError("Cloud metadata endpoints cannot be used as a provider base URL.")

    if os.environ.get(_BLOCK_PRIVATE_ENV) == "1":
        _reject_non_public(hostname, port, scheme)

    return raw.rstrip("/")


def list_available_providers(include_hidden: bool = False) -> list[dict[str, Any]]:
    """Return registered providers (for the /registry endpoint).

View on GitHub (pinned to 203007d190)

Solutions

  1. Prefix the URL with http:// or https:// (https for real providers).
  2. Strip any protocol prefix from user input and re-add https:// programmatically.
  3. Reject non-http schemes in the client form before submission.

Example fix

# before
validate_provider_base_url("api.openai.com/v1")
# after
validate_provider_base_url("https://api.openai.com/v1")
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlsplit
if urlsplit(raw).scheme.lower() not in ("http", "https"):
    raw = "https://" + raw  # or reject

Type guard

def has_http_scheme(raw: str) -> bool:
    from urllib.parse import urlsplit
    return urlsplit(raw).scheme.lower() in ("http", "https")

Prevention

When it happens

Trigger: Passing 'ftp://host/model', 'file:///etc/passwd', a bare 'api.openai.com/v1' (parsed with 'api.openai.com' as scheme), or 'wss://...' as the base URL.

Common situations: Users omitting the https:// prefix; API examples copied with a scheme the backend does not speak; attempts to point the provider at local files.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/c4674138c8859998. Report an issue: GitHub.