Fix DeepSeek model not responding
Quick answer
If your
deepseek-chat model is not responding, ensure you are using the correct OpenAI SDK v1+ pattern with the proper api_key and base_url set to https://api.deepseek.com. Verify network connectivity and that your API key is valid and has permissions. Use the official openai Python client with the client.chat.completions.create() method targeting deepseek-chat to avoid deprecated calls.PREREQUISITES
Python 3.8+DeepSeek API keypip install openai>=1.0
Setup
Install the official openai Python SDK version 1 or higher and set your DeepSeek API key as an environment variable. Use https://api.deepseek.com as the base_url to direct requests to DeepSeek's endpoint.
pip install openai>=1.0 Step by step
Use the following Python code to call the DeepSeek deepseek-chat model correctly. This example shows the minimal working code to get a chat completion response.
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="https://api.deepseek.com")
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello, DeepSeek!"}]
)
print(response.choices[0].message.content) output
Hello! How can I assist you today?
Common variations
You can switch to the deepseek-reasoner model for reasoning tasks by changing the model parameter. Async calls are not natively supported in the official SDK, so use synchronous calls. Avoid deprecated SDK methods like openai.ChatCompletion.create().
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="https://api.deepseek.com")
response = client.chat.completions.create(
model="deepseek-reasoner",
messages=[{"role": "user", "content": "Explain quantum computing."}]
)
print(response.choices[0].message.content) output
Quantum computing is a type of computation that uses quantum bits or qubits...
Troubleshooting
- If you get connection errors, verify your network and that
https://api.deepseek.comis reachable. - If authentication fails, check your
DEEPSEEK_API_KEYenvironment variable is set correctly. - If the model does not respond, confirm you are using the latest
openaiSDK and the correctmodelname. - Check for rate limits or quota issues on your DeepSeek account dashboard.
Key Takeaways
- Use the official OpenAI SDK v1+ with base_url set to https://api.deepseek.com for DeepSeek API calls.
- Always set your DeepSeek API key in the environment variable DEEPSEEK_API_KEY to avoid authentication errors.
- Use the correct model names like deepseek-chat or deepseek-reasoner to ensure responses.
- Check network connectivity and API key validity if the model is not responding.
- Avoid deprecated SDK methods and keep your openai package updated.