unslothai/unsloth · error · ValueError

Provider base URL is required.

Error message

Provider base URL is required.

What it means

Simplest validation failure in validate_provider_base_url: the value is not a non-empty string after strip. The API requires a base URL to build any provider request, so an empty/None input is refused before any parsing.

Source

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


def validate_provider_base_url(base_url: str) -> str:
    """Return a normalized provider base URL, or raise ``ValueError``.

    The backend issues outbound requests to this URL with the caller's decrypted
    API key attached, so it is caller-controlled server-side egress. Only shapes
    that can never be a real provider endpoint are refused: a non-http(s) scheme,
    control characters, a missing host, and cloud metadata services. Plain http,
    loopback, LAN hosts, odd ports, query strings and basic-auth userinfo all
    stay valid -- Ollama, llama.cpp, vLLM and custom gateways rely on them. A
    caller-supplied hostname is resolved far enough to apply the metadata block
    to DNS aliases of it; rejecting other private addresses stays opt-in.

    Normalization is strip + trailing-slash removal only (what the client did
    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:

View on GitHub (pinned to 203007d190)

Solutions

  1. Provide the actual provider base URL, e.g. https://api.openai.com/v1.
  2. Make the field required in the UI/form before calling the API.
  3. Default from a known-good constant when the env var is absent.

Example fix

# before
validate_provider_base_url(os.environ.get("PROVIDER_URL"))
# after
url = os.environ.get("PROVIDER_URL") or "https://api.openai.com/v1"
validate_provider_base_url(url)
Defensive patterns

Strategy: validation

Validate before calling

if not isinstance(base_url, str) or not base_url.strip():
    raise ValueError("base URL is required")  # before calling the API

Type guard

def has_base_url(v) -> bool:
    return isinstance(v, str) and bool(v.strip())

Prevention

When it happens

Trigger: Creating or updating a provider record with base_url None, "", or whitespace-only; a form submitted without the URL field; a config loader passing an unset variable.

Common situations: Frontend form not requiring the URL field before submit; env var for a custom provider missing; defaulted dict field never filled.

Related errors


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