Unlocking DeepSeek R1: How to Leverage the New Reasoning Model with Spring AI
This article introduces DeepSeek R1, a breakthrough reasoning‑focused large model that visualizes its chain‑of‑thought process, matches OpenAI O1 performance, offers open‑source advantages, and provides step‑by‑step Spring AI integration guidance, including dependency setup, configuration, and code examples.
DeepSeek R1 Breakthroughs
DeepSeek R1 is a reasoning‑focused large model that adopts Chain of Thought technology. Compared with GPT‑4 and DeepSeek V3, R1 offers significant advantages:
Reasoning process visualization : Unlike generic models that act as a "black box," R1 displays the full chain of thought, allowing users to understand how conclusions are reached.
Reinforcement learning breakthrough : Using large‑scale reinforcement learning, R1 achieves reasoning ability comparable to OpenAI O1 with only a small amount of labeled data.
Performance parity : On mathematics, code, and natural‑language reasoning tasks, R1 matches the official OpenAI O1, providing a strong open‑source alternative for complex reasoning.
R1 vs V3: Writing Ability Comparison
Compared with the general‑purpose DeepSeek V3, R1 shows clear advantages in structured writing and logical reasoning.
Open‑Source and Ecosystem Benefits
Unlike the closed nature of OpenAI O1 and GPT‑4, DeepSeek R1 follows an open‑source approach:
Full open source : Provides the complete 660B‑parameter model, including DeepSeek‑R1‑Zero and DeepSeek‑R1.
Distilled small models : Six smaller models are released via distillation, with 32B and 70B versions already matching O1‑mini on many capabilities.
MIT License : The permissive license allows commercial use, secondary development, and further model training through distillation.
Spring AI Integration Practice
Below is a simple example showing how to integrate the DeepSeek Reasoner model with Spring AI.
Adding Dependencies
Add the Spring AI starter to
pom.xml:
<code><dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
<version>1.0.0-M4</version>
</dependency></code>Configuration File
Configure DeepSeek API settings in the application properties:
<code>spring.ai.openai.chat.options.model=deepseek-reasoner
spring.ai.openai.base-url=https://api.deepseek.com
spring.ai.openai.api-key=sk-xxx</code>Handling the Temperature Parameter Issue
DeepSeek Reasoner does not support the
temperatureparameter, but Spring AI adds it by default, causing an error:
<code>Caused by: dev.ai4j.openai4j.OpenAiHttpException: {"error":{"message":"deepseek-reasoner does not support the parameter `temperature`","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}</code>To fix this, add a request interceptor that removes the
temperatureparameter, achieving a "jailbreak" effect:
<code>@Configuration
public class AIConfig {
@Bean
public RestClientCustomizer restClientCustomizer() {
return restClientBuilder -> restClientBuilder.requestInterceptor((request, body, execution) -> {
// Use Jackson to parse the request body and remove the temperature field
JSONObject entries = JSONUtil.parseObj(new String(body));
entries.remove("temperature");
return execution.execute(request, entries.toString().getBytes(StandardCharsets.UTF_8));
}).build();
}
}
</code>Creating the Controller
Create a simple test to handle AI conversation requests:
<code>@Autowired
private ChatClient chatClient;
@Test
void contextLoads() {
String content = chatClient.prompt("9.11 and 9.8, which is greater?").call().content();
System.out.println(content);
}
</code>DeepSeek R1 API Features
Input Parameters
max_tokens: maximum length of the final answer (excluding chain‑of‑thought output), default 4K, up to 8K.
Chain‑of‑thought output can reach up to 32K tokens.
Temperature parameter not supported (fixed at 0.7).
Output Fields
reasoning_content: the chain‑of‑thought content.
content: the final answer.
Context Length
API supports up to 64K context.
The length of
reasoning_contentis not counted toward the 64K limit.
Pricing
Input tokens: ¥1 per million tokens (cache hit) or ¥4 per million tokens (cache miss).
Output tokens: ¥16 per million tokens.
Complex Reasoning Tasks
R1/O1: Provide detailed reasoning via chain‑of‑thought, suitable for mathematical proofs and logical inference.
GPT‑4: Strong generality but reasoning process is opaque.
V3: Better for creative writing and open‑ended dialogue.
Pricing Advantage
Compared with OpenAI O1, DeepSeek R1 offers more competitive pricing:
Input tokens: ¥1 per million (cache hit) or ¥4 per million (cache miss).
Output tokens: ¥16 per million.
Conclusion
The release of DeepSeek R1 marks a milestone where Chinese large models achieve world‑leading reasoning capabilities. Through Spring AI integration, developers can easily harness this powerful model. Although some parameter compatibility tweaks are required, they do not diminish its excellent performance in complex reasoning scenarios.
For applications demanding strong reasoning ability, R1 is a more specialized choice than GPT‑4, a more open alternative to O1, and a more focused option than V3, with open‑source benefits that enrich the AI ecosystem.
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.