{"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":"http","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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/anthropic/common_utils.py#L781-L817","documentation":"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).","triggerScenarios":"Thrown at litellm/llms/anthropic/common_utils.py:799 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the status code and response body in the error; fix credentials or endpoint accordingly.","Verify the ANTHROPIC_API_BASE is reachable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}