BerriAI/litellm · error · Exception

Failed to fetch prompt

Error message

Failed to fetch prompt '{prompt_id}' from API: {e}

What it means

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.

Solutions

  1. 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.
  2. curl the URL yourself: curl -H 'Authorization: Bearer <key>' '<api_base>/beta/litellm_prompt_management?prompt_id=<id>'.
  3. Fix the api_base scheme/host (e.g. missing https://, wrong port) in generic_prompt_config.
  4. If it's transient (timeout/503), retry the request — prompt fetches are safe to retry.

Example fix

# before
generic_prompt_config: {'api_base': 'http://prompts.svc:8080'}  # wrong scheme/port -> HTTPError

# after
generic_prompt_config: {'api_base': 'https://prompts.internal.example.com'}
Defensive patterns

Strategy: retry

Validate before calling

import httpx

# preflight: endpoint reachable and auth valid before wiring prompt routing
resp = httpx.get(f'{api_base}/beta/litellm_prompt_management', params={'prompt_id': 'test'}, headers=headers, timeout=5)
resp.raise_for_status()  # surface auth/URL problems at startup, not request time

Try / catch

import time
for attempt in range(3):
    try:
        data = manager.fetch_prompt_from_api(prompt_id, None)
        break
    except Exception as e:
        msg = str(e)
        if 'Failed to fetch' not in msg or attempt == 2:
            raise
        if '401' in msg or '403' in msg or '404' in msg:
            raise  # not retryable: fix key or prompt_id
        time.sleep(2 ** attempt)  # retryable: timeout / 5xx / connect

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/d72e3d0991decceb. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/generic_prompt_management/generic_prompt_manager.py:128

        url: Final = f"{self.api_base}/beta/litellm_prompt_management"
        params: Final = {
            "prompt_id": prompt_id,
            **(self.additional_provider_specific_query_params or {}),
        }
        http_client: Final = _get_httpx_client()

        try:
            response: Final = http_client.get(
                url,
                params=params,
                headers=self._get_headers(),
            )

            response.raise_for_status()
            return response.json()
        except httpx.HTTPError as e:
            raise Exception(f"Failed to fetch prompt '{prompt_id}' from API: {e}")
        except json.JSONDecodeError as e:
            raise Exception(f"Failed to parse prompt response for '{prompt_id}': {e}")

    async def async_fetch_prompt_from_api(
        self, prompt_id: str | None, prompt_spec: PromptSpec | None
    ) -> dict[str, Any]:
        """
        Fetch a prompt from the API asynchronously.
        """
        if prompt_id is None and prompt_spec is None:
            raise ValueError("prompt_id or prompt_spec is required")

        url: Final = f"{self.api_base}/beta/litellm_prompt_management"
        params: Final = {
            "prompt_id": prompt_id,
            **(
                prompt_spec.litellm_params.provider_specific_query_params
                if prompt_spec and prompt_spec.litellm_params.provider_specific_query_params

View on GitHub (pinned to 77b7c6c40c)