The DeepSeek API offers powerful AI capabilities, and getting started is surprisingly straightforward. This guide will walk you through making your first API call, leveraging DeepSeek's compatibility with the OpenAI API format. By the end, you'll be equipped to integrate DeepSeek's models into your projects.
One of the key advantages of the DeepSeek API is its compatibility with the OpenAI API format. This means you can often use existing OpenAI SDKs and software with minimal modification to access DeepSeek's functionalities. This compatibility reduces the learning curve and allows for a seamless transition for developers already familiar with OpenAI.
Before making your first API call, you'll need two essential pieces of information:
https://api.deepseek.com
(You can also use https://api.deepseek.com/v1
for OpenAI compatibility)Important Considerations:
https://api.deepseek.com/v1
for compatibility, the /v1
in this URL does not reflect the model's version.deepseek-chat
model is powered by DeepSeek-V3. Invoke it by specifying model='deepseek-chat'
.deepseek-reasoner
to access DeepSeek-R1, the latest reasoning model from DeepSeek.Once you have your API key, you can use various methods to interact with the DeepSeek API. Below are examples using curl
, Python, and Node.js. These examples demonstrate a non-streaming request. For streaming responses, simply set the stream
parameter to true
.
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
}'
First, install the OpenAI SDK:
pip3 install openai
Then, use the following script:
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)
First, install the OpenAI SDK:
npm install openai
Then, use the following script:
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();
Congratulations! You've successfully made your first API call to the DeepSeek API. Explore additional quick start resources:
By leveraging DeepSeek's API, users can start integrating state-of-the-art AI models into their workflows. For more advanced use cases, explore features like Function Calling and Context Caching. This will allow one to fully utilize every capability DeepSeek unlocks.