openai/openai-java
The official Java library for the OpenAI API
What it solves
This library removes the boilerplate of calling OpenAI's REST API from Java. Instead of hand-writing HTTP requests, parsing JSON, and managing authentication, developers get a typed, convenient client that handles the plumbing so they can focus on their application logic.
How it works
The SDK provides a client object you configure (with an API key, organization, project, etc.) via environment variables, system properties, or directly in code. You then call methods on that client — for example, client.responses().create(params) for text generation — passing parameter objects built with a fluent builder. The response comes back as a typed Java object. The SDK supports both the modern Responses API and the older Chat Completions API, and it offers synchronous and asynchronous clients, plus streaming for real-time chunked output. All model types are immutable and use builders for safe construction.
Who it’s for
Java developers who want to integrate OpenAI models (GPT, etc.) into their applications — whether for chat, completion, or other model interactions — without dealing with raw HTTP details. It's also useful for teams that need enterprise features like workload identity authentication for cloud environments, and for those using Amazon Bedrock to reach OpenAI-compatible APIs.
Highlights
- Supports both the Responses API and the Chat Completions API
- Synchronous and asynchronous clients with
CompletableFuturesupport - Streaming methods for real-time chunk processing, with helper accumulators for chat completions
- Immutable model classes with builders, and a
toBuilder()method for safe modifications - Flexible configuration via environment variables, system properties, or manual setters
- Optional Amazon Bedrock integration for using OpenAI models through AWS credentials
- Workload identity authentication (Kubernetes, Azure, GCP) with short-lived tokens
- X.509 client certificate authentication for direct token exchange
- Well-documented with Javadocs and runnable examples in the repository
Related
- Project
- Project
- Project
- Project
- Project