BerriAI/litellm · error · Exception
Failed to fetch models from Anthropic. Status code: {respons
Error message
Failed to fetch models from Anthropic. Status code: {response.status_code}, Response: {response.text} What it means
Error "Failed to fetch models from Anthropic. Status code: {response.status_code}, Response: {response.text}" thrown in BerriAI/litellm.
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 6c2dcb801b)
Solutions
- Check ANTHROPIC_API_KEY and network access to the /models endpoint.
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@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/ccb78f176b0e1e7c.
Report an issue: GitHub.