{"record":{"id":"df696789c5eb92d2","repo":"BerriAI/litellm","slug":"missing-anthropic-api-key-df6967","errorCode":null,"errorMessage":"Missing Anthropic API Key","messagePattern":"Missing Anthropic API Key","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/anthropic/files/handler.py","lineNumber":91,"sourceCode":"            HttpxBinaryResponseContent: Binary content wrapped in compatible response format\n        \"\"\"\n        file_id: Final = file_content_request.get(\"file_id\")\n        if not file_id:\n            raise ValueError(\"file_id is required in file_content_request\")\n\n        # Extract batch_id from file_id\n        # Handle both formats: \"anthropic_batch_results:{batch_id}\" or just \"{batch_id}\"\n        if file_id.startswith(\"anthropic_batch_results:\"):\n            batch_id = file_id.replace(\"anthropic_batch_results:\", \"\", 1)\n        else:\n            batch_id = file_id\n\n        # Get Anthropic API credentials\n        api_base = self.anthropic_model_info.get_api_base(api_base)\n        auth_header: Final = self.anthropic_model_info.get_auth_header(api_key, api_base)\n\n        if auth_header is None:\n            raise ValueError(\"Missing Anthropic API Key\")\n\n        # Construct the Anthropic batch results URL\n        encoded_batch_id: Final = encode_url_path_segment(batch_id, field_name=\"batch_id\")\n        results_url: Final = f\"{api_base.rstrip('/')}/v1/messages/batches/{encoded_batch_id}/results\"\n\n        # Prepare headers\n        headers: Final = {\n            \"accept\": \"application/json\",\n            \"anthropic-version\": \"2023-06-01\",\n        }\n        headers.update(auth_header)\n\n        # Make the request to Anthropic\n        async_client: Final = get_async_httpx_client(llm_provider=LlmProviders.ANTHROPIC)\n        anthropic_response: Final = await async_client.get(url=results_url, headers=headers)\n        anthropic_response.raise_for_status()\n\n        # Transform Anthropic batch results to OpenAI format","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/anthropic/files/handler.py#L73-L109","documentation":"Raised when the Anthropic files handler cannot build an auth header for the batch-results download call. AnthropicModelInfo.get_auth_header(api_key, api_base) returns None when no usable credential is found (passed api_key or ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN env), and downloading batch results requires direct Anthropic credentials.","triggerScenarios":"Calling get_file_content without api_key while ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are unset in the environment — e.g. a worker process that fetched batches via the router (credentials held server-side) but downloads results directly.","commonSituations":"Background jobs / Celery workers lacking the env var; containers where the key is mounted under a different name; assuming the gateway injects credentials into direct handler calls.","solutions":["Set ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) in the environment of the process doing the download.","Or pass api_key explicitly to the file-content call.","In containerized deployments, verify the secret is actually exported into that pod/process env."],"exampleFix":"# before\ncontent = handler.get_file_content(file_content_request={\"file_id\": fid})  # no env key\n\n# after\nimport os\nos.environ[\"ANTHROPIC_API_KEY\"] = \"sk-ant-...\"\ncontent = handler.get_file_content(file_content_request={\"file_id\": fid})\n# or pass api_key=\"sk-ant-...\" directly","handlingStrategy":"validation","validationCode":"import os\n\ndef anthropic_credentials_present(api_key: str | None) -> bool:\n    return bool(api_key or os.getenv(\"ANTHROPIC_API_KEY\") or os.getenv(\"ANTHROPIC_AUTH_TOKEN\"))","typeGuard":null,"tryCatchPattern":"try:\n    content = handler.get_file_content(file_content_request=req, api_key=api_key)\nexcept ValueError as e:\n    if \"Missing Anthropic API Key\" in str(e):\n        return http_error(500, \"server missing ANTHROPIC_API_KEY configuration\")\n    raise","preventionTips":["Export ANTHROPIC_API_KEY in every worker process that downloads batch results, not just the gateway.","Pass api_key explicitly when calling file handlers from jobs.","Fail fast at startup if a batch workload is enabled without Anthropic credentials."],"tags":["anthropic","auth","api-key","files","environment"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}