基于 CJackHwang/ds2api 的修改版。
原始项目: https://github.com/CJackHwang/ds2api
本版本在原版基础上做了三项核心改动,目的是降低 DeepSeek 风控触发概率:
| 原版 | 本版 | |
|---|---|---|
| 账号切换策略 | Round-Robin(每次请求换一个账号) | Sticky Session(一个账号用到出错才换) |
| 效果 | 39 个账号同时频繁登录,容易触发风控 | 同一 API Key 绑定同一账号,大幅减少登录次数 |
- 每个 API Key(
callerID)首次请求时随机绑定一个可用账号 - 后续请求始终使用该账号,直到遇到错误
- 出错后自动切换到下一个账号,原账号冷却后可重新使用
- 新增
internal/auth/rate_limiter.go - 两次登录请求之间强制间隔 2 秒
- 防止重启后大量账号同时登录触发 DeepSeek 风控
| 原版 | 本版 | |
|---|---|---|
| 重启行为 | 清除所有 Token,重新登录 | 保留 Token,直接复用 |
| 效果 | 39 个账号同时登录 → 风控 | 零登录开销 |
- 修改
internal/config/store.go,禁用ClearAccountTokens() - 服务重启后直接使用已缓存的 Token,无需重新登录
- 配合 Rate Limiter + Stagger(随机偏移),即使 Token 过期也能平滑刷新
internal/auth/request.go — Sticky Session 绑定 + 错误切换逻辑
internal/auth/rate_limiter.go — 2 秒登录限速器(新增文件)
internal/config/store.go — 启用 Token 持久化
如果上游有更新,可以用 patch 重新应用改动:
cd /path/to/new-ds2api-src
git apply all-changes.patch本 Fork 保留了原版的所有功能:
- OpenAI / Claude / Gemini / Ollama 兼容 API
- DeepSeek Web 对话转 API(支持 thinking / nothinking / search 模式)
- 多账号管理 + WebUI 管理台
- 并发队列控制 + PoW 计算
- Tool Calling 适配
- Docker / Vercel / 源码部署
| 模型 ID | thinking | search |
|---|---|---|
deepseek-v4-flash |
默认开启 | ❌ |
deepseek-v4-flash-nothinking |
永久关闭 | ❌ |
deepseek-v4-pro |
默认开启 | ❌ |
deepseek-v4-pro-nothinking |
永久关闭 | ❌ |
deepseek-v4-flash-search |
默认开启 | ✅ |
deepseek-v4-pro-search |
默认开启 | ✅ |
deepseek-v4-vision |
默认开启 | ❌ |
支持常见 alias(gpt-4.1、claude-*、gemini-* 等),完整列表见 原版 API.md。
镜像地址: ghcr.io/iewknewon/ds2api:latest
docker pull ghcr.io/iewknewon/ds2api:latest创建 config.json:
{
"port": 5001,
"keys": ["sk-your-api-key"],
"accounts": [
{ "email": "your@email.com", "password": "your-password" }
],
"enable_browser": true
}docker run -d \
-p 5001:5001 \
-v ./config.json:/data/config.json \
--name ds2api \
--restart always \
-e TZ=Asia/Shanghai \
-e LOG_LEVEL=INFO \
-e DS2API_ADMIN_KEY=your-admin-key \
ghcr.io/iewknewon/ds2api:latest# 查看日志
docker logs -f ds2api
# 测试 API
curl http://localhost:5001/v1/models# 克隆仓库
git clone https://github.com/iewknewon/ds2api.git
cd ds2api
# 编辑 config.json 填入你的账号信息
# 启动
docker compose up -d
# 查看日志
docker compose logs -f
# 停止
docker compose downgit clone https://github.com/iewknewon/ds2api.git
cd ds2api
go build -o ds2api ./cmd/ds2api
./ds2api详细部署文档见 原版 docs/。
{
"port": 5001,
"keys": ["sk-your-api-key"],
"accounts": [
{ "email": "user@example.com", "password": "your-password" }
],
"enable_browser": true
}- 原项目作者 CJackHwang 及 Linux.do 社区的贡献者们
- 本 Fork 仅做风控优化,核心功能和架构均来自原版
本仓库仅供学习、研究和个人实验使用。不对因使用本项目产生的任何损失负责。请勿用于违反服务条款的场景。