BerriAI/litellm · error · ValueError

Failed to fetch models from Lemonade. Status code: {response

Error message

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

What it means

The request to Lemonade's /models endpoint completed but returned a non-200 status. The ValueError includes both the status code and the response body, so the server's own error text (e.g. 404 route not found, 500 model load failure, 401 auth required) is visible in the message.

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 6c2dcb801b)

Solutions

  1. Read the status code and body in the message to identify the server-side failure
  2. 404: verify the URL — base should be scheme://host:port with /models appended automatically
  3. 401: provide the api_key for authenticated Lemonade servers
  4. 500/503: check Lemonade server logs; often resolves after models finish loading or the server restarts
Defensive patterns

Strategy: try-catch

Validate before calling

def lemonade_models_endpoint_healthy(api_base: str) -> tuple[bool, str]:
    import requests
    r = requests.get(f"{api_base.rstrip('/')}/models", timeout=5)
    return r.status_code == 200, f"{r.status_code}: {r.text[:200]}"

Try / catch

try:
    models = provider.get_models()
except ValueError as e:
    msg = str(e)
    if "Status code: 404" in msg:
        raise RuntimeError("LEMONADE_API_BASE likely wrong — /models not found") from e
    if "Status code: 5" in msg:
        time.sleep(5); models = provider.get_models()  # server still loading
    else:
        raise

Prevention

When it happens

Trigger: Pointing LEMONADE_API_BASE at a server that doesn't expose /models (404); the Lemonade server erroring while loading models (500); an authenticated server reached without credentials (401); version mismatch where the endpoint moved.

Common situations: Base URL includes a path prefix or wrong port so /models lands elsewhere; older/newer Lemonade build with a different route; server in a bad state after a crashed model load.

Related errors


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