DeepSeek API is designed to be compatible with the OpenAI API format, enabling you to leverage your existing OpenAI SDK skills and software to access DeepSeek's powerful AI models. This guide will walk you through your first API call, providing a solid foundation for building innovative applications.
One of the key advantages of DeepSeek API is its compatibility with the OpenAI ecosystem. By making a few configuration adjustments, you can seamlessly transition your projects to utilize DeepSeek's cutting-edge models. This compatibility extends to various software solutions that are already designed to work with the OpenAI API.
To begin using the DeepSeek API, you'll need two essential components:
https://api.deepseek.com
. For OpenAI compatibility, you can also use https://api.deepseek.com/v1
. Note that the v1
in the URL is for compatibility and does not reflect the model version.Stay up-to-date with DeepSeek's model advancements:
deepseek-chat
model has been fully upgraded to DeepSeek-V3. You can access it by specifying model='deepseek-chat'
in your API calls.deepseek-reasoner
. To utilize DeepSeek-R1, specify model='deepseek-reasoner'
. Check here for more information about reasoning model.After obtaining your API key, you can use the following code snippets to interact with the DeepSeek API. These examples demonstrate non-streaming output, but you can easily enable streaming by setting stream
to true
.
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
}'
# Please install OpenAI SDK first: `pip3 install openai`
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)
// Please install OpenAI SDK first: `npm install openai`
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();
By following this guide, you're well on your way to harnessing the power of DeepSeek AI for your projects.