openai / openai/openai-java

Request for Java-friendly support when customizing OkHttp (current implementation in Kotlin causes difficulties)

Open
#574 2 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement sdk
Dominant language
Kotlin
Stars
1.5k
Forks
264
Avg merge
9h 46m
Merged PRs (30d)
96

Description

📌 Background

Currently, to customize the OkHttp client, the recommended approach is to copy the OkHttpClient implementation from openai-java-client-okhttp and modify it.
However, since the implementation is written in Kotlin, this process is difficult for developers working in pure Java projects.


⚠ Problems
  1. Language barrier

    • Requires understanding of Kotlin syntax (apply, null safety, extension functions, etc.).
    • Converting the code to Java requires additional work.
  2. Build environment overhead

    • Pure Java projects need to add the Kotlin build plugin to use the copied code.
    • This introduces extra build configuration and dependency management burden.

💡 Suggestions
  • Option 1: Provide a Java-friendly abstraction layer

    • e.g., an OpenAIOkHttpClientBuilder that allows configuring Timeout, Dispatcher, Interceptors, etc.
  • Option 2: Allow direct injection of an OkHttpClient instance via factory methods

    • Example:

      OpenAIClient client = OpenAIClientImpl.builder()
          .apiKey("...")
          .httpClient(customOkHttpClient) // Built via OkHttpClient.Builder
          .build();
      
  • Option 3: Provide a Java version of the current Kotlin implementation as a sample

    • So Java developers can copy and modify it without Kotlin dependencies.

✅ Expected benefits
  • Java developers can customize OkHttp without learning Kotlin.
  • Significantly lowers the barrier compared to the current “copy-and-modify” approach.
  • Improves flexibility for adapting to different network environments.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the current Kotlin implementation in openai-java-client-okhttp and the OpenAIClientImpl.builder entry point. Determine which Java-friendly customization approach should be supported, then verify that Java projects can configure or inject a custom OkHttp client without Kotlin build dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.