From 3d7d1300e25520b1f213fcfcc798e0baec1570f4 Mon Sep 17 00:00:00 2001 From: Abhijit L Date: Wed, 23 Jul 2025 17:07:44 +0530 Subject: [PATCH 1/2] fix: model sdk tests --- examples/azure-openai/azure_general_route.py | 6 +++--- examples/azure-openai/langchain_azure_universal.py | 4 ++-- examples/bedrock/bedrock_general_route.py | 2 +- examples/openai/langchain-openai-universal.py | 6 +++--- examples/openai/openai_general_route.py | 6 +++--- javelin_sdk/client.py | 8 ++++++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/azure-openai/azure_general_route.py b/examples/azure-openai/azure_general_route.py index 4ac283a..59aec58 100644 --- a/examples/azure-openai/azure_general_route.py +++ b/examples/azure-openai/azure_general_route.py @@ -22,7 +22,7 @@ def init_azure_client_sync(): "AZURE_OPENAI_API_KEY and JAVELIN_API_KEY must be set in " "your .env file." ) - javelin_headers = {"x-api-key": javelin_api_key} + javelin_headers = {"x-javelin-apikey": javelin_api_key} client = AzureOpenAI( api_key=llm_api_key, base_url=f"{os.getenv('JAVELIN_BASE_URL')}/v1/query/azure-openai", @@ -45,7 +45,7 @@ def init_azure_embeddings_client_sync(): "AZURE_OPENAI_API_KEY and JAVELIN_API_KEY must be set in " "your .env file." ) - javelin_headers = {"x-api-key": javelin_api_key} + javelin_headers = {"x-javelin-apikey": javelin_api_key} client = AzureOpenAI( api_key=llm_api_key, base_url=("https://api-dev.javelin.live/v1/query/azure_ada_embeddings"), @@ -140,7 +140,7 @@ async def init_async_azure_client(): "AZURE_OPENAI_API_KEY and JAVELIN_API_KEY must be set in " "your .env file." ) - javelin_headers = {"x-api-key": javelin_api_key} + javelin_headers = {"x-javelin-apikey": javelin_api_key} # Include the API version in the base URL for the async client. client = AsyncOpenAI( api_key=llm_api_key, diff --git a/examples/azure-openai/langchain_azure_universal.py b/examples/azure-openai/langchain_azure_universal.py index 8f72ab1..433e382 100644 --- a/examples/azure-openai/langchain_azure_universal.py +++ b/examples/azure-openai/langchain_azure_universal.py @@ -38,7 +38,7 @@ validate_base_url=False, verbose=True, default_headers={ - "x-api-key": javelin_api_key, + "x-javelin-apikey": javelin_api_key, "x-javelin-route": route_name, "x-javelin-model": model_choice, "x-javelin-provider": "https://javelinpreview.openai.azure.com/openai", @@ -96,7 +96,7 @@ def invoke_streaming(question: str) -> str: validate_base_url=False, verbose=True, default_headers={ - "x-api-key": javelin_api_key, + "x-javelin-apikey": javelin_api_key, "x-javelin-route": route_name, "x-javelin-model": model_choice, "x-javelin-provider": "https://javelinpreview.openai.azure.com/openai", diff --git a/examples/bedrock/bedrock_general_route.py b/examples/bedrock/bedrock_general_route.py index bf70613..35c3853 100644 --- a/examples/bedrock/bedrock_general_route.py +++ b/examples/bedrock/bedrock_general_route.py @@ -58,7 +58,7 @@ def get_bedrock_client(): aws_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY", "YOUR_SECRET_KEY") bedrock_api_key = os.getenv("JAVELIN_API_KEY", "YOUR_BEDROCK_API_KEY") - custom_headers = {"x-api-key": bedrock_api_key} + custom_headers = {"x-javelin-apikey": bedrock_api_key} client = boto3.client( service_name="bedrock-runtime", diff --git a/examples/openai/langchain-openai-universal.py b/examples/openai/langchain-openai-universal.py index b34f035..52ad932 100644 --- a/examples/openai/langchain-openai-universal.py +++ b/examples/openai/langchain-openai-universal.py @@ -31,7 +31,7 @@ def init_chat_llm_non_streaming(): openai_api_key=OPENAI_API_KEY, openai_api_base=f"{BASE_URL}/v1/openai", default_headers={ - "x-api-key": JAVELIN_API_KEY, + "x-javelin-apikey": JAVELIN_API_KEY, "x-javelin-route": ROUTE_NAME, "x-javelin-provider": "https://api.openai.com/v1", "x-javelin-model": MODEL_NAME_CHAT, @@ -48,7 +48,7 @@ def init_chat_llm_streaming(): openai_api_key=OPENAI_API_KEY, openai_api_base=f"{BASE_URL}/v1/openai", default_headers={ - "x-api-key": JAVELIN_API_KEY, + "x-javelin-apikey": JAVELIN_API_KEY, "x-javelin-route": ROUTE_NAME, "x-javelin-provider": "https://api.openai.com/v1", "x-javelin-model": MODEL_NAME_CHAT, @@ -65,7 +65,7 @@ def init_embeddings_llm(): openai_api_key=OPENAI_API_KEY, openai_api_base=f"{BASE_URL}/v1/openai", default_headers={ - "x-api-key": JAVELIN_API_KEY, + "x-javelin-apikey": JAVELIN_API_KEY, "x-javelin-route": ROUTE_NAME, "x-javelin-provider": "https://api.openai.com/v1", "x-javelin-model": MODEL_NAME_EMBED, diff --git a/examples/openai/openai_general_route.py b/examples/openai/openai_general_route.py index 229f82f..c1e2eed 100644 --- a/examples/openai/openai_general_route.py +++ b/examples/openai/openai_general_route.py @@ -16,7 +16,7 @@ def init_sync_openai_client(): try: openai_api_key = os.getenv("OPENAI_API_KEY") javelin_api_key = os.getenv("JAVELIN_API_KEY") - javelin_headers = {"x-api-key": javelin_api_key} + javelin_headers = {"x-javelin-apikey": javelin_api_key} print(f"[DEBUG] Synchronous OpenAI client key: {openai_api_key}") # This client is configured for chat completions. return OpenAI( @@ -33,7 +33,7 @@ def init_async_openai_client(): try: openai_api_key = os.getenv("OPENAI_API_KEY") javelin_api_key = os.getenv("JAVELIN_API_KEY") - javelin_headers = {"x-api-key": javelin_api_key} + javelin_headers = {"x-javelin-apikey": javelin_api_key} return AsyncOpenAI( api_key=openai_api_key, base_url="https://api-dev.javelin.live/v1/query/openai", @@ -97,7 +97,7 @@ def sync_openai_embeddings(_): try: openai_api_key = os.getenv("OPENAI_API_KEY") javelin_api_key = os.getenv("JAVELIN_API_KEY") - javelin_headers = {"x-api-key": javelin_api_key} + javelin_headers = {"x-javelin-apikey": javelin_api_key} # Create a new client instance for embeddings. embeddings_client = OpenAI( api_key=openai_api_key, diff --git a/javelin_sdk/client.py b/javelin_sdk/client.py index c43712e..4ae9416 100644 --- a/javelin_sdk/client.py +++ b/javelin_sdk/client.py @@ -177,8 +177,6 @@ def _setup_client_headers(self, openai_client, route_name): openai_client._custom_headers.update(self._headers) - base_url_str = str(self.openai_base_url).rstrip("/") - openai_client._custom_headers["x-javelin-provider"] = base_url_str if route_name is not None: openai_client._custom_headers["x-javelin-route"] = route_name @@ -600,6 +598,12 @@ def register_provider( self.patched_clients.add(client_id) self.provider_name = provider_name # Store for use in helper methods + if provider_name == "azureopenai": + print(f"[DEBUG] self.base_url: {self.base_url}") + # Add /v1/openai to the base_url if not already present + base_url = self.base_url.rstrip("/") + if not base_url.endswith("openai"): + self.base_url = f"{base_url}/openai" self._setup_client_headers(openai_client, route_name) self._store_original_methods(openai_client, provider_name) From 11e78797efcad853d487162dfccd4afbf8360730 Mon Sep 17 00:00:00 2001 From: Abhijit L Date: Wed, 23 Jul 2025 17:16:06 +0530 Subject: [PATCH 2/2] fix: remove debug log --- javelin_sdk/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/javelin_sdk/client.py b/javelin_sdk/client.py index 4ae9416..c6d9315 100644 --- a/javelin_sdk/client.py +++ b/javelin_sdk/client.py @@ -599,7 +599,6 @@ def register_provider( self.patched_clients.add(client_id) self.provider_name = provider_name # Store for use in helper methods if provider_name == "azureopenai": - print(f"[DEBUG] self.base_url: {self.base_url}") # Add /v1/openai to the base_url if not already present base_url = self.base_url.rstrip("/") if not base_url.endswith("openai"):