{"record":{"id":"318abedf7c0f5451","repo":"BerriAI/litellm","slug":"failed-to-fetch-models-from-lemonade-set-lemonade","errorCode":null,"errorMessage":"Failed to fetch models from Lemonade. Set Lemonade API Base via `LEMONADE_API_BASE` environment variable. Error: {e}","messagePattern":"Failed to fetch models from Lemonade\\. Set Lemonade API Base via `LEMONADE_API_BASE` environment variable\\. Error: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/lemonade/chat/transformation.py","lineNumber":95,"sourceCode":"\n        Returns:\n            List of model names prefixed with \"lemonade/\"\n        \"\"\"\n        api_base, api_key = self._get_openai_compatible_provider_info(api_base=api_base, api_key=api_key)\n\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):","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/lemonade/chat/transformation.py#L77-L113","documentation":"Lemonade get_models performs a plain HTTP GET to {api_base}/models inside a try/except; any transport-level exception (connection refused, DNS resolution failure, timeout, SSL error) is re-raised as ValueError with the underlying error text appended. The message tells you the request never completed, not that the server rejected it.","triggerScenarios":"The Lemonade server is not running at LEMONADE_API_BASE; wrong host/port; firewall or VPN blocking the connection; HTTPS scheme against an HTTP-only local server; DNS name not resolvable.","commonSituations":"Local llama.cpp/Lemonade server not started before model discovery; port mismatch between the env var and the actual listener; container trying to reach localhost instead of host.docker.internal.","solutions":["Confirm the server is up: curl http://$LEMONADE_API_BASE/models","Fix LEMONADE_API_BASE to the real host/port the server listens on","From Docker, use host.docker.internal (or the service name) instead of localhost","Match the scheme (http vs https) to what the server actually serves","Start the Lemonade/llama server if it is simply down"],"exampleFix":"# before: server not running on that host yet\nos.environ[\"LEMONADE_API_BASE\"] = \"http://localhost:8000\"\nLemonadeConfig().get_models()  # ValueError: Failed to fetch models ... Error: [Errno 111] Connection refused\n\n# after: verify reachability first, then list\nimport httpx\nbase = os.environ[\"LEMONADE_API_BASE\"]\nhttpx.get(f\"{base}/models\", timeout=2).raise_for_status()  # fail fast with a clear cause\nmodels = LemonadeConfig().get_models()","handlingStrategy":"retry","validationCode":"import httpx, os\n\nbase = os.getenv(\"LEMONADE_API_BASE\")\ntry:\n    httpx.get(f\"{base.rstrip('/')}/models\", timeout=2).raise_for_status()\nexcept httpx.HTTPError as e:\n    raise RuntimeError(f\"Lemonade server unreachable at {base}: {e}\") from e","typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        models = LemonadeConfig().get_models()\n        break\n    except ValueError as e:\n        if \"Failed to fetch models\" in str(e) and attempt < 2:\n            time.sleep(1.5 * (attempt + 1))  # transient network blip: retry\n            continue\n        raise","preventionTips":["Start/health-check the Lemonade (llama.cpp) server before model discovery in scripts","Use the correct host from containers (host.docker.internal, not localhost)","Set explicit timeouts on discovery calls so hangs surface as fast failures"],"tags":["lemonade","get-models","network","connection-refused"],"backgroundTag":"connection-error","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}