DeepSeek API offers developers a powerful suite of AI tools, readily accessible through a format compatible with the OpenAI API. This means you can leverage your existing OpenAI SDK knowledge and tools to integrate DeepSeek's advanced models into your projects with minimal adjustments.
This article will guide you through your first API call, providing a clear understanding of the necessary steps and configurations.
The DeepSeek API is designed for seamless integration, adopting an API format that aligns with OpenAI standards. This strategic compatibility allows developers familiar with the OpenAI ecosystem to quickly adapt and utilize DeepSeek's functionalities.
Key benefits of this compatibility include:
Before diving into the code, you'll need to obtain an API key and configure your environment.
You'll need an API key to authenticate your requests. You can apply for one on the DeepSeek Platform.
The base URL for the DeepSeek API is https://api.deepseek.com
. For OpenAI compatibility, you can also use https://api.deepseek.com/v1
. Note that the v1
in the URL does not refer to the model version.
DeepSeek offers various models, including:
model='deepseek-chat'
in your API request.model='deepseek-reasoner'
. You can find more information about this in the reasoning model documentation.Here's how to make your first API call using different programming languages. These examples demonstrate how to interact with the DeepSeek API to generate conversational responses.
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();
https://api.deepseek.com
or https://api.deepseek.com/v1
.deepseek-chat
, deepseek-reasoner
).role
(either "system"
, "user"
, or "assistant"
) and content
.true
for streaming responses, false
for complete responses.Once you've successfully made your first API call, you can explore more advanced features:
temperature
parameter to control the randomness of the generated text. See more details in the Temperature Settings documentation.Keep up-to-date with the latest DeepSeek API features and updates through the official news and updates pages.
The DeepSeek API offers a powerful and accessible platform for developers to integrate advanced AI capabilities into their applications. By leveraging its OpenAI compatibility and exploring its diverse features, you can build innovative solutions and enhance user experiences.