How to add Custom Interceptors In OpenAI Java SDK

How to add Custom Interceptors In OpenAI Java SDK when using response API?
All i Can do is
OpenAIOkHttpClient.builder()
.apiKey(“Keys”)
.timeout(Duration.ofSeconds(300))
.maxRetries(3)
.responseValidation(true)
.build()

But i want to add custom headers so i can track remaing requests and then throttle accordingly
Any help is appriciated!

FYI i am using 2.12 Version

Hey! Did you find any solution? Need to do the same

Nope!
Moved away from SDK to Rest Calls,
There i can track my own headers and outputs. Problem is it will take some good time to implement with all the options available in SDK

The following worked for me with the ChatCompletion API. (openai-java 2.20.1)

            try (HttpResponseFor<ChatCompletion> rawResponse = openAIClient
                    .chat()
                    .withRawResponse()
                    .completions()
                    .create(createParamsBuilder.build())){

                var headers = rawResponse.headers();
                log.info("Response headers: {}", headers);

                ChatCompletion response = rawResponse.parse();
            }

Note withRawResponse. You can use rawResponse.parse(); get ChatCompletion and rawResponse.headers() to get headers.

Thanks. I actually ended up using the .putAllHeaders() method of the client builder. Another way I was able to make it work was using the .additionalHeaders() method of the ChatCompletionCreateParams builder.