
If you are looking to migrate from ChatGPT to DeepSeek, the process is straightforward due to the compatibility of the DeepSeek API with the OpenAI format.
Here’s a step-by-step guide on how to make your first API call with DeepSeek.
1. Obtain Your DeepSeek API Key
First, you need to apply for an API key from DeepSeek. Visit their website to sign up and request an API key, which is required to authenticate your requests.
2. Set the Base URL
The DeepSeek API can be accessed using the following base URL:
https://api.deepseek.com
If you prefer, you can use the versioned URL:
https://api.deepseek.com/v1
Note that the v1
in the base URL is unrelated to the model’s version.
3. Choose the Right Model
The current chat model available on DeepSeek is called deepseek-chat
. If you need to access the latest reasoning model, you should use deepseek-reasoner
, which refers to the DeepSeek-R1 model.
4. Make Your First API Call
With your API key in hand, you can now interact with the DeepSeek API. Below is an example of how to invoke the chat API using curl
. You can use other SDKs, like Python or Node.js, as well.
Example using curl
:
curl https://api.deepseek.com/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{ "model": "deepseek-chat", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ], "stream": false }'
Example using Python:
import requests import json url = "https://api.deepseek.com/chat/completions" headers = { "Content-Type": "application/json", "Authorization": "Bearer " } data = { "model": "deepseek-chat", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ], "stream": False } response = requests.post(url, headers=headers, data=json.dumps(data)) print(response.json())
Example using Node.js:
const fetch = require('node-fetch'); const url = 'https://api.deepseek.com/chat/completions'; const headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ', }; const data = { model: 'deepseek-chat', messages: [ { role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Hello!' } ], stream: false }; fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(data), }) .then(response => response.json()) .then(json => console.log(json));
5. Handle Streaming Responses
If you wish to handle streaming responses, simply set the stream
parameter to true
in your request. This will allow you to receive a continuous stream of results as they are generated, similar to the behavior in the OpenAI API.
6. Conclusion
By following these steps, you can easily migrate from using ChatGPT to using DeepSeek for your AI needs. The API structure is similar to OpenAI, making the transition seamless.
DeepSeek is cheaper than ChatGPT. Happy coding!