Using the OpenAI Java SDK for Edit and Claude AI Operations with Code Samples
This article introduces the OpenAI Java SDK, provides code examples for edit operations and Claude AI completions, and shows how to configure the SDK in a Maven project while also recommending related SpringBoot tools.
The article first recommends two SpringBoot‑based open‑source projects: a comprehensive multi‑database management tool (Datacap) supporting over 40 data sources and a simple permission management platform (authx), both available on GitHub.
It then introduces the OpenAI Java SDK, which offers Java developers an easy way to interact with OpenAI’s APIs.
Recent updates include renaming some entity classes and splitting Azure documentation.
Support for creating edit requests
EditEntity configure = EditEntity.builder()
.model(EditModel.TEXT_DAVINCI_EDIT_001)
.input("Hello OpenAi Java SDK")
.instruction("Fix the spelling mistakes")
.build();
client.edit(configure);Support for Claude AI
try (OpenAiClient client = OpenAiClient.builder()
.apiKey(System.getProperty("claude.token"))
.provider(ProviderModel.CLAUDE)
.build()) {
CompletionEntity configure = CompletionEntity.builder()
.model(CompletionModel.CLAUDE_2.getName())
.prompt("How to create a completion")
.build();
client.createCompletion(configure).getChoices();
}How to use the SDK
<properties>
<openai.version>1.6.0</openai.version>
</properties>
<dependencies>
<dependency>
<groupId>org.devlive.sdk</groupId>
<artifactId>openai-java-sdk</artifactId>
<version>${openai.version}</version>
</dependency>
</dependencies>The article concludes by encouraging readers to like and share the content as a form of support.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.