Install & Compatibility
Where this runs
tested against v? · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 2.970s · 108.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 5.8s · import 2.726s · 178MB
144MB installed
● package 144MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
DeepSeek via OpenAI SDK
✓ from openai import OpenAI
import os
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': 'system', 'content': 'You are a helpful assistant'},
{'role': 'user', 'content': 'Hello'}
],
stream=False
)
print(response.choices[0].message.content)
✗ import deepseek
client = deepseek.Client(api_key='...')
No deepseek Python package exists. The deepseek PyPI stub (1.0.0) has no functionality. Always use openai SDK with base_url='https://api.deepseek.com'.
deepseek-reasoner (R1 thinking model)
✓ from openai import OpenAI
client = OpenAI(
api_key='DEEPSEEK_API_KEY',
base_url='https://api.deepseek.com'
)
response = client.chat.completions.create(
model='deepseek-reasoner', # R1 thinking model
messages=[{'role': 'user', 'content': 'Solve: 2x + 5 = 13'}]
)
# Access reasoning content separately
reasoning = response.choices[0].message.reasoning_content
answer = response.choices[0].message.content
print(reasoning)
print(answer)
✗ response = client.chat.completions.create(
model='deepseek-r1', # wrong model name
messages=[...]
)
Model name is 'deepseek-reasoner' not 'deepseek-r1'. Reasoning model returns extra reasoning_content field not present in standard OpenAI responses.
Minimal DeepSeek API call using openai SDK with base_url override.
# pip install openai
from openai import OpenAI
import os
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': 'system', 'content': 'You are a helpful assistant'},
{'role': 'user', 'content': 'What is the capital of France?'}
]
)
print(response.choices[0].message.content)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'deepseek'
Developers are attempting to import from a non-existent DeepSeek Python SDK; DeepSeek API is designed to be used with the OpenAI Python client.
fixUse the `openai` Python package and configure it with DeepSeek's API base URL. Do not install or import 'deepseek' directly.
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Invalid API Key' ...}}
The provided DeepSeek API key is either missing, incorrect, expired, or has insufficient permissions.
fixVerify your DeepSeek API key in your DeepSeek dashboard, ensure it's correctly set as an environment variable or passed directly to the `OpenAI` client, and check your account balance.
Error code: 400 - {'error': {'message': "Failed to deserialize the JSON body into the target type: messages[X]: invalid type: sequence, expected a string at line 1 column YYY", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
DeepSeek API expects message content to be a simple string, but the request sent an array or a complex object for the message content, often seen with advanced OpenAI SDK features like structured outputs or vision API compatibility which DeepSeek may not fully support.
fixEnsure that the `content` field within your `messages` array is always a simple string, rather than an array of parts or a complex JSON object.
Error: OpenAI inference failed: Error code: 400 - {'error': {'message': 'This response_format type is unavailable now', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
DeepSeek API does not support the `response_format` parameter for structured outputs as implemented in some OpenAI SDK versions or wrappers.
fixRemove the `response_format` parameter from your `chat.completions.create` call. Instead, prompt the model to generate JSON and then parse the string response manually.
AttributeError: 'OpenAI' object has no attribute 'ChatCompletion'
This error occurs when using an older version of the `openai` Python package (v0.28.1 or earlier) with code written for the newer, breaking changes introduced in `openai` v1.0.0+.
fixUpgrade your `openai` Python package to the latest version (`pip install --upgrade openai`) to use the `client.chat.completions.create` syntax.
Upgrade
Version history
1.0.0latest on PyPI · released Jan 3, 2025
Audit
Dependencies
openairequiredDeepSeek API is OpenAI-compatible. Use openai SDK with base_url override. No separate DeepSeek package needed.