DeepSeek
DeepSeek
API Status: Operational ⚡ Response Time 380ms

💻 API Documentation

OpenAI‑compatible endpoints for DeepSeek V4 Pro and Flash models.

Quick Start

1

Step 1: Get your API Key

Sign up and create a key at the developer platform.

2

Step 2: Install the SDK

The API is OpenAI-compatible — reuse existing SDKs.

3

Step 3: Make your first call

Point base_url to DeepSeek and start building.

Base Endpoint

https://api.deepseek.com/v1

Available Models

DeepSeek V4 Pro

deepseek-v4-pro

671B MoE · Best reasoning & vision

Context1M
Speed45 tok/s

DeepSeek V4 Flash

deepseek-v4-flash

37B · Fast & cost-effective

Context128K
Speed112 tok/s

Request Parameters

Parameter Type Required Default Description
model string Yes Model name to use
messages array Yes List of conversation messages
temperature number No 1.0 Sampling temperature (0-2)
max_tokens integer No 4096 Maximum output tokens
stream boolean No false Enable streaming output
top_p number No 1.0 Nucleus sampling (0-1)
frequency_penalty number No 0 Frequency penalty (-2 to 2)
presence_penalty number No 0 Presence penalty (-2 to 2)

Code Examples

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.deepseek.com/v1"
)

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Hello!"}],
    temperature=0.7,
    max_tokens=1024,
)
print(response.choices[0].message.content)

Streaming Output

Set stream: true to receive Server-Sent Events (SSE) token by token.

Python

stream = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Write a poem"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

JavaScript

const stream = await client.chat.completions.create({
  model: "deepseek-v4-pro",
  messages: [{ role: "user", content: "Write a poem" }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}

Response Format

A standard OpenAI-compatible JSON response.

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1751430000,
  "model": "deepseek-v4-pro",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "Hello! How can I help?" },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 }
}

Function Calling

Define tools and let the model decide when to call them.

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {"city": {"type": "string"}},
                "required": ["city"]
            }
        }
    }],
)
print(response.choices[0].message.tool_calls)

Error Codes

Code Meaning Solution
400 Invalid request parameters Check your request body and parameter types.
401 Invalid API Key Verify your Authorization header and key.
429 Rate limit exceeded Slow down requests or request a higher quota.
500 Internal server error Retry with exponential backoff.

Rate Limits

Limits are applied per API key across requests and tokens.

Tier RPM TPM
Free 60 100K
Pro 600 5M

Anthropic-Compatible Endpoint

Use the Anthropic Messages API format with DeepSeek models.

curl https://api.deepseek.com/anthropic/v1/messages \
  -H "x-api-key: $DEEPSEEK_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Pricing

🎁 Free quota: 10M tokens / month

Model Input Cache Hit Input Output
DeepSeek V4 Pro $0.55 / 1M $0.14 / 1M $2.19 / 1M
DeepSeek V4 Flash $0.07 / 1M $0.02 / 1M $0.28 / 1M
GPT-4o $5.00 / 1M $2.50 / 1M $15.00 / 1M

SDKs

Official SDKs

Python pip install openai
JavaScript npm install openai
Go go get github.com/sashabaranov/go-openai
Java implementation "com.theokanning.openai-gpt3-java:service"
Rust cargo add async-openai

API Status: Operational

380ms

Response Time

99.9%

Availability