Override base url and headers with gateway data
So in my company we use an api gateway (Gravitee) to provide a central point for all apis (internal and external).
I read in the docs that the base url can be changed, but it looked to me that this is only intended for OpenAI on Azure. I also didn't find a way to easily override the headers of all requests. As we use our own api key internally and let the gateway transform the headers.
Question 1: How can we change the base url to our gateway? Question 2: How can we use different headers for all requests?
I have not that much experience with python, so very likely that I overlooked something. All help is greatly appreciated :)
Hi @vincentklg,
I think I can help you out a bit. You should be able to overwrite the base url with openai.api_base = <your api base>.
I don't think there's a way to consistently overwrite the headers. What kind of overwriting did you want to do?
Hi @vincentklg,
I think I can help you out a bit. You should be able to overwrite the base url with
openai.api_base = <your api base>.I don't think there's a way to consistently overwrite the headers. What kind of overwriting did you want to do?
I want to add a token parameter in the headers for authentication through the gateway
Found the solution:
response = openai.ChatCompletion.create(
headers = {"Token":"Here is token"}, # Put the extra parameters here.
model = "gpt-3.5-turbo",
messages = [{"role": "user", "content": "Hello!"}]
)
Cool! Glad that seems to be working