openai-java
openai-java copied to clipboard
Override base url and header with gateway data
So in my company we use an api gateway (Gravitee) to provide a central point for all apis (internal and external). 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?
All help is greatly appreciated :)
I know this isn't that helpful, but in theory the gravitee proxy should just work as it sounds like that is their core specialty.
For your other two questions, take a look at the postman openAI api documentation. They include the base URI as a variable, and you can inspect all the individual headers and parameterize them.
https://www.postman.com/devrel/workspace/openai/documentation/13183464-90abb798-cb85-43cb-ba3a-ae7941e968da
This will get you a really long way to what you need & then figure out what part of this codebase needs to be parameterized.
You'll have to make your own instance of OpenAiApi and pass it to the OpenAiService constructor. I added a section to the readme about how customize everything https://github.com/TheoKanning/openai-java#customizing-openaiservice.
For example to set the base url:
Retrofit retrofit = defaultRetrofit(client, mapper)
.newBuilder()
.baseUrl(YOUR_URL)
.build()
Not sure how to make separate headers for each request off the top of my head, but you should be able to customize anything you want now.