Simple-OpenAI: The OpenAI Java Client

New Release 3.9.2

simple-openai has been updated to support:

  • Usage of existing Json Schemas (in addition to defining them by classes) for Structured Outputs.
  • Usage of custom Json Object Mappers for loading Jackson Modules for example to understand date/time types.

New Release 3.10.0 - Realtime API

simple-openai has been updated to support Realtime API, so you can enable sync speech-to-speech communication in your Java applications, as well as multimodality (audio, text) and function calling.

Here you can see a demo code of Realtime:

1 Like

Release 3.12.0 - Latest OpenAI API Updates

simple-openai has been updated for:

  • Adding Session Tokens API to support WebRTC Realtime.
  • Adding reasoningEffort field and developer role to ChatCompletions.
  • Updating FineTuning API including DPO.
  • Updating Realtime API to have more control over responses.

PS: Thanks to OpenAI Staff for including simple-openai in the list of Java community libraries.

1 Like

Release 3.13.0

What’s Changed

  • Improved approach to handle multiple OpenAI providers.
    • Current support for OpenAI, Azure, Anyscale
  • Fixing software quality issues.
  • Refactoring SimpleUncheckedException.

Take a look at simple-openai.

Release 3.14.0

What’s Changed

  • Support to Mistral API for the following OpenAI compatible services:
    • Chat Completions (text generation, streaming, function calling, vision)
    • Embeddings (float format)
    • Models (list, detail, delete)
  • Removing transitive dependency for slf4j-simple.
  • Other minor changes and fixes.

Take a look at simple-openai.

Hey @sashirestela, do you have an example of using a WebRTC connection with the realtime API in java? Does the library enable this?

Hi @kevinseanscalabrini

do you have an example of using a WebRTC connection with the realtime API in java?

I can prepare an example for WebRTC supported by simple-openai.

Does the library enable this?

Yes, simple-openai enables this via the Session Token API to provide ephemeral tokens to your web application.

Great thank you :). I saw the session API but didn’t know if there was an easier way to use webrtc completely in java, or if it was meant more for use in a client app. I was looking to do Java directly so an example would be amazing!

It’s correct, WebRTC is for use in client applications, but it needs a backend endpoint to request for an ephemeral token, because you don’t want to expose your regular OpenAI api key.

I’ve created a minimalist Java application which serves a frontend component (web files) and a backend component (Java classes). The backend is exposing an endpoint for the frontend to ask for an ephemeral token that is used to start a WebRTC session from the frontend. That backend is supported by simple-openai.

Here is the OpenAI WebRTC Java Demo:

1 Like

Release 3.15.0 - Support for Deepseek API

Deepseek API has been included to the simple-openai list of supported providers with compatible OpenAI API.

For Deepseek the supported services are:

  • ChatCompletions (text generation, streaming)
  • Models (list)

Other compatible OpenAI providers supported by simple-openai are:
Mistral, Azure OpenAI, Anyscale.

1 Like

Release 3.16.0 - OkHttp Support, Response Interceptor

What’s new in simple-openai?

  • For http client communications it uses Java’s HttpClient by default, now you can choose to use OkHttp. See how to use.

  • For websocket communications it uses Java’s HttpClient by default, now you can choose to use OkHttp. See how to use.

  • Support for response interceptors to modify the response body after it’s received.

  • Updated the RealtimeDemo to test the user transcription events in addition to other events.

1 Like

Release 3.17.0 - Gemini API Support, DeepSeek Update

simple-openai has been updated for:

  • Support the Gemini Google API for the following services:
    • Chat Completions (text generation, streaming, function calling, vision, structured outputs)
    • Embeddings (float format)
  • Update the DeepSeek API to:
    • Show the chain of thought (CoT)
    • Allow function calling
2 Likes

Simple-OpenAI is ready to work with o3-mini

Just to let you know that simple-openai is ready to work with the latest o3-mini model:

  • Field reasoning_effort in the request.
  • Field usage.completion_tokens_details.reasoning_tokens in the response.

2 Likes

Thanks for the update.

Keep up the great work!

3 Likes

:robot: Instructions for Android

Follow the next instructions to run simple-openai in Android devices:

Configuration (build.gradle)

android {
    //...
    defaultConfig {
        //...
        minSdk 24
        //...
    }
    //...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
}

dependencies {
    //...
    implementation 'io.github.sashirestela:simple-openai:[simple-openai_version]'
    implementation 'com.squareup.okhttp3:okhttp:[okhttp_version]'
}

Create a SimpleOpenAI object

In Java:

SimpleOpenAI openAI = SimpleOpenAI.builder()
    .apiKey(API_KEY)
    .clientAdapter(new OkHttpClientAdapter())  // Optionally you could add a custom OkHttpClient
    .build();

In Kotlin:

val openAI = SimpleOpenAI.builder()
    .apiKey(API_KEY)
    .clientAdapter(OkHttpClientAdapter())  // Optionally you could add a custom OkHttpClient
    .build()
1 Like

Use the newest Gemini 2.0 Flash on Simple-OpenAI

Thanks to simple-openai’s versatile design, you can work with the Gemini 2.0 Flash model in Java:

  • text generation
  • streaming
  • function calling
  • vision
  • structured outputs

1 Like

Release 3.18.0 - Retrying Requests, Unknown Tools

simple-openai has been updated for:

  • Supporting retrying requests. You can configure the following parameters:
    • maxAttempts: Maximum number of retry attempts. Default 3
    • initialDelayMs: Initial delay before retrying (in milliseconds). Default 1000
    • maxDelayMs: Maximum delay between retries (in milliseconds). Default 10000
    • backoffMultiplier: Multiplier for exponential backoff. Default 2.0
    • jitterFactor: Percentage of jitter to apply to delay values. Default 0.2
    • retryableExceptions: List of exception types that should trigger a retry. Default IOException, ConnectException, SocketTimeoutException
    • retryableStatusCodes: List of HTTP status codes that should trigger a retry. Default 408, 409, 429, 500-599
  • Handling unknown tools
    • While the documented tools are code_interpreter, file_search, and function, OpenAI is sending unknown tools such as browser sometimes. Now simple-openai won’t fail if they send any unknown tool.

Release 3.19.0 - Gemini Vertex, Assistants on Azure OpenAI, Moderation Updates

simple-openai has been updated for:

  • Support for Gemini Vertex
    • text generation, streaming, function calling, vision, structured outputs.
  • Support for Assistants API on Azure OpenAI
    • assistants, threads, messages, runs, steps, vector stores, streaming, function calling, vision, structured outputs
  • Support for updates in Moderation API
1 Like

This project is really great, thank you.

2 Likes

@CodeTheory Thank you for using simple-openai and for your kind words.

What do you like most about simple-openai? Is there anything you miss?