{"record":{"id":"ccb78f176b0e1e7c","repo":"BerriAI/litellm","slug":"failed-to-fetch-models-from-anthropic-status-code","errorCode":null,"errorMessage":"Failed to fetch models from Anthropic. Status code: {response.status_code}, Response: {response.text}","messagePattern":"Failed to fetch models from Anthropic\\. Status code: (.+?), Response: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/anthropic/common_utils.py","lineNumber":799,"sourceCode":"\n    def get_models(self, api_key: str | None = None, api_base: str | None = None) -> list[str]:\n        api_base = AnthropicModelInfo.get_api_base(api_base)\n        auth_header: Final = AnthropicModelInfo.get_auth_header(api_key, api_base)\n        if api_base is None or auth_header is None:\n            raise ValueError(\n                \"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.\"\n            )\n        headers: Final = {\"anthropic-version\": \"2023-06-01\"}\n        headers.update(auth_header)\n        response: Final = litellm.module_level_client.get(\n            url=f\"{api_base}/v1/models\",\n            headers=headers,\n        )\n\n        try:\n            response.raise_for_status()\n        except httpx.HTTPStatusError:\n            raise Exception(\n                f\"Failed to fetch models from Anthropic. Status code: {response.status_code}, Response: {response.text}\"\n            )\n\n        models: Final = response.json()[\"data\"]\n\n        litellm_model_names: Final = []\n        for model in models:\n            stripped_model_name = model[\"id\"]\n            litellm_model_name = \"anthropic/\" + stripped_model_name\n            litellm_model_names.append(litellm_model_name)\n        return litellm_model_names\n\n    def get_token_counter(self) -> BaseTokenCounter | None:\n        \"\"\"\n        Factory method to create an Anthropic token counter.\n\n        Returns:\n            AnthropicTokenCounter instance for this provider.","sourceCodeStart":781,"sourceCodeEnd":817,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/anthropic/common_utils.py#L781-L817","documentation":"Error \"Failed to fetch models from Anthropic. Status code: {response.status_code}, Response: {response.text}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/anthropic/common_utils.py:799 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check ANTHROPIC_API_KEY and network access to the /models endpoint."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}