How to beginner · 3 min read

How to install DeepSeek Python SDK

Quick answer
Install the DeepSeek Python SDK by using pip install openai since DeepSeek is OpenAI-compatible and uses the openai package. Then, instantiate the client with OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"]) to start making API calls.

PREREQUISITES

  • Python 3.8+
  • DeepSeek API key
  • pip install openai>=1.0

Setup

DeepSeek does not have a separate Python SDK package. Instead, it is OpenAI-compatible and uses the openai Python package. Install it via pip and set your API key as an environment variable.

bash
pip install openai

Step by step

Use the openai package to create a client with your DeepSeek API key and call the chat completion endpoint with the deepseek-chat model.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"])

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "Hello from DeepSeek!"}]
)

print(response.choices[0].message.content)
output
Hello from DeepSeek! How can I assist you today?

Common variations

You can switch to the reasoning model deepseek-reasoner for complex queries or adjust parameters like max_tokens and temperature. Async usage is not officially supported via the SDK but can be implemented with async HTTP clients.

python
response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=[{"role": "user", "content": "Explain quantum computing in simple terms."}],
    max_tokens=500,
    temperature=0.7
)
print(response.choices[0].message.content)
output
Quantum computing uses quantum bits that can be in multiple states simultaneously, enabling faster problem solving for certain tasks.

Troubleshooting

  • If you get authentication errors, verify your DEEPSEEK_API_KEY environment variable is set correctly.
  • For network errors, check your internet connection and proxy settings.
  • If the model name is unrecognized, confirm you are using the latest openai package and correct model IDs.

Key Takeaways

  • DeepSeek uses the OpenAI-compatible openai Python package for integration.
  • Set your API key in the environment variable DEEPSEEK_API_KEY before running code.
  • Use deepseek-chat for general chat and deepseek-reasoner for reasoning tasks.
  • Adjust parameters like max_tokens and temperature to customize responses.
  • Check environment variables and model names if you encounter errors.
Verified 2026-04 · deepseek-chat, deepseek-reasoner
Verify ↗