{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/generic_prompt_management/generic_prompt_manager.py#L110-L146","documentation":"GenericPromptManager wraps any httpx.HTTPError from GET {api_base}/beta/litellm_prompt_management in a generic Exception with this message. It covers connection failures, timeouts, DNS errors, and non-2xx statuses (raise_for_status runs inside the try), so inspect the appended '{e}' text to tell a 401/404 apart from a network failure.","triggerScenarios":"api_base unreachable (wrong host, DNS, firewall, TLS); expired or missing API key causing 401/403; prompt_id that no longer exists causing 404; slow prompt service hitting the client timeout; self-signed cert without verification config.","commonSituations":"Internal prompt service down or behind a VPN the proxy can't reach; secret rotation invalidated the api_key; environment differences where staging URL leaked into prod config; large prompt payloads exceeding timeout defaults.","solutions":["Read the trailing '{e}' detail: a 401/403 means fix api_key, 404 means the prompt_id is wrong, ConnectError/Timeout means api_base or networking.","curl the URL yourself: curl -H 'Authorization: Bearer <key>' '<api_base>/beta/litellm_prompt_management?prompt_id=<id>'.","Fix the api_base scheme/host (e.g. missing https://, wrong port) in generic_prompt_config.","If it's transient (timeout/503), retry the request — prompt fetches are safe to retry."],"exampleFix":"# before\ngeneric_prompt_config: {'api_base': 'http://prompts.svc:8080'}  # wrong scheme/port -> HTTPError\n\n# after\ngeneric_prompt_config: {'api_base': 'https://prompts.internal.example.com'}","handlingStrategy":"retry","validationCode":"import httpx\n\n# preflight: endpoint reachable and auth valid before wiring prompt routing\nresp = httpx.get(f'{api_base}/beta/litellm_prompt_management', params={'prompt_id': 'test'}, headers=headers, timeout=5)\nresp.raise_for_status()  # surface auth/URL problems at startup, not request time","typeGuard":null,"tryCatchPattern":"import time\nfor attempt in range(3):\n    try:\n        data = manager.fetch_prompt_from_api(prompt_id, None)\n        break\n    except Exception as e:\n        msg = str(e)\n        if 'Failed to fetch' not in msg or attempt == 2:\n            raise\n        if '401' in msg or '403' in msg or '404' in msg:\n            raise  # not retryable: fix key or prompt_id\n        time.sleep(2 ** attempt)  # retryable: timeout / 5xx / connect","preventionTips":["Run a startup preflight GET against the prompt API so URL/auth problems fail the deploy, not requests.","Distinguish retryable causes (timeout, 5xx, ConnectError) from permanent ones (401/403/404) before retrying.","Set explicit timeouts on the prompt client so hangs become fast failures."],"tags":["prompt-management","http-client","network","upstream-error"],"backgroundTag":"upstream-http-request-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}