跳到正文
DeepSeek:API 更新日誌·· 2026-10-17AI 評分43

DeepSeek Chat API 呼叫示例

Invoke The Chat API

AI 導讀

DeepSeek 提供以 OpenAI API 格式呼叫模型的 curl、Python 和 Node.js 範例,使用 deepseek-flash,並示範啟用 thinking、設定 reasoning_effort 為 high,以及關閉串流回應。

正文

Once you have obtained an API key, you can access the DeepSeek model using the following example scripts in the OpenAI API format. This is a non-stream example, you can set the stream parameter to true to get stream response.

For examples using the Anthropic API format, please refer to Anthropic API.

Before running these examples, set the DEEPSEEK_API_KEY environment variable in your terminal to your API key.

  • curl
  • python
  • nodejs
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DEEPSEEK_API_KEY}" \
-d '{
"model": "deepseek-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"thinking": {"type": "enabled"},
"reasoning_effort": "high",
"stream": false
}'
# Please install OpenAI SDK first: `pip3 install openai`
import os
from openai import OpenAI

client = OpenAI(
api_key=os.environ.get('DEEPSEEK_API_KEY'),
base_url="https://api.deepseek.com",
)

response = client.chat.completions.create(
model="deepseek-flash",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello"},
],
stream=False,
reasoning_effort="high",
extra_body={"thinking": {"type": "enabled"}},
)

print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`

import OpenAI from "openai";

const openai = new OpenAI({
baseURL: 'https://api.deepseek.com',
apiKey: process.env.DEEPSEEK_API_KEY,
});

async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: "system", content: "You are a helpful assistant." }],
model: "deepseek-flash",
thinking: {"type": "enabled"},
reasoning_effort: "high",
stream: false,
});

console.log(completion.choices[0].message.content);
}

main();

來源:DeepSeek:API 更新日誌 · api-docs.deepseek.com