-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
To be clear, I’m not certain this is a bug, but I’m uncertain how to do this now.
For extra security layers, I am exposing Azure OpenAI via the Azure API Management service. When I make a call this way, I pass a bearer JWT token and Apim subscription key as headers. I had no problem doing this on lower versions like 0.28.1, but now I don’t know how to do this.
To Reproduce
Attempting to call Azure OpenAI with 1.1.1. The call does not successfully connect. After glancing through the source Python code, I thought maybe sticking the headers as default_headers
in the AzureOpenAI client would work, but it does not.
# Setting the auth headers
auth_headers = {
‘Ocp-Apim-Subscription-Key’: my_apim_sub_key,
‘Authorization’: f’Bearer {my_jwt_token}’
}
# Setting the Azure OpenAI client
azure_openai_client = AzureOpenAI(
api_key = ‘null’,
api_version = ‘2023-07-01-preview’,
azure_endpoint = my_special_url,
default_headers = auth_headers
)
# Calling Azure OpenAI
openai_response = azure_openai_client.chat.completions.create(
model = ‘gpt-35-turbo-16k’,
messages = my_messages
)
Here’s the way I’m doing it on 0.28.1, and this still works just fine. As you can see, I’m passing the auth headers at the time of the actual API call here.
import openai
# Setting the auth headers
auth_headers = {
‘Ocp-Apim-Subscription-Key’: my_apim_sub_key,
‘Authorization’: f’Bearer {my_jwt_token}’
}
# Setting config information on OpenAI
openai.api_url = my_special_url
openai.api_version = ‘2023-07-01-preview’
openai.api_key = ‘null’
# Calling Azure OpenAI
openai_response = openai.ChatCompletion.create(
engine = ‘gpt-35-turbo-16k’,
messages = my_messages,
Headers = auth_headers
)
What might I be doing wrong?
Code snippets
No response
OS
macOS
Python version
Python v3.10
Library version
1.1.1