DeepSeek API offers powerful AI capabilities, and the best part is its compatibility with the OpenAI API format. This means you can leverage existing OpenAI SDKs and tools with minimal configuration changes to access DeepSeek's advanced models. This guide will walk you through making your first API call to the DeepSeek API.
The DeepSeek API is designed to be easily adopted by developers already familiar with OpenAI. By simply adjusting the base URL and API key, you can seamlessly integrate DeepSeek's models into your existing projects.
Here's how it works:
Before making your first call, you'll need the following:
PARAMETER | VALUE |
---|---|
base_url |
https://api.deepseek.com (or https://api.deepseek.com/v1 for OpenAI compatibility) |
api_key |
Obtain an API key from the DeepSeek Platform. |
Note: While you can use https://api.deepseek.com/v1
for base_url for OpenAI compatibility, the /v1
here does NOT correlate with the model's version.
Once you have your API key, you can use various programming languages to interact with the DeepSeek API. Here are a few examples:
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: `pip 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();
Explanation:
<Your DeepSeek API Key>
with your actual API key.model
parameter specifies which DeepSeek model to use (e.g., "deepseek-chat").messages
array contains the conversation history. The system
role sets the behavior of the assistant, and the user
role contains the user's input.stream: false
indicates a non-streaming response. Set to true
for a streaming response.deepseek-chat
model has been upgraded to DeepSeek-V3. The API remains unchanged; continue using model='deepseek-chat'
to invoke DeepSeek-V3.model='deepseek-reasoner'
.You've now successfully made your first API call! To enhance your experience, explore these resources:
By understanding the core components and leveraging the provided examples, you're well-equipped to integrate DeepSeek's powerful AI models into your projects.