BerriAI/litellm · error · ValueError

ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL or…

Error message

ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL or ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN is not set. Please set the environment variable, to query Anthropic's `/models` endpoint.

What it means

Error "ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL or ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN is not set. Please set the environment variable, to query Anthropic's `/models` endpoint." thrown in BerriAI/litellm.

Solutions

  1. Set ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN.
  2. Set ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL if using a custom endpoint.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/llms/anthropic/common_utils.py:786 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at litellm/llms/anthropic/common_utils.py:786

        resolved_key: Final = AnthropicModelInfo.get_api_key(api_key)
        if resolved_key is not None:
            if is_anthropic_oauth_key(resolved_key):
                return {"authorization": f"Bearer {resolved_key}"}
            return AnthropicModelInfo._make_api_key_auth_header(resolved_key, api_base, use_bearer_for_custom_base)
        auth_token: Final = AnthropicModelInfo.get_auth_token()
        if auth_token is not None:
            return {"authorization": f"Bearer {auth_token}"}
        return None

    @staticmethod
    def get_base_model(model: str | None = None) -> str | None:
        return model.replace("anthropic/", "") if model else None

    def get_models(self, api_key: str | None = None, api_base: str | None = None) -> list[str]:
        api_base = AnthropicModelInfo.get_api_base(api_base)
        auth_header: Final = AnthropicModelInfo.get_auth_header(api_key, api_base)
        if api_base is None or auth_header is None:
            raise ValueError(
                "ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL or ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN is not set. Please set the environment variable, to query Anthropic's `/models` endpoint."
            )
        headers: Final = {"anthropic-version": "2023-06-01"}
        headers.update(auth_header)
        response: Final = litellm.module_level_client.get(
            url=f"{api_base}/v1/models",
            headers=headers,
        )

        try:
            response.raise_for_status()
        except httpx.HTTPStatusError:
            raise Exception(
                f"Failed to fetch models from Anthropic. Status code: {response.status_code}, Response: {response.text}"
            )

        models: Final = response.json()["data"]

View on GitHub (pinned to 77b7c6c40c)