DeepSeek — Complete Guide to China's Frontier Open-Source LLM 2026

Sanjeev SharmaSanjeev Sharma
8 min read

Advertisement

Introduction

Why This Matters

DeepSeek AI made global headlines when DeepSeek-R1 achieved reasoning scores competitive with OpenAI's o1 model at a fraction of the training cost. Released as fully open weights under the MIT license, DeepSeek-R1 demonstrated that frontier-quality reasoning models are no longer exclusive to the largest American AI labs. DeepSeek-V3, the underlying dense model, is a 671B MoE model that rivals GPT-4o across general tasks.

For developers and ML engineers, the DeepSeek ecosystem offers a compelling value proposition: state-of-the-art reasoning via API at costs significantly below OpenAI, fully open weights for self-hosting, and specialized models like DeepSeek-Coder that excel at code generation. Understanding how to use DeepSeek models effectively — via API, Ollama, or Hugging Face — is important for anyone building cost-efficient, high-capability AI applications in 2026.

DeepSeek Model Family

ModelParametersTypeLicenseBest for
DeepSeek-V2236B (MoE)Chat/APICustomGeneral tasks via API
DeepSeek-V3671B (MoE)Chat/APIMITFrontier general quality
DeepSeek-R1671B (MoE)ReasoningMITMulti-step reasoning, math
DeepSeek-R1-Distill-Qwen-7B7BReasoning distillMITLocal reasoning on GPU
DeepSeek-R1-Distill-Llama-8B8BReasoning distillMITLocal reasoning on GPU
DeepSeek-Coder-V2236B (MoE)CodeCustomCode generation via API
DeepSeek-Coder-7B-Instruct7BCodeCustomLocal code generation

Quick Start with Ollama

# DeepSeek-R1 distilled to 7B — local reasoning model
ollama pull deepseek-r1:7b
ollama run deepseek-r1:7b "Solve this step by step: A train travels 120 km at 60 km/h. How long does it take?"
 
# DeepSeek-Coder — code generation
ollama pull deepseek-coder
ollama run deepseek-coder "Write a Python implementation of merge sort with time complexity comments."

Using the DeepSeek API

DeepSeek provides an OpenAI-compatible API, so migration from OpenAI is minimal:

pip install openai  # DeepSeek uses the OpenAI SDK
from openai import OpenAI
 
# DeepSeek API is OpenAI-compatible
client = OpenAI(
    api_key="your-deepseek-api-key",
    base_url="https://api.deepseek.com/v1",
)
 
response = client.chat.completions.create(
    model="deepseek-chat",   # Maps to DeepSeek-V3
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain the attention mechanism in transformers."},
    ],
    max_tokens=500,
    temperature=0.7,
)
 
print(response.choices[0].message.content)
# DeepSeek-R1 for complex reasoning tasks
response = client.chat.completions.create(
    model="deepseek-reasoner",  # DeepSeek-R1
    messages=[
        {"role": "user", "content": "Prove that the square root of 2 is irrational."},
    ],
    max_tokens=2000,
)
 
# R1 exposes its reasoning chain
print("Reasoning:", response.choices[0].message.reasoning_content)
print("Answer:", response.choices[0].message.content)

Streaming Responses

stream = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "Explain Docker networking in detail."}],
    max_tokens=800,
    stream=True,
)
 
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

Local Deployment with Hugging Face Transformers

For the smaller distilled variants that fit on consumer hardware:

pip install transformers torch accelerate bitsandbytes
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch
 
# DeepSeek-R1 Distilled 7B — local reasoning on RTX 3080
model_id = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
 
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)
 
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=bnb_config,
    device_map="auto",
    trust_remote_code=True,
)

Generating with DeepSeek-R1 (Thinking Tokens)

DeepSeek-R1 generates a <think> block before its final answer. This chain-of-thought is visible in local inference:

def reason_and_answer(problem: str) -> dict:
    """Generate a step-by-step reasoning chain plus final answer."""
    messages = [{"role": "user", "content": problem}]
    formatted = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True,
    )
 
    inputs = tokenizer(formatted, return_tensors="pt").to(model.device)
    outputs = model.generate(
        **inputs,
        max_new_tokens=1024,
        temperature=0.6,   # R1 prefers lower temperature for reasoning
        do_sample=True,
        pad_token_id=tokenizer.eos_token_id,
    )
 
    new_tokens = outputs[0][inputs["input_ids"].shape[1]:]
    full_response = tokenizer.decode(new_tokens, skip_special_tokens=True)
 
    # Split thinking chain from final answer
    if "</think>" in full_response:
        parts = full_response.split("</think>")
        thinking = parts[0].replace("<think>", "").strip()
        answer = parts[1].strip()
    else:
        thinking = ""
        answer = full_response.strip()
 
    return {"thinking": thinking, "answer": answer}
 
result = reason_and_answer("If you have 3 boxes each with 7 apples, and you give away 12 apples, how many remain?")
print("Reasoning chain:", result["thinking"][:500], "...")
print("\nFinal answer:", result["answer"])

DeepSeek-Coder for Code Generation

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
 
model_id = "deepseek-ai/deepseek-coder-7b-instruct-v1.5"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True,
)
 
