diff --git a/litellm/llms/anthropic/common_utils.py b/litellm/llms/anthropic/common_utils.py index 7199e21014..5b7937208a 100644 --- a/litellm/llms/anthropic/common_utils.py +++ b/litellm/llms/anthropic/common_utils.py @@ -452,7 +452,7 @@ class AnthropicModelInfo(BaseLLMModelInfo): betas.add(ANTHROPIC_OAUTH_BETA_HEADER) elif auth_token and not api_key: headers["authorization"] = f"Bearer {auth_token}" - else: + elif api_key: headers["x-api-key"] = api_key if user_anthropic_beta_headers is not None: diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py index f6b83a68ad..96a7b5a27a 100644 --- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py @@ -22,6 +22,7 @@ from litellm.constants import ( ALLOWED_VERTEX_AI_PASSTHROUGH_HEADERS, BEDROCK_AGENT_RUNTIME_PASS_THROUGH_ROUTES, ) +from litellm.llms.anthropic.common_utils import AnthropicModelInfo from litellm.llms.vertex_ai.vertex_llm_base import VertexBase from litellm.proxy._types import * from litellm.proxy.auth.route_checks import RouteChecks @@ -606,10 +607,11 @@ async def anthropic_proxy_route( is_streaming_request = await is_streaming_request_fn(request) ## CREATE PASS-THROUGH + auth_header = AnthropicModelInfo.get_auth_header(anthropic_api_key or None) endpoint_func = create_pass_through_route( endpoint=endpoint, target=str(updated_url), - custom_headers={"x-api-key": "{}".format(anthropic_api_key)} if anthropic_api_key else {}, + custom_headers=auth_header if auth_header is not None else {}, _forward_headers=True, is_streaming_request=is_streaming_request, ) # dynamically construct pass-through endpoint based on incoming path