DeepSeek API offers a powerful suite of tools for developers looking to integrate advanced AI capabilities into their applications. This article will guide you through making your first API call, providing a practical introduction to using the DeepSeek API.
The DeepSeek API is designed to be compatible with the OpenAI API format. This means you can leverage existing OpenAI SDKs and tools with minimal configuration changes, making the transition smooth and efficient.
Before making your first call, you'll need a few things:
https://api.deepseek.com
. You can also use https://api.deepseek.com/v1
for OpenAI compatibility.Here's how to make a basic API call to the DeepSeek chat endpoint 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();
base_url
: Specifies the API endpoint (https://api.deepseek.com
).api_key
: Your unique API key for authentication.model
: Specifies the model to use (e.g., deepseek-chat
).messages
: An array containing the conversation history.stream
: A boolean value. Set to true
for streaming responses.DeepSeek offers a range of models tailored for different tasks:
deepseek-chat
: is now upgraded to DeepSeek-V3. Invoke DeepSeek-V3 by specifying model='deepseek-chat'.deepseek-reasoner
: DeepSeek-R1, released by DeepSeek, is the latest reasoning model. Invoke DeepSeek-R1 by specifying model='deepseek-reasoner'.By following this guide, you should be well-equipped to make your first API call to the DeepSeek API and begin exploring its capabilities.