DeepSeek-SiliconFlow
This document explains how to call the DeepSeek series models provided by SiliconFlow on Alibaba Cloud Model Studio using the OpenAI-compatible API or the DashScope SDK.
Alibaba Cloud Model Studio offers DeepSeek model services from two inference service providers. The SiliconFlow provider supports a longer context, while the Alibaba Cloud Model Studio provider has more relaxed throttling limits and supports web search and context cache.
ImportantThis document applies only to the China (Beijing) region. To use models, you must use an API Key from the China (Beijing) region.
Activate the service
- Go to the Model Studio console, search for
deepseek, find the SiliconFlow DeepSeek model card, and click Activate Now. - In the dialog box, confirm the activation and authorization.
After completing these steps, you can call the DeepSeek model service provided by SiliconFlow.
Quick start
deepseek-v3.2 is the latest model in the DeepSeek series. It supports thinking and non-thinking modes, which are controlled by theenable_thinking parameter. Run the following code to quickly call the deepseek-v3.2 model in thinking mode.
You must obtain an API Key and configure it as an environment variable. If you use an SDK to call the model, you must also install the SDK.
OpenAI compatible
NoteTheenable_thinking parameter is not a standard OpenAI parameter. For the OpenAI Python SDK, pass it inextra_body. For the Node.js SDK, pass it as a top-level parameter.
Python
Sample code
from openai import OpenAI
import os
# Initialize the OpenAI client
client = OpenAI(
# If the environment variable is not configured, replace with your Alibaba Cloud Model Studio API Key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [{"role": "user", "content": "Who are you?"}]
completion = client.chat.completions.create(
model="siliconflow/deepseek-v3.2",
messages=messages,
# Enable thinking mode by setting enable_thinking in extra_body
extra_body={"enable_thinking": True},
stream=True,
stream_options={
"include_usage": True
},
)
reasoning_content = "" # Full thinking process
answer_content = "" # Full response
is_answering = False # Tracks if the model has started answering
print("\n" + "=" * 20 + "Thinking Process" + "=" * 20 + "\n")
for chunk in completion:
if not chunk.choices:
print("\n" + "=" * 20 + "token usage" + "=" * 20 + "\n")
print(chunk.usage)
continue
delta = chunk.choices[0].delta
# Collect only the thinking content
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
# When content is received, start the response
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "Full Response" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
Response
====================Thinking Process====================
Ah, the user is asking who I am, which is a simple self-introduction question. I need to clearly state my identity, development background, core functions, and features, without overcomplicating things.
I can start with my company background and AI identity, then list key capabilities to help the user quickly understand my value. Finally, I'll use a friendly tone to remain open. I thought about highlighting practical points like being free, having a long context, and processing files, and adding an emoji to seem more approachable.
I should avoid technical details and focus on what the user can directly perceive.
====================Full Response====================
Hello! I am DeepSeek, an AI assistant created by DeepSeek!
I am a text-only model with a 128K context length, and I am completely free for everyone to use. While I don't support multimodal recognition, I can help you process uploaded images, txt, pdf, ppt, word, and excel files by extracting and analyzing their text content.
My knowledge cutoff is July 2024, and I also support web search (you need to manually enable it). You can download my app from the official app store.
I am happy to help you with various questions, whether they are about studying, work, life, or creative projects. I will provide enthusiastic and detailed assistance! Is there anything you would like to know or need my help with?
====================token usage====================
CompletionUsage(completion_tokens=239, prompt_tokens=5, total_tokens=244, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=None, audio_tokens=None, reasoning_tokens=95, rejected_prediction_tokens=None, text_tokens=144), prompt_tokens_details=None)
Node.js
Sample code
import OpenAI from "openai";
import process from 'process';
// Initialize the OpenAI client
const openai = new OpenAI({
// If the environment variable is not configured, replace with your Alibaba Cloud Model Studio API Key: apiKey: "sk-xxx"
apiKey: process.env.DASHSCOPE_API_KEY,
// China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
baseURL: 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1'
});
let reasoningContent = ''; // Full thinking process
let answerContent = ''; // Full response
let isAnswering = false; // Tracks if the model has started answering
async function main() {
try {
const messages = [{ role: 'user', content: 'Who are you?' }];
const stream = await openai.chat.completions.create({
model: 'siliconflow/deepseek-v3.2',
messages,
// Note: In the Node.js SDK, non-standard parameters like enable_thinking are passed as top-level properties, not within extra_body.
enable_thinking: true,
stream: true,
stream_options: {
include_usage: true
},
});
console.log('\n' + '='.repeat(20) + 'Thinking Process' + '='.repeat(20) + '\n');
for await (const chunk of stream) {
if (!chunk.choices?.length) {
console.log('\n' + '='.repeat(20) + 'token usage' + '='.repeat(20) + '\n');
console.log(chunk.usage);
continue;
}
const delta = chunk.choices[0].delta;
// Collect only the thinking content
if (delta.reasoning_content !== undefined && delta.reasoning_content !== null) {
if (!isAnswering) {
process.stdout.write(delta.reasoning_content);
}
reasoningContent += delta.reasoning_content;
}
// When content is received, start the response
if (delta.content !== undefined && delta.content) {
if (!isAnswering) {
console.log('\n' + '='.repeat(20) + 'Full Response' + '='.repeat(20) + '\n');
isAnswering = true;
}
process.stdout.write(delta.content);
answerContent += delta.content;
}
}
} catch (error) {
console.error('Error:', error);
}
}
main();
Response
====================Thinking Process====================
Ah, the user is asking a very basic self-introduction question. This type of question doesn't require complex deconstruction; I can just provide a standard identity description.
I need to state that I am an AI assistant from DeepSeek and list my core features so the user can quickly understand my capabilities. I'll end with an enthusiastic but concise tone and guide the user to make a specific request.
I should keep the response structure clear but not too rigid, and add some emojis to seem friendly.
====================Full Response====================
Hello! I am DeepSeek, an AI assistant created by DeepSeek!
I am a text-only model and I am good at answering various questions, assisting with writing, analyzing problems, programming, and more. While I don't support multimodal recognition, I can process uploaded images, txt, pdf, ppt, word, and excel files by extracting and analyzing their text content.
I am completely free to use, have a 128K context length, and support web search (you need to manually enable it). You can also download my app version from the official app store.
My knowledge cutoff is July 2024, and I will provide help in an enthusiastic and detailed manner. If you have any questions or need assistance, just let me know! I'll do my best to help you!
====================token usage====================
{
prompt_tokens: 5,
completion_tokens: 226,
total_tokens: 231,
completion_tokens_details: { reasoning_tokens: 81, text_tokens: 145 }
}
HTTP
Sample code
curl
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "siliconflow/deepseek-v3.2",
"messages": [
{
"role": "user",
"content": "Who are you?"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_thinking": true
}'
DashScope
Python
Sample code
import os
import dashscope
from dashscope import Generation
# The following is the configuration for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID when making a call. Configurations vary by region.
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"
# Initialize request parameters
messages = [{"role": "user", "content": "Who are you?"}]
completion = Generation.call(
# If the environment variable is not configured, replace with your Alibaba Cloud Model Studio API Key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
model="siliconflow/deepseek-v3.2",
messages=messages,
result_format="message", # Set the result format to message
enable_thinking=True,
stream=True, # Enable streaming output
incremental_output=True, # Enable incremental output
)
reasoning_content = "" # Full thinking process
answer_content = "" # Full response
is_answering = False # Tracks if the model has started answering
print("\n" + "=" * 20 + "Thinking Process" + "=" * 20 + "\n")
for chunk in completion:
message = chunk.output.choices[0].message
# Collect only the thinking content
if "reasoning_content" in message:
if not is_answering:
print(message.reasoning_content, end="", flush=True)
reasoning_content += message.reasoning_content
# When content is received, start the response
if message.content:
if not is_answering:
print("\n" + "=" * 20 + "Full Response" + "=" * 20 + "\n")
is_answering = True
print(message.content, end="", flush=True)
answer_content += message.content
print("\n" + "=" * 20 + "token usage" + "=" * 20 + "\n")
print(chunk.usage)
Response
====================Thinking Process====================
Hmm, the user asked a very basic self-introduction question. This kind of question doesn't require complex deconstruction; I just need to state my identity and core functions.
I can respond with a clear and concise structure: first, state my AI identity, then introduce my capabilities in sections, and finally end with an open-ended question to continue the conversation. Avoid being too verbose and maintain information density.
I need to be particularly careful to maintain a friendly but professional tone, use emojis to adjust the mood but not excessively. Mentioning the knowledge cutoff date and the fact that I am free can increase credibility, and ending with "at your service" can reinforce a sense of helpfulness.
====================Full Response====================
Hello! I am DeepSeek, an AI assistant created by DeepSeek!
I am a text-only model and I am good at answering various questions, assisting with writing, analyzing problems, programming, and more. While I don't support multimodal recognition, I can process uploaded images, txt, pdf, ppt, word, and excel files by reading their text content.
Some of my features:
- Completely free to use, no payment plans
- Supports a 128K context length
- App available for download from the official app store
- Supports web search (needs to be enabled manually)
- Knowledge cutoff: July 2024
I am happy to be your learning and work partner. Whether it's for daily chats, answering questions, or assisting with complex tasks, I will provide enthusiastic and detailed help! What can I do for you?
====================token usage====================
{"input_tokens": 6, "output_tokens": 265, "total_tokens": 271, "output_tokens_details": {"reasoning_tokens": 103, "text_tokens": 162}}
Java
Sample code
ImportantDashScope Java SDK version 2.19.4 or later is required.
// DashScope SDK version >= 2.19.4
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
import com.alibaba.dashscope.utils.Constants;
public class Main {
static {
// The following is the configuration for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID when making a call. Configurations vary by region.
Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
}
private static StringBuilder reasoningContent = new StringBuilder();
private static StringBuilder finalContent = new StringBuilder();
private static boolean isFirstPrint = true;
private static void handleGenerationResult(GenerationResult message) {
String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
String content = message.getOutput().getChoices().get(0).getMessage().getContent();
if (reasoning != null && !reasoning.isEmpty()) {
reasoningContent.append(reasoning);
if (isFirstPrint) {
System.out.println("====================Thinking Process====================");
isFirstPrint = false;
}
System.out.print(reasoning);
}
if (content != null && !content.isEmpty()) {
finalContent.append(content);
if (!isFirstPrint) {
System.out.println("\n====================Full Response====================");
isFirstPrint = true;
}
System.out.print(content);
}
}
private static GenerationParam buildGenerationParam(Message userMsg) {
return GenerationParam.builder()
// If the environment variable is not configured, replace the following line with your Alibaba Cloud Model Studio API Key: .apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("siliconflow/deepseek-v3.2")
.enableThinking(true)
.incrementalOutput(true)
.resultFormat("message")
.messages(Arrays.asList(userMsg))
.build();
}
public static void streamCallWithMessage(Generation gen, Message userMsg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(userMsg);
Flowable<GenerationResult> result = gen.streamCall(param);
result.blockingForEach(message -> handleGenerationResult(message));
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("Who are you?").build();
streamCallWithMessage(gen, userMsg);
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.err.println("An exception occurred: " + e.getMessage());
}
}
}
Response
====================Thinking Process====================
Hmm, the user asked a simple self-introduction question. This is a common question, so I need to quickly and clearly state my identity and function. I'll use a relaxed, friendly tone to introduce myself as DeepSeek-V3 and mention that I was created by DeepSeek. I can add the types of help I can provide, like answering questions, chatting, and tutoring, and finally use an emoji to add a touch of friendliness. No need to over-explain; keep it concise and clear.
====================Full Response====================
DeepSeek-V3, an intelligent assistant created by DeepSeek! I can help you answer various questions, provide advice, perform knowledge queries, and even chat with you! Whether it's for study, work, or questions about daily life, feel free to ask me. Is there anything I can help you with?
HTTP
Sample code
curl
# China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
"model": "siliconflow/deepseek-v3.2",
"input":{
"messages":[
{
"role": "user",
"content": "Who are you?"
}
]
},
"parameters":{
"enable_thinking": true,
"incremental_output": true,
"result_format": "message"
}
}'
Other features
| Model | ||||||
|---|---|---|---|---|---|---|
siliconflow/deepseek-v3.2 | Supported | Supported | Supported
| Not supported | Not supported | Not supported |
siliconflow/deepseek-v3.1-terminus | Supported | Supported | Supported
| Not supported | Not supported | Not supported |
siliconflow/deepseek-r1-0528 | Supported | Supported | Not supported | Not supported | Not supported | Not supported |
siliconflow/deepseek-v3-0324 | Supported | Supported | Supported | Not supported | Not supported | Not supported |
Default parameter values
Model | Temperature | Top p | Repetition penalty | Presence penalty |
|---|---|---|---|---|
siliconflow/deepseek-v3.2 | 1.0 | 1.0 | - | - |
siliconflow/deepseek-v3.1-terminus | 1.0 | 1.0 | - | - |
siliconflow/deepseek-r1-0528 | 1.0 | 1.0 | - | - |
siliconflow/deepseek-v3-0324 | 1.0 | 1.0 | - | - |
A hyphen (-) indicates that the parameter is not supported.
Models and billing
SiliconFlow uses its self-developed inference engine to provide low-latency, highly stable inference services for DeepSeek models.
- Hybrid Thinking Models (thinking is controlled by the
enable_thinkingparameter): siliconflow/deepseek-v3.2, siliconflow/deepseek-v3.1-terminus - Thinking-only models (always think before responding):
siliconflow/deepseek-r1-0528 - Non-thinking models:
siliconflow/deepseek-v3-0324
The siliconflow/deepseek-v3.2 model excels at tasks such as coding and mathematics and is offered at the lowest price. We recommend using this model first.
For information about model context length and pricing, see the Model Studio console.
Billing is based on the number of input and output tokens.
In thinking mode, the chain of thought is billed as output tokens.
Error codes
For troubleshooting, see Error Messages.