DeepSeek API offers powerful AI capabilities, and this guide will walk you through making your first API call. The DeepSeek API is designed with compatibility in mind, using an API format similar to OpenAI's. This means you can leverage existing OpenAI SDKs and software with minimal configuration adjustments to access DeepSeek's functionalities.
One of the key advantages of the DeepSeek API is its compatibility with the OpenAI ecosystem. This allows developers familiar with OpenAI tools to quickly integrate and utilize DeepSeek's AI models.
Key takeaway: By modifying the base URL and API key, you can use OpenAI SDKs to interact with the DeepSeek API.
Before making your first API call, you'll need to set up your environment with the necessary credentials and libraries.
pip3 install openai
. For Node.js, use npm install openai
.To successfully call the DeepSeek API, you'll need to configure the base URL and provide your API key in the request header. Here's a breakdown of the essential parameters:
base_url
: This is the endpoint for the DeepSeek API. Use https://api.deepseek.com
. You can also use https://api.deepseek.com/v1
for better OpenAI compatibility. Note: The /v1
in the base URL does NOT relate to the model's version.api_key
: Your unique API key obtained from the DeepSeek Platform.Here are examples of how to invoke the Chat API using curl
, Python, and Node.js:
1. Using 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
}'
2. Using Python (with OpenAI SDK):
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)
3. Using Node.js (with OpenAI SDK):
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();
Important Considerations:
<DeepSeek API Key>
with your actual API key."stream"
parameter to true
.DeepSeek offers a range of models optimized for different tasks. Here are a couple to get you started:
deepseek-chat
: This model is now powered by DeepSeek-V3, offering improved conversational capabilities. Use this model for general chat and assistant-like tasks.deepseek-reasoner
: This model utilizes DeepSeek-R1, DeepSeek's reasoning model. Use this for complex reasoning tasks. Learn more about reasoning models in this API Guide.Congratulations on making your first API call to DeepSeek! From here, you can explore other powerful features of the DeepSeek API: