BerriAI/litellm · error · ValueError

advisor tool definition sets 'api_base'={api_base!r}, which

Error message

advisor tool definition sets 'api_base'={api_base!r}, which must use the https scheme.

What it means

Follow-on guard in the advisor credential resolver: when a caller-supplied api_base is honored (api_key also present), the URL must use the https scheme. Plain http:// would transmit the caller's api_key in cleartext, so non-https bases are rejected before validate_url runs.

Source

Thrown at litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.py:221

    and relies on certificate validation to block DNS rebinding, so this
    closes the same gap without threading the pinned URL through the whole
    ``anthropic_messages()`` call chain.
    """
    if not _allow_client_side_advisor_credentials():
        return None, None
    api_key: Final[str | None] = advisor_tool.get("api_key")
    api_base: Final[str | None] = advisor_tool.get("api_base")
    if api_base is None:
        return api_key, None
    if not api_key:
        raise ValueError(
            "advisor tool definition sets 'api_base' without 'api_key'. A "
            "caller-supplied api_base is only honored alongside a "
            "caller-supplied api_key, so the proxy's own credentials are "
            "never sent to a caller-chosen destination."
        )
    if not api_base.startswith("https://"):
        raise ValueError(f"advisor tool definition sets 'api_base'={api_base!r}, which must use the https scheme.")
    if getattr(litellm, "ssl_verify", True) is False:
        raise ValueError(
            "advisor tool definition sets 'api_base' but the proxy has TLS verification "
            "disabled (litellm.ssl_verify=False), so a caller-supplied api_base can't be "
            "safely validated against DNS rebinding."
        )
    if getattr(litellm, "user_url_validation", True):
        validate_url(api_base)
    return api_key, api_base


def _make_synthetic_advisor_tool() -> dict:
    """Build a regular tool definition the executor provider can understand."""
    return {
        "name": "advisor",
        "description": ADVISOR_TOOL_DESCRIPTION,
        "input_schema": {
            "type": "object",

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Serve the destination over HTTPS and use an https:// URL, e.g. via a local reverse proxy with a self-signed or real cert (TLS verification must also be on).
  2. For trusted internal destinations, register them as server-side models in the proxy config instead of client-side api_base.
  3. Double-check the URL string: exactly 'https://' prefix, two slashes.

Example fix

# before
tools = [{"type": "advisor", "model": "m", "api_key": "k", "api_base": "http://localhost:8000"}]

# after
tools = [{"type": "advisor", "model": "m", "api_key": "k", "api_base": "https://localhost:8443"}]
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse

def validate_advisor_api_base(api_base: str) -> None:
    if not api_base.startswith("https://"):
        raise ValueError("advisor api_base must use the https scheme")
    parsed = urlparse(api_base)
    if not parsed.netloc:
        raise ValueError("advisor api_base must be a valid https URL")

Type guard

def is_https_url(url: object) -> bool:
    return isinstance(url, str) and url.startswith("https://") and bool(urlparse(url).netloc)

Try / catch

try:
    resp = litellm.anthropic_messages(tools=tools, ...)
except ValueError as e:
    if "must use the https scheme" in str(e):
        return http_error(400, "advisor api_base must be https")
    raise

Prevention

When it happens

Trigger: Advisor tool with api_base='http://localhost:8000' (or any http:// URL) plus an api_key. The startswith('https://') check fails and raises with the offending URL embedded in the message.

Common situations: Pointing the advisor at a local dev server (vLLM/ollama-style endpoints are usually http://); internal HTTP-only services behind no TLS; typos like 'https:/example.com' (single slash) which fail the prefix check.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/1136162adf7d98bb. Report an issue: GitHub.