How to beginner · 3 min read

How to run DeepSeek locally

Quick answer
DeepSeek models run primarily as cloud APIs and do not have an official local runtime. To use DeepSeek locally, you can run a local LLM server compatible with OpenAI API calls and point your client to it using the base_url parameter. This enables local inference with DeepSeek models if you have a local deployment or private instance.

PREREQUISITES

  • Python 3.8+
  • DeepSeek API key (if using cloud)
  • pip install openai>=1.0
  • Access to a local DeepSeek-compatible LLM server (optional)

Setup

DeepSeek does not provide an official local runtime or downloadable model weights. However, you can run a local LLM server that supports the OpenAI API specification and configure your Python client to connect to it. This requires installing the openai Python package and setting your environment variables.

  • Install the OpenAI SDK compatible with DeepSeek API calls:
bash
pip install openai>=1.0

Step by step

Here is a complete example to run DeepSeek locally by connecting to a local server that implements the OpenAI-compatible API. Replace http://localhost:8000/v1 with your local server URL and set your API key in the environment.

python
import os
from openai import OpenAI

# Set your DeepSeek API key in environment variable DEEPSEEK_API_KEY
client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="http://localhost:8000/v1")

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

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

Common variations

You can use different DeepSeek models such as deepseek-chat or deepseek-reasoner by changing the model parameter. For asynchronous calls, use Python asyncio with the OpenAI SDK's async client. Streaming responses are also supported by the SDK.

python
import asyncio
import os
from openai import OpenAI

async def main():
    client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="http://localhost:8000/v1")
    response = await client.chat.completions.acreate(
        model="deepseek-chat",
        messages=[{"role": "user", "content": "Stream response example."}]
    )
    print(response.choices[0].message.content)

asyncio.run(main())
output
Streaming response example. How can I help you further?

Troubleshooting

  • If you get connection errors, verify your local server is running and accessible at the base_url.
  • Ensure your API key is correctly set in the environment variable DEEPSEEK_API_KEY.
  • If the model is not found, confirm your local server supports the requested DeepSeek model names.

Key Takeaways

  • DeepSeek does not officially support local model downloads but can be accessed via a local OpenAI-compatible server.
  • Use the OpenAI Python SDK with the base_url parameter to connect to local DeepSeek servers.
  • Set your API key in environment variables to authenticate requests securely.
  • You can run asynchronous and streaming calls with the OpenAI SDK for DeepSeek locally.
  • Check server availability and model support if you encounter connection or model errors.
Verified 2026-04 · deepseek-chat, deepseek-reasoner
Verify ↗