DeepSeek API offers powerful AI capabilities accessible through a format compatible with OpenAI. This means you can leverage existing OpenAI SDKs and tools with minor configuration adjustments to tap into DeepSeek's potential. This guide provides a walkthrough for making your first API call, empowering you to quickly start building applications with DeepSeek.
One of the key advantages of DeepSeek API is its design for seamless integration with the OpenAI ecosystem. Instead of learning a completely new system, developers familiar with OpenAI can quickly adapt. Here’s what you need to know:
To begin using the DeepSeek API, you'll need two crucial parameters:
Parameter | Value |
---|---|
base_url |
https://api.deepseek.com or https://api.deepseek.com/v1 (for OpenAI compatibility) |
api_key |
Obtainable from the DeepSeek Platform |
Important Notes:
v1
in the alternate base_url
has no relationship with the model's version.deepseek-chat
model has been upgraded to DeepSeek-V3. The API remains unchanged. You can invoke DeepSeek-V3 by specifying model='deepseek-chat'
.deepseek-reasoner
is the latest reasoning model, DeepSeek-R1. Invoke it by specifying model='deepseek-reasoner'
.Once you have your API key, you can use various programming languages to interact with the DeepSeek API. Here are examples using curl
, Python
, and Node.js
.
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
}'
# 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();
These examples demonstrate a basic, non-streaming request. For real-time applications, you can set the stream
parameter to true
to receive streaming responses.
Congratulations, you've made your first API call to DeepSeek! Now you can start digging deeper:
By understanding the compatibility, essential parameters, and basic API calls, you're now equipped to start building innovative applications with DeepSeek.