Fix OpenAI client construction for OCI IAM auth (issue #9)#10
Merged
Conversation
OpenAIOkHttpClient.Builder in openai-java 4.x does not expose an okHttpClient() method, so all IAM auth examples failed to compile. Add OciOpenAIHttpClient, a public HttpClient adapter that wraps an OCI-signed OkHttpClient and implements com.openai.core.http.HttpClient. Callers now build the OpenAI client via ClientOptions.builder() .httpClient(OciOpenAIHttpClient.of(ociHttpClient, baseUrl)). - Add openai-java-core as an optional compile dependency so that OciOpenAIHttpClient is available without forcing it on consumers who do not use the OpenAI SDK. - Update README and all five IAM-auth example files to use the correct ClientOptions + OpenAIClientImpl pattern. - Remove the duplicate OpenAIOkHttpAdapter inner class from both integration tests; they now use OciOpenAIHttpClient directly. Fixes #9
|
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
shenoyvvarun
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OpenAIOkHttpClient.Builderinopenai-java4.x has nookHttpClient()method. Every IAM-auth example and both README snippets used this non-existent API, causing a compilation failure.OciOpenAIHttpClient— a publiccom.openai.core.http.HttpClientadapter that wraps an OCI-signedOkHttpClientand routes all OpenAI SDK requests through it.new OpenAIClientImpl(ClientOptions.builder().httpClient(OciOpenAIHttpClient.of(ociHttpClient, baseUrl))...).Changes
OciOpenAIHttpClient.java— public library class, extracted and generalized from the privateOpenAIOkHttpAdapterthat was duplicated in both integration tests.pom.xml: addopenai-java-coreas anoptionalcompile dependency (not forced on consumers who don't use the OpenAI SDK).OpenAIOkHttpClient.builder().okHttpClient(...)and.addHeader()(neither exists) with the correctClientOptions+OciOpenAIHttpClientpattern.OpenAIOkHttpAdapterinner class; useOciOpenAIHttpClientinstead.Test plan
mvn compile -pl oci-genai-auth-java-core— BUILD SUCCESSmvn test-compile -pl oci-genai-auth-java-core— BUILD SUCCESSOpenAIIntegrationTest,OpenAIResponsesIntegrationTest) require a live OCI session to run — marked@Disabledas beforeCloses #9