Your First API Call
The DeepSeek API uses an API format compatible with OpenAI. By modifying the configuration, you can use the OpenAI SDK or softwares compatible with the OpenAI API to access the DeepSeek API.
| PARAM | VALUE |
|---|---|
| base_url* | https://api.deepseek.com |
| api_key | apply for anAPI key |
* To be compatible with OpenAI, you can also usehttps://api.deepseek.com/v1 as thebase_url. But note that thev1 here has NO relationship with the model's version.
*Thedeepseek-chat anddeepseek-reasoner correspond to the model version DeepSeek-V3.2 (128K context limit), which differs from the APP/WEB version.deepseek-chat is thenon-thinking mode of DeepSeek-V3.2 anddeepseek-reasoner is thethinking mode of DeepSeek-V3.2.
Invoke The Chat API
Once you have obtained an API key, you can access the DeepSeek API using the following example scripts. This is a non-stream example, you can set thestream parameter totrue to get stream response.
- curl
- python
- nodejs
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`
import os
from openaiimport OpenAI
client= OpenAI(api_key=os.environ.get('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`
importOpenAIfrom"openai";
const openai=newOpenAI({
baseURL:'https://api.deepseek.com',
apiKey: process.env.DEEPSEEK_API_KEY,
});
asyncfunctionmain(){
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();