mirror of
https://github.com/invariantlabs-ai/invariant-gateway.git
synced 2026-05-24 07:44:01 +02:00
Add comments in the Anthropic route for the header invariant key hack.
This commit is contained in:
@@ -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 <Invariant API Key>"
|
||||
# The x-api-key header contains the Anthropic API Key
|
||||
# "x-api-key": "<Anthropic 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": "<Anthropic API Key>|invariant-auth: <Invariant API Key>"
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user