DeepSeek API offers powerful language models accessible through a user-friendly API format compatible with OpenAI. This compatibility allows developers to leverage existing OpenAI SDKs and software, streamlining the integration process. This article will guide you through making your first API call to the DeepSeek API.
The DeepSeek API is designed to be easily integrated into your projects. Thanks to its OpenAI-compatible format, developers can quickly adapt their existing workflows to utilize DeepSeek's advanced language models.
Here's what you need to know:
https://api.deepseek.com
. You can also use https://api.deepseek.com/v1
for OpenAI compatibility. Note that the /v1
does not correspond to the model version.deepseek-chat
model has been upgraded to DeepSeek-V3. The API remains unchanged. Invoke DeepSeek-V3 by specifying model='deepseek-chat'
.deepseek-reasoner
is the latest reasoning model, DeepSeek-R1. Invoke DeepSeek-R1 by specifying model='deepseek-reasoner'
.Once you have your API key, you can start making requests to the DeepSeek API. The following examples demonstrate how to invoke the Chat API using curl
, Python, and NodeJS.
Essential Parameters:
Before diving into the code, here are the key parameters you'll need:
base_url
: https://api.deepseek.com
api_key
: Your unique API key obtained from the DeepSeek platform.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
}'
This command sends a request to the /chat/completions
endpoint with a simple conversation. Replace <DeepSeek API Key>
with your actual API key. The "stream": false
parameter indicates that the API should return the complete response at once, as opposed to streaming it.
# 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)
This Python script utilizes the OpenAI SDK. Remember to install the OpenAI library before running this code using pip3 install openai
. Again, replace <DeepSeek API Key>
with your actual API key.
// 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();
This NodeJS example also uses the OpenAI SDK. Install it with npm install openai
. Replace <DeepSeek API Key>
with your actual API key.
Congratulations on making your first API call to the DeepSeek API! Now that you've successfully connected, consider exploring these next steps:
By leveraging the DeepSeek API's power and flexibility, you can create innovative applications and experiences. This guide provides a starting point for your journey with DeepSeek's language models.