Java SDK for OpenAI that babysits your API keys and counts tokens
An unofficial Java SDK for OpenAI that wraps the entire API and tries to solve the boring operational problems—key rotation, token counting, and streaming—so you don’t have to.

What it does
chatgpt-java is a community-maintained Java SDK for OpenAI’s full REST surface—chat, images, audio, assistants, fine-tuning, embeddings, and moderation. It offers synchronous and streaming clients built on OkHttp, with builders for custom configuration. For Java teams, it is essentially a drop-in adapter that spares you from writing your own HTTP glue.
The interesting bit Most wrappers stop at mapping JSON, but this one adds production-minded guardrails: dynamic API-key rotation when a key is banned or expired, pluggable alerting hooks (DingTalk, Feishu, email, etc.—though you wire them yourself), and local token counting. That focus on key lifecycle management is unusual for a community library.
Key highlights
- Covers the entire OpenAI API, including GPT-4, GPT-3.5-Turbo, DALL-E 3, TTS, Whisper, and Assistants.
- Supports streaming via SSE and WebSocket, with a compatibility matrix for mini-programs, Android, iOS, and H5.
- Built-in token calculation and balance-query helpers.
- Interceptor-based key management: custom strategies for multi-key pools and automatic failover on invalid keys.
- Documentation and domestic-access proxy guidance are primarily in Chinese.
Caveats
- The project is community-maintained, so long-term stability and update cadence depend on the author’s availability.
- Alerting integrations for key failures require custom development; they are not turnkey.
- The README mixes Chinese and English, and the English documentation appears to lag behind.
Verdict Worth a look if you are running Java in production against OpenAI and want key-rotation logic without building it yourself. Skip it if you prefer official or language-agnostic HTTP clients, or if you need guaranteed enterprise support.
Frequently asked
- What is Grt1228/chatgpt-java?
- An unofficial Java SDK for OpenAI that wraps the entire API and tries to solve the boring operational problems—key rotation, token counting, and streaming—so you don’t have to.
- Is chatgpt-java open source?
- Yes — Grt1228/chatgpt-java is open source, released under the Apache-2.0 license.
- What language is chatgpt-java written in?
- Grt1228/chatgpt-java is primarily written in Java.
- How popular is chatgpt-java?
- Grt1228/chatgpt-java has 3.4k stars on GitHub.
- Where can I find chatgpt-java?
- Grt1228/chatgpt-java is on GitHub at https://github.com/Grt1228/chatgpt-java.