You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
YuCheng Hu 8619ecc46e 修改编译使用的 JDK 为 JDK 17 7 days ago
.idea 修改编译使用的 JDK 为 JDK 17 7 days ago
api 修改编译使用的 JDK 为 JDK 17 7 days ago
client 更新自述文件,并且将 Key 配置到环境文件中 1 week ago
example Update the test folder and sub-task 2 months ago
.gitignore update the git file 2 months ago
LICENSE update the git file 2 months ago 修改编译使用的 JDK 为 JDK 17 7 days ago
pom.xml 修改编译使用的 JDK 为 JDK 17 7 days ago


This project builds by JDK 17 and OpenJ9 for JVM.

Java libraries for using OpenAI's GPT-3 api.

We forked this API from:

The major reason we rebuild this API was OpenAI-JAVA include lombok, we think it is better build this in plain java code.



联系方式名称 联系方式
电子邮件(Email) [email protected]
QQ 或微信(WeChat) 103899765
QQ 交流群 15186112
社区论坛 (Community)




关注公众号以后,可以通过向这个公众号发送消息来测试 ChatGPT 的微信消息集成功能。

有关更多 ChatGPT 的讨论,请访问我们的 ChatGPT 社区


我们也在头条号上创建了我们的公众号,请扫描下面的 QR 关注我们的头条号。



Deprecated OpenAI API Endpoint

APIs are deprecated, and will stop working on December 3rd, 2022.

OpenAI has deprecated all Engine-based APIs.

See Deprecated Endpoints below for more info.

How To Use

Includes the following artifacts:

  • api : request/response POJOs for the GPT-3 engine, completion, and search APIs.
  • client : a basic retrofit client for the GPT-3 endpoints, includes the api module

as well as an example project using the client.


Importing into a gradle project

implementation 'com.theokanning.openai-gpt3-java:api:<version>'
implementation 'com.theokanning.openai-gpt3-java:client:<version>'

Using OpenAiService

If you're looking for the fastest solution, import the client and use OpenAiService.

OpenAiService service = new OpenAiService("your_token");
CompletionRequest completionRequest = CompletionRequest.builder()
        .prompt("Somebody once told me the world is gonna roll me")

Using OpenAiApi Retrofit client

If you're using retrofit, you can import the client module and use the OpenAiApi.
You'll have to add your auth token as a header ( see AuthenticationInterceptor) and set your converter factory to use snake case and only include non-null fields.

Using data classes only

If you want to make your own client, just import the POJOs from the api module.
Your client will need to use snake case to work with the OpenAI API.

Running the example project

There is an example project with a OpenAiApiExample file contain main function to run.

Also, you can run all tests by JUnit too.

OpenAI-J 如何进行测试

Deprecated Endpoints

OpenAI has deprecated engine-based endpoints in favor of model-based endpoints. For example, instead of using v1/engines/{engine_id}/completions, switch to v1/completions and specify the model in the CompletionRequest. The code includes upgrade instructions for all deprecated endpoints.

I won't remove the old endpoints from this library until OpenAI shuts them down.


Supported APIs

Deprecated by OpenAI


OpenAI-J is licensed under the MIT License