BerriAI/litellm · error · Exception

Failed to fetch models from Anthropic. Status code

Error message

Failed to fetch models from Anthropic. Status code: {response.status_code}, Response: {response.text}

What it means

Anthropic /models listing guard: the HTTP request to Anthropic's models endpoint returned a non-OK status; the failure is raised with the status code and response body so callers can see why model listing failed (bad key, wrong base URL, quota).

Solutions

  1. Check the status code and response body in the error; fix credentials or endpoint accordingly.
  2. Verify the ANTHROPIC_API_BASE is reachable.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at litellm/llms/anthropic/common_utils.py:799 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/ccb78f176b0e1e7c. Report an issue: GitHub.

Appendix: source

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

    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"]

        litellm_model_names: Final = []
        for model in models:
            stripped_model_name = model["id"]
            litellm_model_name = "anthropic/" + stripped_model_name
            litellm_model_names.append(litellm_model_name)
        return litellm_model_names

    def get_token_counter(self) -> BaseTokenCounter | None:
        """
        Factory method to create an Anthropic token counter.

        Returns:
            AnthropicTokenCounter instance for this provider.

View on GitHub (pinned to 77b7c6c40c)