DeepSeek API provides a powerful platform for integrating AI capabilities into your applications. Designed with compatibility in mind, it leverages the OpenAI-compatible API format, allowing you to seamlessly transition using the OpenAI SDK or other compatible software. This guide will walk you through the process of making your first API call and highlight key features for a smooth start.
deepseek-chat
) and DeepSeek-R1 (via deepseek-reasoner
).Before you begin, you'll need the following:
pip3 install openai
npm install openai
DeepSeek follows a standard API structure. Here's a breakdown using curl
, Python, and Node.js:
Key Parameters:
base_url
: https://api.deepseek.com
(or https://api.deepseek.com/v1
for OpenAI compatibility)api_key
: Your DeepSeek API key.model
: Specifies the DeepSeek model to use (e.g., deepseek-chat
, deepseek-reasoner
).curl
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <DeepSeek API Key>" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false
}'
from openai import OpenAI
client = OpenAI(
api_key="<DeepSeek API Key>",
base_url="https://api.deepseek.com"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello"},
],
stream=False
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: 'https://api.deepseek.com',
apiKey: '<DeepSeek API Key>'
});
async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: "system", content: "You are a helpful assistant." }],
model: "deepseek-chat",
});
console.log(completion.choices[0].message.content);
}
main();
model
: Crucially defines which DeepSeek model will process your request. Use "deepseek-chat"
to access DeepSeek-V3, and "deepseek-reasoner"
for DeepSeek-R1.messages
: An array of message objects defining the conversation history. Each object includes a role
(either "system", "user", or "assistant") and corresponding content
.stream
: Set to true
for streaming output, enabling real-time responses. Set to false
for a single, complete response.Once you've successfully made your first API call, explore the API documentation for more advanced features and models. Consider these next steps:
temperature
parameter to control the randomness and creativity of the generated text. Learn more on the Temperature Settings page.deepseek-reasoner
for advanced reasoning tasks. See API Guides for instructions.DeepSeek regularly releases new models, features, and updates. Stay informed through the following channels:
By following this guide, you're well on your way to harnessing the power of DeepSeek API in your projects. Remember to consult the official documentation for comprehensive information and explore the various models and functionalities available.