BerriAI/litellm · error · ValueError

Missing Anthropic API Key - A call is being made to anthropi

Error message

Missing Anthropic API Key - A call is being made to anthropic but no key is set either in the environment variables or via params

What it means

Error "Missing Anthropic API Key - A call is being made to anthropic but no key is set either in the environment variables or via params" thrown in BerriAI/litellm.

Source

Thrown at litellm/llms/anthropic/batches/transformation.py:50

        """Return the LLM provider type for this configuration."""
        return LlmProviders.ANTHROPIC

    def validate_environment(
        self,
        headers: dict,
        model: str,
        messages: list[AllMessageValues],
        optional_params: dict,
        litellm_params: dict,
        api_key: str | None = None,
        api_base: str | None = None,
    ) -> dict:
        """Validate and prepare environment-specific headers and parameters."""
        if api_base is None and isinstance(litellm_params, dict):
            api_base = litellm_params.get("api_base")
        auth_header: Final = self.anthropic_model_info.get_auth_header(api_key, api_base)
        if auth_header is None:
            raise ValueError(
                "Missing Anthropic API Key - A call is being made to anthropic but no key is set either in the environment variables or via params"
            )
        _headers: Final = {
            "accept": "application/json",
            "anthropic-version": "2023-06-01",
            "content-type": "application/json",
        }
        _headers.update(auth_header)
        # Add beta header for message batches
        if "anthropic-beta" not in headers:
            headers["anthropic-beta"] = "message-batches-2024-09-24"
        headers.update(_headers)
        return headers

    def get_complete_batch_url(
        self,
        api_base: str | None,
        api_key: str | None,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set ANTHROPIC_API_KEY in the environment or pass api_key.

When it happens

Trigger: Thrown at litellm/llms/anthropic/batches/transformation.py:50 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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