{"record":{"id":"d72e3d0991decceb","repo":"BerriAI/litellm","slug":"failed-to-fetch-prompt-prompt-id-from-api-e","errorCode":null,"errorMessage":"Failed to fetch prompt '{prompt_id}' from API: {e}","messagePattern":"Failed to fetch prompt '(.+?)' from API: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/generic_prompt_management/generic_prompt_manager.py","lineNumber":128,"sourceCode":"\n        url: Final = f\"{self.api_base}/beta/litellm_prompt_management\"\n        params: Final = {\n            \"prompt_id\": prompt_id,\n            **(self.additional_provider_specific_query_params or {}),\n        }\n        http_client: Final = _get_httpx_client()\n\n        try:\n            response: Final = http_client.get(\n                url,\n                params=params,\n                headers=self._get_headers(),\n            )\n\n            response.raise_for_status()\n            return response.json()\n        except httpx.HTTPError as e:\n            raise Exception(f\"Failed to fetch prompt '{prompt_id}' from API: {e}\")\n        except json.JSONDecodeError as e:\n            raise Exception(f\"Failed to parse prompt response for '{prompt_id}': {e}\")\n\n    async def async_fetch_prompt_from_api(\n        self, prompt_id: str | None, prompt_spec: PromptSpec | None\n    ) -> dict[str, Any]:\n        \"\"\"\n        Fetch a prompt from the API asynchronously.\n        \"\"\"\n        if prompt_id is None and prompt_spec is None:\n            raise ValueError(\"prompt_id or prompt_spec is required\")\n\n        url: Final = f\"{self.api_base}/beta/litellm_prompt_management\"\n        params: Final = {\n            \"prompt_id\": prompt_id,\n            **(\n                prompt_spec.litellm_params.provider_specific_query_params\n                if prompt_spec and prompt_spec.litellm_params.provider_specific_query_params","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/generic_prompt_management/generic_prompt_manager.py#L110-L146","documentation":"Raised by GenericPromptManager._fetch_prompt_from_api (sync path) when the HTTP GET to {api_base}/beta/litellm_prompt_management raises any httpx.HTTPError. This covers connection failures, timeouts, DNS errors, and non-2xx responses surfaced by response.raise_for_status(). The original exception is flattened into a message string, so the httpx exception type is lost.","triggerScenarios":"api_base points at a host that is down or unresolvable; a proxy/firewall blocks the egress request; the API returns 401/404/500 so raise_for_status() raises HTTPStatusError; the request exceeds the httpx client's default timeout; TLS certificate verification fails against a self-hosted API.","commonSituations":"Self-hosting the prompt API behind an internal network not reachable from the deployment environment; wrong api_base scheme (http vs https) or a missing port; expired API key causing 401s; transient network blips in Kubernetes pods during startup before the service endpoint is ready.","solutions":["Verify the API is reachable from where litellm runs: curl {api_base}/beta/litellm_prompt_management?prompt_id=<id> with the same api_key headers.","Fix the api_base value (scheme, host, port, path) in the model's litellm_params; it must be the root of a LiteLLM-compatible API.","If the status is 401/403, check that api_key is set and valid on the same litellm_params.","For transient failures, retry the request or wrap the completion call in a retry with backoff — the error is a plain Exception, so match on the message prefix 'Failed to fetch prompt'."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import httpx\n\ndef check_prompt_api_reachable(api_base: str, api_key: str | None, prompt_id: str) -> None:\n    resp = httpx.get(\n        f\"{api_base}/beta/litellm_prompt_management\",\n        params={\"prompt_id\": prompt_id},\n        headers={\"Authorization\": f\"Bearer {api_key}\"} if api_key else {},\n        timeout=10,\n    )\n    resp.raise_for_status()\n    assert resp.json(), \"empty prompt response\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=\"prompt-model\", messages=msgs)\nexcept Exception as e:\n    if \"Failed to fetch prompt\" in str(e):\n        # network/HTTP failure against the prompt API: retry with backoff\n        handle_prompt_api_outage(e)\n    else:\n        raise","preventionTips":["Run a health check against {api_base}/beta/litellm_prompt_management during deployment readiness probes.","Set sensible DNS/egress rules so the runtime can reach the prompt API host.","Keep api_key and api_base in one validated config object so they cannot drift apart."],"tags":["network","http","prompt-management"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}