{"record":{"id":"434924df322b479d","repo":"BerriAI/litellm","slug":"anthropic-api-base-anthropic-base-url-or-anthropic","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/anthropic/common_utils.py","lineNumber":786,"sourceCode":"        resolved_key: Final = AnthropicModelInfo.get_api_key(api_key)\n        if resolved_key is not None:\n            if is_anthropic_oauth_key(resolved_key):\n                return {\"authorization\": f\"Bearer {resolved_key}\"}\n            return AnthropicModelInfo._make_api_key_auth_header(resolved_key, api_base, use_bearer_for_custom_base)\n        auth_token: Final = AnthropicModelInfo.get_auth_token()\n        if auth_token is not None:\n            return {\"authorization\": f\"Bearer {auth_token}\"}\n        return None\n\n    @staticmethod\n    def get_base_model(model: str | None = None) -> str | None:\n        return model.replace(\"anthropic/\", \"\") if model else None\n\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","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/anthropic/common_utils.py#L768-L804","documentation":"Raised by AnthropicModelInfo.get_models() (the /v1/models listing path) when neither an auth header (from ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN) nor an api base could be resolved from arguments or environment. LiteLLM refuses to guess where to send the request, so listing models fails fast with this ValueError.","triggerScenarios":"Calling litellm.model_list with an anthropic provider (or any code path invoking get_models) in an environment where ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are both unset — and no api_key was passed — or where the api base cannot be derived from ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL.","commonSituations":"CI jobs, containers, or serverless functions deployed without the Anthropic env vars; .env file not loaded before the call; variable name typos (ANTHROPIC_APIKEY); assuming models can be listed anonymously.","solutions":["Set ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) in the environment where the call runs.","If using a gateway, set ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL (and the token var) to its URL.","Alternatively pass api_key=... (and api_base=...) directly to get_models.","Verify with: python -c \"import os; print(os.environ.get('ANTHROPIC_API_KEY'))\" in the same shell/container.","For docker/CI, ensure secrets are injected into the runtime environment, not only the build environment."],"exampleFix":"# before\nmodels = litellm.model_list  # ValueError: no key/base configured\n\n# after\nexport ANTHROPIC_API_KEY=sk-ant-...\n# or in code:\nmodels = litellm.get_model_list():  # not needed once env is set\n# programmatic alternative:\n# from litellm.llms.anthropic.common_utils import AnthropicModelInfo\n# models = AnthropicModelInfo().get_models(api_key=\"sk-ant-...\")","handlingStrategy":"validation","validationCode":"import os\n\ndef anthropic_models_config_ok() -> bool:\n    return (\n        os.getenv(\"ANTHROPIC_API_KEY\") is not None\n        or os.getenv(\"ANTHROPIC_AUTH_TOKEN\") is not None\n    ) and (\n        os.getenv(\"ANTHROPIC_API_BASE\") is not None\n        or os.getenv(\"ANTHROPIC_BASE_URL\") is not None\n        or True  # default api.anthropic.com is fine when a key exists\n    )\n\nif not (os.getenv(\"ANTHROPIC_API_KEY\") or os.getenv(\"ANTHROPIC_AUTH_TOKEN\")):\n    raise RuntimeError(\"Set ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN before listing models\")","typeGuard":null,"tryCatchPattern":"try:\n    models = provider_info.get_models()\nexcept ValueError as e:\n    if \"ANTHROPIC_API_BASE\" in str(e):\n        load_dotenv();  # or read from secret manager\n        models = provider_info.get_models()\n    else:\n        raise","preventionTips":["Set ANTHROPIC_API_KEY in every runtime environment (CI, docker, serverless).","Fail fast at startup with an env-var assertion instead of at first API use.","Use exact variable names: ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN / ANTHROPIC_API_BASE."],"tags":["anthropic","environment","api-key","models","config"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}