mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 00:15:28 +08:00
015ec6eb3c85e18fed59ca55e126b0f1d50305d3
DS2API
Convert DeepSeek Web into an OpenAI & Claude compatible API, with multi-account rotation, automatic token refresh, and a visual admin console.
✨ 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
Option 1: Vercel deployment (recommended)
- Click the button above and set
DS2API_ADMIN_KEY - After deployment, visit
/admin - Add DeepSeek accounts and custom API keys
- 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 serviceaccounts: 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 --buildwithout 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
Description
Languages
Go
74.6%
JavaScript
24.3%
Shell
0.7%
CSS
0.2%
Dockerfile
0.1%