DeepSeek API offers a powerful suite of tools for developers looking to integrate advanced AI capabilities into their applications. This guide will walk you through your first API call and show you how to leverage DeepSeek's functionality. The DeepSeek API is designed to be compatible with the OpenAI API format, allowing you to use the OpenAI SDK and other compatible software with minimal configuration changes.
One of the key advantages of DeepSeek API is its compatibility with the OpenAI API format. This means you can adapt existing code and tools designed for OpenAI to work with DeepSeek, reducing development time and enabling a smooth transition. By simply modifying the configuration, you can seamlessly integrate DeepSeek’s models into your projects.
Let's dive into making your first API call to the DeepSeek API. Here’s what you need to get started:
https://api.deepseek.com
. You can also use https://api.deepseek.com/v1
for OpenAI compatibility, though the v1
here doesn't refer to the model version.Once you have your API key, you can use the following examples to access the DeepSeek API. These examples demonstrate a non-streaming output. If you prefer streaming output, set stream
to true
.
Here's how to call the Chat API using curl
, Python, and Node.js:
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
}'
# Please install OpenAI SDK first: `pip3 install openai`
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)
// Please install OpenAI SDK first: `npm install openai`
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();
pip3 install openai
for Python or npm install openai
for Node.js.deepseek-chat
is used in the examples, and it now utilizes DeepSeek-V3 under the hood.Authorization
header.DeepSeek offers various models tailored for different use cases, each with unique capabilities. To specify a particular model, use the model parameter in your API request.
deepseek-chat
model, ideal for general conversational tasks. Invoke by setting model='deepseek-chat'
.model='deepseek-reasoner'
.Once you've made your first API call, there's a whole range of features & functionalities to explore:
By following this guide, you're well-equipped to start building amazing applications with the DeepSeek API. Good luck, and happy coding!