diff --git a/README.md b/README.md index 7a4025f..11cab96 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ https://explorer.invariantlabs.ai/api/v1/gateway/{add-your-dataset-name-here}/op Set the API Key using the following format: ```text -{your-llm-api-key}|invariant-auth: {your-invariant-api-key} +{your-llm-api-key};invariant-auth={your-invariant-api-key} ``` > **Note:** Do not include the curly braces `{}`. @@ -209,8 +209,8 @@ Run `sweagent` with the following flag: Instead of setting your API Key normally, modify the environment variable as follows: ```bash -export OPENAI_API_KEY={your-openai-api-key}|invariant-auth: {your-invariant-api-key} -export ANTHROPIC_API_KEY={your-anthropic-api-key}|invariant-auth: {your-invariant-api-key} +export OPENAI_API_KEY={your-openai-api-key};invariant-auth={your-invariant-api-key} +export ANTHROPIC_API_KEY={your-anthropic-api-key};invariant-auth={your-invariant-api-key} ``` > **Note:** Do not include the curly braces `{}`. diff --git a/gateway/routes/anthropic.py b/gateway/routes/anthropic.py index bb76fb3..45db6fb 100644 --- a/gateway/routes/anthropic.py +++ b/gateway/routes/anthropic.py @@ -66,12 +66,12 @@ async def anthropic_v1_messages_gateway( # 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: " + # "x-api-key": ";invariant-auth=" invariant_authorization = None if dataset_name: if request.headers.get( INVARIANT_AUTHORIZATION_HEADER - ) is None and "|invariant-auth:" not in request.headers.get( + ) is None and ";invariant-auth=" not in request.headers.get( ANTHROPIC_AUTHORIZATION_HEADER ): raise HTTPException(status_code=400, detail=MISSING_INVARIANT_AUTH_API_KEY) @@ -81,7 +81,7 @@ async def anthropic_v1_messages_gateway( ) else: header_value = request.headers.get(ANTHROPIC_AUTHORIZATION_HEADER) - api_keys = header_value.split("|invariant-auth: ") + api_keys = header_value.split(";invariant-auth=") invariant_authorization = f"Bearer {api_keys[1].strip()}" # Update the authorization header to pass the Anthropic API Key headers[ANTHROPIC_AUTHORIZATION_HEADER] = f"{api_keys[0].strip()}" diff --git a/gateway/routes/open_ai.py b/gateway/routes/open_ai.py index e04b154..0fd9d17 100644 --- a/gateway/routes/open_ai.py +++ b/gateway/routes/open_ai.py @@ -63,12 +63,12 @@ async def openai_chat_completions_gateway( # In such cases, the Invariant API Key is passed as part of the # authorization header with the OpenAI API key. # The header in that case becomes: - # "authorization": "|invariant-auth: " + # "authorization": ";invariant-auth=" invariant_authorization = None if dataset_name: if request.headers.get( INVARIANT_AUTHORIZATION_HEADER - ) is None and "|invariant-auth:" not in request.headers.get( + ) is None and ";invariant-auth=" not in request.headers.get( OPENAI_AUTHORIZATION_HEADER ): raise HTTPException(status_code=400, detail=MISSING_INVARIANT_AUTH_API_KEY) @@ -79,7 +79,7 @@ async def openai_chat_completions_gateway( ) else: header_value = request.headers.get(OPENAI_AUTHORIZATION_HEADER) - api_keys = header_value.split("|invariant-auth: ") + 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 headers[OPENAI_AUTHORIZATION_HEADER] = f"{api_keys[0].strip()}" diff --git a/tests/anthropic/test_anthropic_header_with_invariant_key.py b/tests/anthropic/test_anthropic_header_with_invariant_key.py index 2a73cc0..cbc512e 100644 --- a/tests/anthropic/test_anthropic_header_with_invariant_key.py +++ b/tests/anthropic/test_anthropic_header_with_invariant_key.py @@ -31,7 +31,7 @@ async def test_gateway_with_invariant_key_in_anthropic_key_header( os.environ, { "ANTHROPIC_API_KEY": anthropic_api_key - + "|invariant-auth: " + + ";invariant-auth=" }, ): client = anthropic.Anthropic( diff --git a/tests/open_ai/test_chat_without_tool_calls.py b/tests/open_ai/test_chat_without_tool_calls.py index 6d52e21..b2b9200 100644 --- a/tests/open_ai/test_chat_without_tool_calls.py +++ b/tests/open_ai/test_chat_without_tool_calls.py @@ -183,7 +183,7 @@ async def test_chat_completion_with_invariant_key_in_openai_key_header( openai_api_key = os.getenv("OPENAI_API_KEY") with patch.dict( os.environ, - {"OPENAI_API_KEY": openai_api_key + "|invariant-auth: "}, + {"OPENAI_API_KEY": openai_api_key + ";invariant-auth="}, ): client = OpenAI( http_client=Client(),