Registry / llm-agents / deepseek

deepseek

JSON →
library1.0.0pypypi✓ verified 26d ago

DeepSeek has NO official Python SDK. The correct integration pattern is using the openai package with base_url='https://api.deepseek.com'. The deepseek PyPI package (1.0.0) is a stub placeholder — do not use it. DeepSeek API is fully OpenAI-compatible. Two primary models: deepseek-chat (V3.2, general purpose) and deepseek-reasoner (R1, chain-of-thought reasoning).

pip install openai
INSTALL
IMPORT
SIG · DEEPSEEK
D
deepseek
llm-agentspythonv1.0.0
Install
5.8s avg
Import
2848ms
Disk
144MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 2.970s · 108.3MB
glibc
py 3.103.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)
Debug
Known issues
breakingNo official DeepSeek Python SDK exists. The 'deepseek' PyPI package (1.0.0) is an empty stub with no functionality. LLMs hallucinate 'import deepseek' or 'from deepseek import Client' — neither works.
fix
pip install openai; use OpenAI(api_key=DEEPSEEK_API_KEY, base_url='https://api.deepseek.com')
affects: all
breakingR1 reasoning model name is 'deepseek-reasoner' not 'deepseek-r1'. Wrong model name returns 404 or model not found error.
fix
model='deepseek-reasoner' for R1 thinking model. model='deepseek-chat' for V3.2 general model.
affects: all
gotchadeepseek-reasoner returns an extra reasoning_content field on the message object. Standard OpenAI response parsing misses the chain-of-thought output.
fix
Access response.choices[0].message.reasoning_content for thinking output, response.choices[0].message.content for final answer.
affects: all
gotchabase_url must be 'https://api.deepseek.com' — no trailing slash, no /v1 suffix needed. The /v1 path exists for OpenAI compatibility but has no relationship to model version.
fix
base_url='https://api.deepseek.com' — both with and without /v1 work but without is canonical.
affects: all
gotchaAPI key env var is DEEPSEEK_API_KEY not OPENAI_API_KEY. OpenAI SDK will silently use OPENAI_API_KEY if DEEPSEEK_API_KEY is not explicitly passed.
fix
Always pass api_key=os.environ['DEEPSEEK_API_KEY'] explicitly to OpenAI() constructor.
affects: all
gotchadeepseek-reasoner does not support system prompt in the same way. System prompts are accepted but may be converted to user messages internally. Behavior differs from deepseek-chat.
fix
For deepseek-reasoner use user messages for instructions, not system prompts.
affects: all
breakingThe DEEPSEEK_API_KEY environment variable must be set for authentication. The script failed with a KeyError because this required environment variable was not found.
fix
Ensure the DEEPSEEK_API_KEY environment variable is set with your DeepSeek API key before running the script (e.g., `export DEEPSEEK_API_KEY='YOUR_API_KEY'` or by configuring your execution environment).
affects: all
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.
fix
Use 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.
fix
Verify 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.
fix
Ensure 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.
fix
Remove 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+.
fix
Upgrade 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.
Agent activity
127 hits · last 30 days
node
121
OpenAI (training)
1
Resources