2026-01-21 15:14:49 +00:00
2026-02-04 19:40:34 +08:00
2026-01-21 15:14:49 +00:00
2026-01-21 15:14:49 +00:00

DS2API

License Stars Forks Version Docker

Language: 中文 | English

Convert DeepSeek Web into an OpenAI & Claude compatible API, with multi-account rotation, automatic token refresh, and a visual admin console.

p1 p2 p3 p4

Features

  • 🔄 Dual-protocol support - OpenAI and Claude (Anthropic) compatible APIs
  • 🚀 Multi-account rotation - Round-robin load balancing for high concurrency
  • 🔐 Automatic token refresh - Re-auth on expiry without manual maintenance
  • 🌐 WebUI management - Add accounts, test APIs, and sync Vercel settings visually
  • 🌍 Language toggle - Built-in Chinese and English UI switcher
  • 🔍 Web search - DeepSeek native search enhancement mode
  • 🧠 Deep reasoning - Reasoning mode with trace output
  • 🛠️ Tool calling - OpenAI Function Calling compatible
  • ☁️ One-click Vercel deploy - No server required

📋 Model Support

OpenAI compatible endpoint (/v1/chat/completions)

Model Reasoning Search Notes
deepseek-chat Standard chat
deepseek-reasoner Reasoning (shows trace)
deepseek-chat-search Web search mode
deepseek-reasoner-search Reasoning + search

Claude compatible endpoint (/anthropic/v1/messages)

Model Notes
claude-sonnet-4-20250514 Maps to deepseek-chat (standard)
claude-sonnet-4-20250514-fast Maps to deepseek-chat (fast)
claude-sonnet-4-20250514-slow Maps to deepseek-reasoner (reasoning)

Tip

: The Claude endpoint actually calls DeepSeek and returns Anthropic-format responses.

🚀 Quick Start

Deploy with Vercel

  1. Click the button above and set DS2API_ADMIN_KEY
  2. After deployment, visit /admin
  3. Add DeepSeek accounts and custom API keys
  4. Click "Sync to Vercel" to persist configuration

First sync validates accounts and stores tokens automatically.

Option 2: Local development

# 1. Clone the repo
git clone https://github.com/CJackHwang/ds2api.git
cd ds2api

# 2. Install dependencies
pip install -r requirements.txt

# 3. Configure accounts
cp config.example.json config.json
# Edit config.json to add DeepSeek account info

# 4. Start the service
python dev.py

Visit http://localhost:5001 after startup.

⚙️ Configuration

Environment variables

Variable Description Required
DS2API_ADMIN_KEY Admin console password Required on Vercel
DS2API_CONFIG_JSON Config JSON or Base64 Optional
VERCEL_TOKEN Vercel API token (for sync) Optional
VERCEL_PROJECT_ID Vercel project ID Optional
PORT Service port (default 5001) Optional

Config file format (config.json)

{
  "keys": ["your-api-key-1", "your-api-key-2"],
  "accounts": [
    {
      "email": "user@example.com",
      "password": "your-password",
      "token": ""
    },
    {
      "mobile": "12345678901",
      "password": "your-password",
      "token": ""
    }
  ]
}

Notes:

  • keys: Custom API keys for calling this service
  • accounts: DeepSeek Web accounts (email or mobile)
  • token: Leave blank; DS2API will fetch and refresh automatically

📡 API Usage

See API.md for full API documentation.

Quick examples

List models:

curl http://localhost:5001/v1/models

OpenAI-compatible call:

curl http://localhost:5001/v1/chat/completions \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Hello"}],
    "stream": true
  }'

Claude-compatible call:

curl http://localhost:5001/anthropic/v1/messages \
  -H "x-api-key: your-api-key" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Python SDK usage

from openai import OpenAI

client = OpenAI(
    api_key="your-api-key",
    base_url="http://localhost:5001/v1"
)

response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=[{"role": "user", "content": "Explain quantum entanglement"}],
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

🔧 Deployment Notes

Nginx reverse proxy

location / {
    proxy_pass http://localhost:5001;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffering off;
    proxy_cache off;
    chunked_transfer_encoding on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 120;
}

Option 3: Docker deployment

# 1. Clone the repo and enter the directory
git clone https://github.com/CJackHwang/ds2api.git
cd ds2api

# 2. Configure environment variables
cp .env.example .env
# Edit .env and fill in DS2API_ADMIN_KEY and DS2API_CONFIG_JSON

# 3. Start the service
docker-compose up -d

# 4. Check logs
docker-compose logs -f

Docker advantage: Zero-intrusion design; update the main code with docker-compose up -d --build without changing Docker configuration. See DEPLOY.md.

⚠️ Disclaimer

This project is based on reverse engineering and stability is not guaranteed.

  • For learning and research only. No commercial use or public service is allowed.
  • For production, use the official DeepSeek API
  • You assume all risks from using this project

📜 Acknowledgements

This project is based on the following open-source projects:

📊 Star History

Star History Chart

Languages
Go 74.6%
JavaScript 24.3%
Shell 0.7%
CSS 0.2%
Dockerfile 0.1%