Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/azure-openai/azure_general_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/azure-openai/langchain_azure_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/bedrock_general_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions examples/openai/langchain-openai-universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples/openai/openai_general_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions javelin_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -600,6 +598,11 @@ def register_provider(

self.patched_clients.add(client_id)
self.provider_name = provider_name # Store for use in helper methods
if provider_name == "azureopenai":
# 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)
Expand Down
Loading