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
- Read the status code and body in the message to identify the server-side failure
- 404: verify the URL — base should be scheme://host:port with /models appended automatically
- 401: provide the api_key for authenticated Lemonade servers
- 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
- Keep LEMONADE_API_BASE to scheme://host:port only; /models is appended by the client
- Pass api_key when the Lemonade server enforces auth to avoid 401s on model listing
- Treat 5xx on /models during startup as 'still loading' and back off, not crash
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
- LEMONADE_API_BASE is not set. Please set the environment var
- Failed to fetch models from Lemonade. Set Lemonade API Base
- Failed to transform Braintrust response: {str(e)}
- Error apply_db_fixes: {str(e)}
- File not found. blocked_user_list={blocked_user_list}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/f6da874a919d1691.
Report an issue: GitHub.