Skip to content

chore: PoC wrapping official OpenAI SDK#822

Draft
ZhongpinWang wants to merge 2 commits intomainfrom
poc-openai-sdk-wrapper
Draft

chore: PoC wrapping official OpenAI SDK#822
ZhongpinWang wants to merge 2 commits intomainfrom
poc-openai-sdk-wrapper

Conversation

@ZhongpinWang
Copy link
Copy Markdown

@ZhongpinWang ZhongpinWang commented Apr 10, 2026

Context

AI/ai-sdk-java-backlog#ISSUENUMBER.

Try the sample app and call:

http://localhost:8080/openai-wrapper/chatCompletion/ai-sdk-java-e2e

The model call in OpenAI official client is not nice I agree, perhaps we can find a way in Java to hide it.

Ignore the pom.xml if the changes contain stupid stuff as they were AI generated but they work :)

Feature scope:

  • Task1
  • Task2
    • SubTask1

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Aligned changes with the JavaScript SDK
  • Documentation updated
  • Release notes updated

Comment on lines +104 to +114
private static OpenAIClient buildClient(@Nonnull final HttpDestination destination) {
final DefaultHttpDestination defaultDest = (DefaultHttpDestination) destination;
final String baseUrl = defaultDest.getUri().toString() + "v1/";
log.debug("Building OpenAI client with base URL: {}", baseUrl);

return OpenAIOkHttpClient.builder()
.baseUrl(baseUrl)
.credential(BearerTokenCredential.create(() -> extractBearerToken(defaultDest)))
.putHeader("AI-Resource-Group", getResourceGroupHeader(defaultDest))
.build();
}
Copy link
Copy Markdown
Member

@rpanackal rpanackal Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Major)

Afaik, OpenAI SDK do not handle token refresh. So effectively, the obtained instance of OpenAIOkHttpClient also "expires" which was the concern I had when I started out here.

So, I add an adapter (custom com.openai.core.http.HttpClient) in my PR as we have a familiar Apache client that handles destination logic (incl token refresh)(#794).

Copy link
Copy Markdown
Member

@rpanackal rpanackal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are also good with the wrapper strategy on Java side. Even better since model and api-version will soon be unnecessary in v1.

That said, currently, we still considering to release a Response API specific wrapper (checkout #819).

With a regular client instance, users can do the following

// supported
client.chat().completion()
client.response()

//unsupported
client.completion()
client.realtime()
client.audio()

Ideally, we want to limit exposed api to what is supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants