DeepSeek API offers a powerful and versatile platform for developers looking to integrate cutting-edge AI capabilities into their applications. Designed with compatibility in mind, the DeepSeek API leverages an OpenAI-compatible format, meaning you can adapt existing OpenAI SDKs and software with minimal configuration changes. This makes transitioning to DeepSeek a smooth and efficient process.
This article provides a detailed walkthrough for making your first API call, along with essential information and resources to help you get started.
deepseek-reasoner
).Before diving into the API calls, ensure you have the following prerequisites:
Depending on your preferred language, use the following commands to install the OpenAI SDK:
Python:
pip3 install openai
Node.js:
npm install openai
DeepSeek API's base URL is https://api.deepseek.com
. For OpenAI compatibility, you can also use https://api.deepseek.com/v1
as the base URL, but note that "v1" here is not related to the model version.
Here’s how to make a basic chat completion API call using curl
, Python, and Node.js:
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Your DeepSeek API Key>" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false
}'
from openai import OpenAI
client = OpenAI(
api_key="<Your 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)
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: 'https://api.deepseek.com',
apiKey: '<Your 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();
Replace <Your DeepSeek API Key>
with your actual API key.
Content-Type
header specifies that the request body is in JSON format. The Authorization
header includes your API key for authentication.model
parameter, which specifies the model to use (e.g., deepseek-chat
). The messages
array contains the conversation history, with each message having a role
(system or user) and content
. Setting stream
to false
returns the entire response at once. To use streaming, set it to true
.model='deepseek-chat'
in your API call.model='deepseek-reasoner'
to utilize this model, as detailed in the Reasoning Model Guide.To further enhance your understanding and utilization of DeepSeek API, refer to the following resources:
DeepSeek API offers a robust and accessible platform for integrating powerful AI capabilities into your applications. With its OpenAI compatibility, advanced models, and extensive documentation, getting started with DeepSeek is easier than ever. By following this guide and exploring the provided resources, you'll be well-equipped to leverage the full potential of DeepSeek API in your projects.