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/completion/transformation.py:90

    ) -> None:
        locals_: Final = locals().copy()
        for key, value in locals_.items():
            if key != "self" and value is not None:
                setattr(self.__class__, key, value)

    # makes headers for API call
    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:
        if api_key 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",
            "x-api-key": api_key,
        }
        headers.update(_headers)
        return headers

    def transform_request(
        self,
        model: str,
        messages: list[AllMessageValues],
        optional_params: dict,
        litellm_params: dict,
        headers: dict,

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/completion/transformation.py:90 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/cc1493c8f45f8c6f. Report an issue: GitHub.