Skip to content

Fix OpenAI client construction for OCI IAM auth (issue #9)#10

Merged
OpheliaLjh merged 1 commit into
mainfrom
fix/openai-client-builder-api
May 13, 2026
Merged

Fix OpenAI client construction for OCI IAM auth (issue #9)#10
OpheliaLjh merged 1 commit into
mainfrom
fix/openai-client-builder-api

Conversation

@OpheliaLjh
Copy link
Copy Markdown
Collaborator

Summary

  • OpenAIOkHttpClient.Builder in openai-java 4.x has no okHttpClient() method. Every IAM-auth example and both README snippets used this non-existent API, causing a compilation failure.
  • Add OciOpenAIHttpClient — a public com.openai.core.http.HttpClient adapter that wraps an OCI-signed OkHttpClient and routes all OpenAI SDK requests through it.
  • The correct pattern is now new OpenAIClientImpl(ClientOptions.builder().httpClient(OciOpenAIHttpClient.of(ociHttpClient, baseUrl))...).

Changes

  • New: OciOpenAIHttpClient.java — public library class, extracted and generalized from the private OpenAIOkHttpAdapter that was duplicated in both integration tests.
  • pom.xml: add openai-java-core as an optional compile dependency (not forced on consumers who don't use the OpenAI SDK).
  • README.md: fix both IAM-auth code snippets; replace OpenAIOkHttpClient.builder().okHttpClient(...) and .addHeader() (neither exists) with the correct ClientOptions + OciOpenAIHttpClient pattern.
  • All 5 IAM-auth example files: same fix applied consistently.
  • Both integration tests: remove duplicated OpenAIOkHttpAdapter inner class; use OciOpenAIHttpClient instead.

Test plan

  • mvn compile -pl oci-genai-auth-java-core — BUILD SUCCESS
  • mvn test-compile -pl oci-genai-auth-java-core — BUILD SUCCESS
  • Integration tests (OpenAIIntegrationTest, OpenAIResponsesIntegrationTest) require a live OCI session to run — marked @Disabled as before

Closes #9

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
@oracle-contributor-agreement
Copy link
Copy Markdown

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the 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.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label May 13, 2026
@OpheliaLjh OpheliaLjh added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels May 13, 2026
@OpheliaLjh OpheliaLjh merged commit eed8596 into main May 13, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java code provided in examples is incorrect

2 participants