BerriAI/litellm · error · Exception

Error getting prompt from Humanloop: {e.response.text}

Error message

Error getting prompt from Humanloop: {e.response.text}

What it means

Exception raised by the Humanloop prompt integration when GET {base_url}/prompts/{id} returns a non-2xx status. The response body text from Humanloop (API error message) is embedded, so the message tells you exactly what Humanloop complained about.

Source

Thrown at litellm/integrations/humanloop.py:79

        return compiled_prompts

    def _get_prompt_from_id_api(self, humanloop_prompt_id: str, humanloop_api_key: str) -> PromptManagementClient:
        client: Final = _get_httpx_client()

        base_url: Final = f"https://api.humanloop.com/v5/prompts/{humanloop_prompt_id}"

        response: Final = client.get(
            url=base_url,
            headers={
                "X-Api-Key": humanloop_api_key,
                "Content-Type": "application/json",
            },
        )

        try:
            response.raise_for_status()
        except httpx.HTTPStatusError as e:
            raise Exception(f"Error getting prompt from Humanloop: {e.response.text}")

        json_response: Final = response.json()
        template_message: Final = json_response["template"]
        if isinstance(template_message, dict):
            template_messages = [template_message]
        elif isinstance(template_message, list):
            template_messages = template_message
        else:
            raise ValueError(f"Invalid template message type: {type(template_message)}")
        template_model: Final = json_response["model"]
        optional_params: Final = {}
        for k, v in json_response.items():
            if k in litellm.OPENAI_CHAT_COMPLETION_PARAMS:
                optional_params[k] = v
        return PromptManagementClient(
            prompt_id=humanloop_prompt_id,
            prompt_template=cast(list[AllMessageValues], template_messages),
            model=template_model,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read e.response.text in the message — Humanloop states the reason
  2. Verify prompt_id exists in the same Humanloop project the key belongs to
  3. Rotate/refresh HUMANLOOP_API_KEY if 401/403
  4. Check the configured Humanloop base_url override if any
Defensive patterns

Strategy: try-catch

Validate before calling

import httpx, os

def humanloop_key_ok(prompt_id: str) -> bool:
    r = httpx.get(
        f"https://api.humanloop.com/v4/prompts/{prompt_id}",
        headers={"X-Api-Key": os.environ["HUMANLOOP_API_KEY"]},
        timeout=5,
    )
    return r.status_code == 200

Try / catch

try:
    pmc = get_humanloop_prompt(prompt_id)
except Exception as e:
    if "404" in str(e):
        raise LookupError(f"Humanloop prompt {prompt_id} not found in this project") from e
    if "401" in str(e):
        raise PermissionError("HUMANLOOP_API_KEY invalid") from e
    raise

Prevention

When it happens

Trigger: Calling completions with prompt_id for Humanloop when the id doesn't exist (404), the HUMANLOOP_API_KEY is invalid (401), or the API base URL was customized incorrectly; response.raise_for_status() converts the status into httpx.HTTPStatusError which is caught and re-wrapped.

Common situations: prompt_id copied from a different Humanloop project/environment (dev vs prod); rotated API key not updated; self-hosted/proxied Humanloop base URL misconfigured; prompt archived or deleted in the Humanloop UI.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/1e1d53e6ced3b959. Report an issue: GitHub.