Unlock DeepSeek R1’s Full Potential in Spring with deepseek4j
This article introduces deepseek4j, a Spring‑Boot‑compatible library that fully supports DeepSeek R1’s chain‑of‑thought and billing features, offering reactive streaming, easy configuration, and a built‑in debugging page, with step‑by‑step setup and code examples to help developers quickly integrate the model.
With the release of the DeepSeek R1 model, its powerful chain‑of‑thought capability excites developers. However, mainstream frameworks such as Spring AI lack sufficient support, preventing many developers from fully leveraging the model’s potential. This article presents a ready‑to‑use solution – deepseek4j.
1. Why deepseek4j?
1.1 Limitations of existing frameworks
Chain‑of‑thought content loss : The core reasoning process of R1 is completely ignored.
Incompatible response mode : Cannot handle the “thinking first, conclusion later” output pattern.
Parameter restrictions : Settings for temperature, top_p and other key parameters are ineffective.
Incomplete streaming support : Leads to poor user experience.
Although the author’s previous blog introduced how to call the DeepSeek API directly with WebFlux, that approach has several drawbacks: high development cost – directly invoking the API or adapting existing frameworks requires handling many details such as request construction, response parsing, and error handling.
To solve these problems, the author built on the excellent architecture of the OpenAI4J project and created a dedicated, out‑of‑the‑box solution for DeepSeek – DeepSeek4J.
Enhanced support for DeepSeek’s unique chain‑of‑thought and billing features.
Comprehensive reactive support with Project Reactor.
Provides a Spring Boot Starter with automatic configuration.
2. Core Features
✨ Full preservation of chain‑of‑thought capability and billing.
🚀 Reactive streaming processing.
🛠 Simple and elegant API design.
📦 Out‑of‑the‑box Spring Boot integration, supporting 2.x / 3.x.
💡 Built‑in debugging page.
🔍 Detailed request and response logging.
🔧 Flexible proxy configuration.
⚡️ Reactive programming support.
3. Quick Start
3.1 Add Dependency
<code><dependency>
<groupId>io.github.pig-mesh.ai</groupId>
<artifactId>deepseek-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
</code>3.2 Configure Parameters
<code>deepseek:
api-key: your-api-key-here
base-url: https://api.deepseek.com/v1 # optional, defaults to official API address, supports Volcano, Gitee, Silicon Flow
</code>3.3 Basic Usage
<code>@Autowired
private DeepSeekClient deepSeekClient;
// SSE streaming response
@GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ChatCompletionResponse> chat(String prompt) {
return deepSeekClient.chatFluxCompletion(prompt);
}
</code>3.4 Advanced Configuration
<code>public Flux<ChatCompletionResponse> chat(String prompt) {
ChatCompletionRequest request = ChatCompletionRequest.builder()
// Model selection, supports DEEPSEEK_CHAT, DEEPSEEK_REASONER, etc.
.model(ChatCompletionModel.DEEPSEEK_CHAT)
// Add user message
.addUserMessage(prompt)
// Add assistant message for multi‑turn dialogue
.addAssistantMessage("Previous result")
// Add system message to set role and behavior
.addSystemMessage("You are a professional assistant")
// Set max tokens, default 2048
.maxTokens(1000)
// Set response format, supports JSON structured output
.responseFormat()
.tools() // function calling
.build();
return deepSeekClient.chatFluxCompletion(request);
}
</code>3.5 Developer Easter Egg
The library includes a built‑in visual debugging page; double‑click
sse.htmlto start real‑time conversation monitoring, fully displaying the evolution of the chain‑of‑thought. The page provides complete front‑end implementation code for reference.
Click “Read original” to go to the project repository and start your intelligent development era.
DeepSeek4J: https://github.com/pig-mesh/deepseek4j
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
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.