{"id":145,"library":"deepseek","title":"DeepSeek API","description":"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).","status":"active","version":"API only — no SDK version","language":"python","source_language":"en","source_url":"https://api-docs.deepseek.com/","tags":["deepseek","llm","openai-compatible","python","r1","v3","reasoning"],"install":[{"cmd":"pip install openai","lang":"bash","label":"Python (correct — use openai SDK with DeepSeek base_url)"}],"dependencies":[{"reason":"DeepSeek API is OpenAI-compatible. Use openai SDK with base_url override. No separate DeepSeek package needed.","package":"openai","optional":false}],"imports":[{"note":"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'.","wrong":"import deepseek\nclient = deepseek.Client(api_key='...')","symbol":"DeepSeek via OpenAI SDK","correct":"from openai import OpenAI\nimport os\n\nclient = OpenAI(\n    api_key=os.environ['DEEPSEEK_API_KEY'],\n    base_url='https://api.deepseek.com'\n)\n\nresponse = client.chat.completions.create(\n    model='deepseek-chat',\n    messages=[\n        {'role': 'system', 'content': 'You are a helpful assistant'},\n        {'role': 'user', 'content': 'Hello'}\n    ],\n    stream=False\n)\nprint(response.choices[0].message.content)"},{"note":"Model name is 'deepseek-reasoner' not 'deepseek-r1'. Reasoning model returns extra reasoning_content field not present in standard OpenAI responses.","wrong":"response = client.chat.completions.create(\n    model='deepseek-r1',  # wrong model name\n    messages=[...]\n)","symbol":"deepseek-reasoner (R1 thinking model)","correct":"from openai import OpenAI\n\nclient = OpenAI(\n    api_key='DEEPSEEK_API_KEY',\n    base_url='https://api.deepseek.com'\n)\n\nresponse = client.chat.completions.create(\n    model='deepseek-reasoner',  # R1 thinking model\n    messages=[{'role': 'user', 'content': 'Solve: 2x + 5 = 13'}]\n)\n# Access reasoning content separately\nreasoning = response.choices[0].message.reasoning_content\nanswer = response.choices[0].message.content\nprint(reasoning)\nprint(answer)"}],"quickstart":{"code":"# pip install openai\nfrom openai import OpenAI\nimport os\n\nclient = OpenAI(\n    api_key=os.environ['DEEPSEEK_API_KEY'],\n    base_url='https://api.deepseek.com'\n)\n\nresponse = client.chat.completions.create(\n    model='deepseek-chat',\n    messages=[\n        {'role': 'system', 'content': 'You are a helpful assistant'},\n        {'role': 'user', 'content': 'What is the capital of France?'}\n    ]\n)\nprint(response.choices[0].message.content)","lang":"python","description":"Minimal DeepSeek API call using openai SDK with base_url override."},"warnings":[{"fix":"pip install openai; use OpenAI(api_key=DEEPSEEK_API_KEY, base_url='https://api.deepseek.com')","message":"No 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.","severity":"breaking","affected_versions":"all"},{"fix":"model='deepseek-reasoner' for R1 thinking model. model='deepseek-chat' for V3.2 general model.","message":"R1 reasoning model name is 'deepseek-reasoner' not 'deepseek-r1'. Wrong model name returns 404 or model not found error.","severity":"breaking","affected_versions":"all"},{"fix":"Access response.choices[0].message.reasoning_content for thinking output, response.choices[0].message.content for final answer.","message":"deepseek-reasoner returns an extra reasoning_content field on the message object. Standard OpenAI response parsing misses the chain-of-thought output.","severity":"gotcha","affected_versions":"all"},{"fix":"base_url='https://api.deepseek.com' — both with and without /v1 work but without is canonical.","message":"base_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.","severity":"gotcha","affected_versions":"all"},{"fix":"Always pass api_key=os.environ['DEEPSEEK_API_KEY'] explicitly to OpenAI() constructor.","message":"API 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.","severity":"gotcha","affected_versions":"all"},{"fix":"For deepseek-reasoner use user messages for instructions, not system prompts.","message":"deepseek-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.","severity":"gotcha","affected_versions":"all"},{"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).","message":"The DEEPSEEK_API_KEY environment variable must be set for authentication. The script failed with a KeyError because this required environment variable was not found.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T08:43:20.716Z","next_check":"2026-06-24T00:00:00.000Z","problems":[{"fix":"Use the `openai` Python package and configure it with DeepSeek's API base URL. Do not install or import 'deepseek' directly.","cause":"Developers are attempting to import from a non-existent DeepSeek Python SDK; DeepSeek API is designed to be used with the OpenAI Python client.","error":"ModuleNotFoundError: No module named 'deepseek'"},{"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.","cause":"The provided DeepSeek API key is either missing, incorrect, expired, or has insufficient permissions.","error":"openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Invalid API Key' ...}}"},{"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.","cause":"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.","error":"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'}}"},{"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.","cause":"DeepSeek API does not support the `response_format` parameter for structured outputs as implemented in some OpenAI SDK versions or wrappers.","error":"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'}}"},{"fix":"Upgrade your `openai` Python package to the latest version (`pip install --upgrade openai`) to use the `client.chat.completions.create` syntax.","cause":"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+.","error":"AttributeError: 'OpenAI' object has no attribute 'ChatCompletion'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.69,"mem_mb":23.6,"disk_size":"102.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.21,"mem_mb":23.6,"disk_size":"172M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.34,"mem_mb":25.4,"disk_size":"111.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.99,"mem_mb":26.1,"disk_size":"180M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.29,"mem_mb":25.2,"disk_size":"101.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.27,"mem_mb":25.2,"disk_size":"171M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.04,"mem_mb":26.2,"disk_size":"100.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.07,"mem_mb":26.2,"disk_size":"170M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.67,"mem_mb":24.5,"disk_size":"101.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.49,"mem_mb":24.5,"disk_size":"171M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}