openai-java icon indicating copy to clipboard operation
openai-java copied to clipboard

Override base url and header with gateway data

Open vincentklg opened this issue 2 years ago • 1 comments

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 :)

vincentklg avatar Feb 02 '23 14:02 vincentklg

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.

cryptoapebot avatar Feb 02 '23 14:02 cryptoapebot

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.

TheoKanning avatar Feb 14 '23 13:02 TheoKanning