def generate_code(task: str, language: str = "Python") -> str:
    messages = [
        {"role": "system", "content": f"You are an expert {language} programmer. Write clean, well-commented code."},
        {"role": "user", "content": task},
    ]
    formatted = tokenizer.apply_chat_template(
        messages, tokenize=False, add_generation_prompt=True
    )
    inputs = tokenizer(formatted, return_tensors="pt").to(model.device)
    outputs = model.generate(
        **inputs,
        max_new_tokens=800,
        temperature=0.2,   # Low temperature for deterministic code
        do_sample=True,
        pad_token_id=tokenizer.eos_token_id,
    )
    new_tokens = outputs[0][inputs["input_ids"].shape[1]:]
    return tokenizer.decode(new_tokens, skip_special_tokens=True)
 
code = generate_code("Implement a LRU cache class with get and put methods in O(1) time complexity.")
print(code)

LangChain Integration via API

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
 
# LangChain works with DeepSeek via the OpenAI-compatible interface
llm = ChatOpenAI(
    model="deepseek-chat",
    api_key="your-deepseek-api-key",
    base_url="https://api.deepseek.com/v1",
    temperature=0.7,
)
 
prompt = ChatPromptTemplate.from_template(
    "Explain {topic} with a concrete example in {language}."
)
 
chain = prompt | llm | StrOutputParser()
result = chain.invoke({"topic": "async/await", "language": "Python"})
print(result)

Multi-turn Chat Application

from openai import OpenAI
 
client = OpenAI(
    api_key="your-deepseek-api-key",
    base_url="https://api.deepseek.com/v1",
)
 
class DeepSeekChat:
    def __init__(self, model: str = "deepseek-chat", system: str = "You are a helpful assistant."):
        self.model = model
        self.messages = [{"role": "system", "content": system}]
 
    def chat(self, user_input: str, max_tokens: int = 500) -> str:
        self.messages.append({"role": "user", "content": user_input})
        response = client.chat.completions.create(
            model=self.model,
            messages=self.messages,
            max_tokens=max_tokens,
            temperature=0.7,
        )
        assistant_content = response.choices[0].message.content
        self.messages.append({"role": "assistant", "content": assistant_content})
        return assistant_content
 
    def reset(self):
        self.messages = [self.messages[0]]  # Preserve system prompt
 
# Usage
bot = DeepSeekChat(system="You are an expert Python tutor.")
print(bot.chat("What is a Python metaclass?"))
print(bot.chat("Show me a practical example."))

DeepSeek Pricing vs Competitors (2026)

ProviderModelInput (per 1M tokens)Output (per 1M tokens)
DeepSeekdeepseek-chat (V3)$0.27$1.10
DeepSeekdeepseek-reasoner (R1)$0.55$2.19
OpenAIgpt-4o$2.50$10.00
OpenAIgpt-4o-mini$0.15$0.60
Anthropicclaude-3-5-sonnet$3.00$15.00

DeepSeek-V3 via API delivers GPT-4-class quality at roughly 90% lower cost, making it the most cost-efficient frontier-quality API in 2026.

Common Mistakes

  • Using trust_remote_code=False with DeepSeek models — DeepSeek models use custom code in their model repository; trust_remote_code=True is required for local inference
  • Ignoring the <think> blocks in R1 output — DeepSeek-R1 prefixes its answer with a <think>...</think> reasoning chain; parse it out before displaying to end users
  • Using high temperature for coding tasks — code generation benefits from low temperature (0.1-0.2); high temperature introduces syntax errors and logical bugs
  • Not caching the API client — instantiate the OpenAI client once at module level, not on every request, to avoid connection overhead
  • Confusing deepseek-chat and deepseek-reasonerdeepseek-chat is faster and cheaper for general tasks; deepseek-reasoner (R1) is for complex multi-step problems and is slower

Best Practices

  • Use the DeepSeek API for production workloads — V3 and R1 via API are far more capable than any locally-runnable quantized variant
  • Use DeepSeek-R1-Distill-Qwen-7B locally when you need reasoning capability without cloud dependency — it retains significant R1 reasoning quality at 7B parameters
  • Set temperature to 0.6 for R1 model calls — the DeepSeek team recommends this value for optimal reasoning performance
  • Parse the <think> block from R1 outputs and either display it in a collapsible UI component or log it separately for debugging
  • Monitor API costs using the usage object in each response: response.usage.prompt_tokens, response.usage.completion_tokens

Key Takeaways

  • DeepSeek-R1 achieved reasoning scores competitive with OpenAI's o1 model and was released as open weights under the MIT license — a landmark moment for open-source AI
  • DeepSeek-V3 is a 671B Mixture of Experts model with ~37B active parameters per forward pass, enabling frontier quality at efficient inference cost
  • The DeepSeek API is OpenAI-compatible — switching from OpenAI requires only changing api_key and base_url in the client initialization
  • DeepSeek-V3 pricing (~0.27input/0.27 input / 1.10 output per 1M tokens) is roughly 90% cheaper than GPT-4o for comparable quality tasks
  • DeepSeek-R1 generates a visible chain-of-thought inside <think>...</think> tags before its final answer — this can be parsed and logged for transparency
  • Local deployment is practical using the distilled variants: R1-Distill-Qwen-7B fits on a single RTX 3080 with 4-bit quantization
  • DeepSeek-Coder-V2 is competitive with GPT-4 on HumanEval and other coding benchmarks and is available via the API
  • Use temperature 0.6 for R1 (reasoning tasks) and 0.1-0.2 for DeepSeek-Coder (code generation) — the team explicitly recommends these values

Advertisement

Sanjeev Sharma

Written by

Sanjeev Sharma

Full Stack Engineer · E-mopro

Related reading