DeepSeek API offers a powerful platform for developers looking to integrate advanced AI capabilities into their applications. This article provides a comprehensive guide to help you make your first API call, understand the key features, and leverage the DeepSeek API effectively.
The DeepSeek API is designed with compatibility in mind. It uses an API format that's compatible with OpenAI. This means you can often use your existing OpenAI SDK knowledge and tools to interact with the DeepSeek API, making the transition smoother than starting from scratch. By simply modifying your configuration, you can access DeepSeek's powerful models.
deepseek-chat
) and DeepSeek-R1 (through deepseek-reasoner
). Learn more about these models in the Reasoner Model guide.Here’s a step-by-step guide to making your first API call to the DeepSeek API:
First, you need an API key. You can apply for one on the DeepSeek Platform. After creating API Key, store in safe place to avoid leakage.
The base URL for the DeepSeek API is https://api.deepseek.com
. For OpenAI compatibility, you can also use https://api.deepseek.com/v1
.
DeepSeek API documentation offers example script in cURL, Python, and NodeJS to get you started. Remember to install corresponding SDK before running the script. Python:
pip3 install openai
NodeJS:
npm install openai
Below are examples of API calls using cURL
, Python
, and NodeJS
. Make sure to replace <DeepSeek API Key>
with your actual API key.
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
}'
Python
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)
NodeJS
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.api_key
: Your unique key for authenticating with the DeepSeek API.model
: Specifies the DeepSeek model you want to use (e.g., deepseek-chat
).messages
: An array containing the conversation history.
role
: Can be "system," "user," or "assistant."content
: The actual text of the message.stream
: Set to false
for non-streaming output. Set to true
for streaming output.DeepSeek offers a variety of models tailored to different tasks. Here's a quick look at some of the key models:
DeepSeek regularly releases updates and new features. Some recent updates:
Stay informed by checking the News section and 更新日志.
The DeepSeek API offers a powerful and accessible way to integrate cutting-edge AI into your projects. By understanding its compatibility with OpenAI, exploring its diverse models, and following the steps outlined in this guide, you can start building innovative applications with DeepSeek today.