From 8ea73df1ac495f9855b471affd85082bef3484d1 Mon Sep 17 00:00:00 2001 From: Hemang Date: Mon, 3 Mar 2025 14:38:31 +0100 Subject: [PATCH] Add comments in the Anthropic route for the header invariant key hack. --- proxy/routes/anthropic.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/proxy/routes/anthropic.py b/proxy/routes/anthropic.py index 801f7cd..83260de 100644 --- a/proxy/routes/anthropic.py +++ b/proxy/routes/anthropic.py @@ -57,6 +57,16 @@ async def anthropic_v1_messages_proxy( headers["accept-encoding"] = "identity" # In case the user wants to push to Explorer, the request must contain the Invariant API Key + # The invariant-authorization header contains the Invariant API Key + # "invariant-authorization": "Bearer " + # The x-api-key header contains the Anthropic API Key + # "x-api-key": "" + # + # For some clients, it is not possible to pass a custom header + # In such cases, the Invariant API Key is passed as part of the + # x-api-key header with the Anthropic API key. + # The header in that case becomes: + # "x-api-key": "|invariant-auth: " invariant_authorization = None if dataset_name: if request.headers.get( @@ -73,7 +83,7 @@ async def anthropic_v1_messages_proxy( header_value = request.headers.get(ANTHROPIC_AUTHORIZATION_HEADER) api_keys = header_value.split("|invariant-auth: ") invariant_authorization = f"Bearer {api_keys[1].strip()}" - # Update the authorization header to pass the OpenAI API Key to the OpenAI API + # Update the authorization header to pass the Anthropic API Key headers[ANTHROPIC_AUTHORIZATION_HEADER] = f"{api_keys[0].strip()}" request_body = await request.body()