BerriAI/litellm · error · ValueError

Failed to fetch models from Lemonade. Status code

Error message

Failed to fetch models from Lemonade. Status code: {response.status_code}, Response: {response.text}

What it means

After the Lemonade /models HTTP GET completes, any non-200 status is raised as ValueError that embeds both the status code and the response body, so the server's own error text is visible. This is an application-level rejection (auth, routing, server error), not a transport failure.

Solutions

  1. Read the status code and body embedded in the ValueError message for the exact server complaint
  2. Set LEMONADE_API_BASE to the bare server root (no /v1 path segment)
  3. Pass the api_key argument (or the provider's key env var) when the server enforces auth
  4. If 5xx, check the Lemonade server logs and restart it

Example fix

# before: OpenAI-style base with /v1 -> GET /v1/models -> 404
os.environ["LEMONADE_API_BASE"] = "http://localhost:8000/v1"

# after
os.environ["LEMONADE_API_BASE"] = "http://localhost:8000"
# and, if auth is enabled:
models = LemonadeConfig().get_models(api_key=os.environ["LEMONADE_API_KEY"])
Defensive patterns

Strategy: try-catch

Validate before calling

import os

base = os.getenv("LEMONADE_API_BASE", "").rstrip("/")
if base.endswith(("/v1", "/models")):
    raise ConfigError("LEMONADE_API_BASE must be the bare server root, not an OpenAI-style path")

Try / catch

try:
    models = LemonadeConfig().get_models(api_key=os.getenv("LEMONADE_API_KEY"))
except ValueError as e:
    msg = str(e)
    if "Status code: 401" in msg or "Status code: 403" in msg:
        raise ConfigError("Lemonade auth required — set api_key") from e
    if "Status code: 404" in msg:
        raise ConfigError("LEMONADE_API_BASE path is wrong — use the bare root") from e
    raise

Prevention

When it happens

Trigger: 404 when api_base already includes a path like /v1 so /v1/models is requested on a server exposing /models; 401/403 when the Lemonade server requires auth and no valid api_key was supplied; 500 when the upstream server errors while listing models.

Common situations: Auth-enabled Lemonade deployment with LEMONADE_API_KEY unset; copying an OpenAI-style base URL (with /v1) into LEMONADE_API_BASE; partially broken server build.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/f6da874a919d1691. Report an issue: GitHub.

Appendix: source

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

        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):
            try:
                parsed: Final = int(value)
            except ValueError:
                return None
            if parsed > 0:

View on GitHub (pinned to 77b7c6c40c)