{"record":{"id":"f6da874a919d1691","repo":"BerriAI/litellm","slug":"failed-to-fetch-models-from-lemonade-status-code","errorCode":null,"errorMessage":"Failed to fetch models from Lemonade. Status code: {response.status_code}, Response: {response.text}","messagePattern":"Failed to fetch models from Lemonade\\. Status code: (.+?), Response: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/lemonade/chat/transformation.py","lineNumber":100,"sourceCode":"\n        if api_base is None:\n            raise ValueError(\n                \"LEMONADE_API_BASE is not set. Please set the environment variable to query Lemonade's /models endpoint.\"\n            )\n\n        # Getting the list of models from lemonade\n        try:\n            response: Final = litellm.module_level_client.get(\n                url=f\"{api_base}/models\",\n                headers=self._get_auth_headers(api_key),\n            )\n        except Exception as e:\n            raise ValueError(\n                f\"Failed to fetch models from Lemonade. Set Lemonade API Base via `LEMONADE_API_BASE` environment variable. Error: {e}\"\n            )\n\n        if response.status_code != 200:\n            raise ValueError(\n                f\"Failed to fetch models from Lemonade. Status code: {response.status_code}, Response: {response.text}\"\n            )\n\n        model_list: Final = response.json().get(\"data\", [])\n        return [\"lemonade/\" + model[\"id\"] for model in model_list]\n\n    @staticmethod\n    def _get_positive_int(value: Any) -> int | None:\n        if isinstance(value, bool):\n            return None\n        if isinstance(value, int) and value > 0:\n            return value\n        if isinstance(value, str):\n            try:\n                parsed: Final = int(value)\n            except ValueError:\n                return None\n            if parsed > 0:","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/lemonade/chat/transformation.py#L82-L118","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the status code and body embedded in the ValueError message for the exact server complaint","Set LEMONADE_API_BASE to the bare server root (no /v1 path segment)","Pass the api_key argument (or the provider's key env var) when the server enforces auth","If 5xx, check the Lemonade server logs and restart it"],"exampleFix":"# before: OpenAI-style base with /v1 -> GET /v1/models -> 404\nos.environ[\"LEMONADE_API_BASE\"] = \"http://localhost:8000/v1\"\n\n# after\nos.environ[\"LEMONADE_API_BASE\"] = \"http://localhost:8000\"\n# and, if auth is enabled:\nmodels = LemonadeConfig().get_models(api_key=os.environ[\"LEMONADE_API_KEY\"])","handlingStrategy":"try-catch","validationCode":"import os\n\nbase = os.getenv(\"LEMONADE_API_BASE\", \"\").rstrip(\"/\")\nif base.endswith((\"/v1\", \"/models\")):\n    raise ConfigError(\"LEMONADE_API_BASE must be the bare server root, not an OpenAI-style path\")","typeGuard":null,"tryCatchPattern":"try:\n    models = LemonadeConfig().get_models(api_key=os.getenv(\"LEMONADE_API_KEY\"))\nexcept ValueError as e:\n    msg = str(e)\n    if \"Status code: 401\" in msg or \"Status code: 403\" in msg:\n        raise ConfigError(\"Lemonade auth required — set api_key\") from e\n    if \"Status code: 404\" in msg:\n        raise ConfigError(\"LEMONADE_API_BASE path is wrong — use the bare root\") from e\n    raise","preventionTips":["Store the bare server root in LEMONADE_API_BASE; never an OpenAI /v1-style URL","Pass api_key whenever the Lemonade server may have auth enabled","Parse the embedded status code out of the ValueError to branch remediation automatically"],"tags":["lemonade","get-models","http-status","authentication"],"backgroundTag":"upstream-http-error","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}