Artificial Intelligence 6 min read

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.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Unlock DeepSeek R1’s Full Potential in Spring with deepseek4j
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>&lt;dependency&gt;
    &lt;groupId&gt;io.github.pig-mesh.ai&lt;/groupId&gt;
    &lt;artifactId&gt;deepseek-spring-boot-starter&lt;/artifactId&gt;
    &lt;version&gt;1.1.0&lt;/version&gt;
&lt;/dependency&gt;
</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&lt;ChatCompletionResponse&gt; chat(String prompt) {
    return deepSeekClient.chatFluxCompletion(prompt);
}
</code>

3.4 Advanced Configuration

<code>public Flux&lt;ChatCompletionResponse&gt; 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.html

to start real‑time conversation monitoring, fully displaying the evolution of the chain‑of‑thought. The page provides complete front‑end implementation code for reference.

Debugging page screenshot
Debugging page screenshot

Click “Read original” to go to the project repository and start your intelligent development era.

DeepSeek4J: https://github.com/pig-mesh/deepseek4j

JavaReactive ProgrammingSpring BootDeepSeekAI integrationOpenAI4J
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.