BerriAI/litellm · error · ValueError

prompt_id or prompt_spec is required

Error message

prompt_id or prompt_spec is required

What it means

GenericPromptManager.fetch_prompt_from_api raises ValueError when both prompt_id and prompt_spec are None. The manager cannot build a query without at least one identifier: prompt_id addresses an existing prompt on the API, while prompt_spec (a structured spec object) is the alternative. This check is repeated in the async variant.

Solutions

  1. Pass a prompt_id: fetch_prompt_from_api('pm-123', None).
  2. Or pass a prompt_spec object when you don't have a server-side ID.
  3. When routing via model names, ensure the prompt ID is actually present: model='litellm_proxy/pm-123'.
  4. Log litellm_params before the call to see which identifier is getting lost.

Example fix

# before
manager.fetch_prompt_from_api(prompt_id=None, prompt_spec=None)  # ValueError

# after
manager.fetch_prompt_from_api(prompt_id='pm-123', prompt_spec=None)
Defensive patterns

Strategy: validation

Validate before calling

if prompt_id is None and prompt_spec is None:
    raise ValueError('Cannot fetch prompt: provide prompt_id or prompt_spec')

Type guard

def has_prompt_identifier(prompt_id: str | None, prompt_spec: object | None) -> bool:
    return prompt_id is not None or prompt_spec is not None

Try / catch

try:
    data = manager.fetch_prompt_from_api(prompt_id, prompt_spec)
except ValueError as e:
    if 'prompt_id or prompt_spec' in str(e):
        raise ConfigError('Prompt request missing prompt_id/prompt_spec') from e
    raise

Prevention

When it happens

Trigger: Calling fetch_prompt_from_api(None, None) directly; a completion routed through generic prompt management whose litellm_params carried neither prompt_id nor a usable prompt_spec; prompt_id stripped/renamed by an upstream serializer so it arrives as None.

Common situations: Custom proxy code that fetches prompts programmatically and assumes a default; model strings like 'litellm_proxy/<prompt_id>' with an empty ID segment; fields dropped because they weren't declared in a pydantic model.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

        if self.api_key:
            headers["Authorization"] = f"Bearer {self.api_key}"
        return headers

    def _fetch_prompt_from_api(self, prompt_id: str | None, prompt_spec: PromptSpec | None) -> dict[str, Any]:
        """
        Fetch a prompt from the API.

        Args:
            prompt_id: The ID of the prompt to fetch

        Returns:
            The prompt data from the API

        Raises:
            Exception: If the API request fails
        """
        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,
            **(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:

View on GitHub (pinned to 77b7c6c40c)