BerriAI/litellm · error · ValueError

Failed to fetch models from Lemonade. Set Lemonade API Base

Error message

Failed to fetch models from Lemonade. Set Lemonade API Base via `LEMONADE_API_BASE` environment variable. Error: {e}

What it means

While fetching Lemonade's /models endpoint to enumerate available models, the HTTP request itself threw (connection refused, DNS failure, timeout, TLS error). The exception text is embedded in a ValueError that also reminds you to set LEMONADE_API_BASE, because a wrong base URL is the most common root cause.

Source

Thrown at litellm/llms/lemonade/chat/transformation.py:95

        Returns:
            List of model names prefixed with "lemonade/"
        """
        api_base, api_key = self._get_openai_compatible_provider_info(api_base=api_base, api_key=api_key)

        if api_base is None:
            raise ValueError(
                "LEMONADE_API_BASE is not set. Please set the environment variable to query Lemonade's /models endpoint."
            )

        # Getting the list of models from lemonade
        try:
            response: Final = litellm.module_level_client.get(
                url=f"{api_base}/models",
                headers=self._get_auth_headers(api_key),
            )
        except Exception as e:
            raise ValueError(
                f"Failed to fetch models from Lemonade. Set Lemonade API Base via `LEMONADE_API_BASE` environment variable. Error: {e}"
            )

        if response.status_code != 200:
            raise ValueError(
                f"Failed to fetch models from Lemonade. Status code: {response.status_code}, Response: {response.text}"
            )

        model_list: Final = response.json().get("data", [])
        return ["lemonade/" + model["id"] for model in model_list]

    @staticmethod
    def _get_positive_int(value: Any) -> int | None:
        if isinstance(value, bool):
            return None
        if isinstance(value, int) and value > 0:
            return value
        if isinstance(value, str):

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Start/verify the Lemonade server: curl {LEMONADE_API_BASE}/models
  2. Fix the base URL (correct host/port; inside Docker use the service name, not localhost)
  3. Add allowrules for the proxy or disable the proxy for the Lemonade host
  4. Retry once the server has finished model loading (first load can take minutes)
Defensive patterns

Strategy: retry

Validate before calling

def lemonade_reachable(api_base: str) -> bool:
    import socket
    from urllib.parse import urlparse
    u = urlparse(api_base)
    try:
        with socket.create_connection((u.hostname, u.port or 80), timeout=3):
            return True
    except OSError:
        return False

Try / catch

try:
    models = provider.get_models()
except ValueError as e:
    if "Failed to fetch models" in str(e) and lemonade_reachable(base):
        time.sleep(2)
        models = provider.get_models()  # one bounded retry
    else:
        raise

Prevention

When it happens

Trigger: LEMONADE_API_BASE pointing at a host/port where nothing listens (connection refused); wrong hostname (DNS resolution failure); server behind a proxy that blocks the request; self-signed cert causing TLS errors.

Common situations: Lemonade server not running or still loading models; base URL copied with a typo; firewall/proxy blocking localhost replacement; container networking where 'localhost' refers to the wrong namespace.

Related errors


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