DeepSeek API offers a powerful and versatile platform for developers looking to integrate advanced AI capabilities into their applications. This article will guide you through your first API call, explaining the fundamentals and providing practical examples to get you up and running quickly.
DeepSeek API is designed to be compatible with the OpenAI API format. This compatibility allows you to seamlessly use the OpenAI SDK or other software that supports the OpenAI API by simply modifying the configuration.
deepseek-chat
) and DeepSeek-R1 (via deepseek-reasoner
).Before making your first API call, ensure you have the following:
pip3 install openai
(Python) or npm install openai
(Node.js).To connect to the DeepSeek API, you'll primarily need the base_url
and your api_key
. Here's how they are used:
Parameter | Value |
---|---|
base_url |
https://api.deepseek.com |
api_key |
Your API key from DeepSeek Platform |
For OpenAI compatibility, you can also set the base_url
to https://api.deepseek.com/v1
. Note that the v1
here is for compatibility and doesn't relate to model versions.
Let's walk through a basic example using the deepseek-chat
model (now upgraded to DeepSeek-V3) to generate a conversational response.
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
}'
<DeepSeek API Key>
with your actual API key.messages
array contains a system message defining the assistant's role and a user message with the initial prompt.stream: false
specifies a non-streaming output.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)
<DeepSeek API Key>
with your API key.chat.completions.create
method sends the request and returns the response.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();
<DeepSeek API Key>
with your actual API key.DeepSeek also offers a powerful reasoning model, DeepSeek-R1, accessible via the deepseek-reasoner
model name. This reasoning model is designed for more complex tasks requiring logical inference and problem-solving.
To use DeepSeek-R1, simply replace "model": "deepseek-chat"
with "model": "deepseek-reasoner"
in your API calls.
Congratulations on making your first API call to DeepSeek! Now that you've grasped the basics, here are some suggestions for next steps:
By following this guide and exploring the available resources, you'll be well-equipped to leverage the power of DeepSeek API in your projects.