Skip to main content

DeepSeek Anthropic API 兼容性代理 — 让 Claude Code 在 DeepSeek V4 模型上稳定运行

Project description

ds-cc-proxy

DeepSeek Anthropic API 兼容性代理 — 让 Claude Code 在 DeepSeek V4 模型上稳定运行。

Claude Code ←→ localhost:16889 (ds-cc-proxy) ←→ api.deepseek.com/anthropic

项目由来

命名说明

本项目的早期版本以 dsv4-cc-proxy(DeepSeek V4 → Claude Code Proxy)发布,对应 PyPI 包名 dsv4-cc-proxy。随着项目从单纯的 "V4 适配" 演变为通用 DeepSeek Anthropic 兼容代理,v1.9.0 社区版更名为 ds-cc-proxy(DeepSeek → Claude Code Proxy),去掉了版本号限定。

如果你正在运行 dsv4-cc-proxy:两者功能兼容,ds-cc-proxy 是其后继版本,增加了大量安全加固和鲁棒性修复(见下表)。升级时只需:

pip uninstall dsv4-cc-proxy
pip install git+https://github.com/snowspruce/ds-cc-proxy.git
# CLI 命令变为 ds-cc-proxy(原 dsv4-cc-proxy 不再可用)

与上游的关系

本项目 fork 自 HosheaLi/P14_dsv4ToCC v1.8.0,在原版双向代理修复基础上,针对 Claude Code 2.1.167+ 的 thinking mode 协议变更和连接池稳定性做了大幅优化。

修复的问题

功能性

问题 原版 修复后
adaptive thinking 被错误剥离 Claude Code 2.1.167 adaptive 模式触发 thinking 剥离,功能异常 识别 adaptive,透传 thinking

稳定性

问题 原版 修复后
连接池耗尽 固定 20 连接,长连接占满后全部 502 50 连接 + 120s 排队 + 503 Retry-After
上游 4xx/5xx 被误解析 当作 SSE 流解析,客户端收到乱码 状态码 ≥400 直接透传

鲁棒性

问题 原版 修复后
环境变量解析崩溃 int(os.getenv(...)) 遇非法值进程崩溃 try/except + 范围校验 + 安全降级
dump 目录不存在崩溃 open() 失败无处理 os.makedirs(exist_ok=True) + OSError 捕获
data: null 致 SSE 解析崩溃 data["index"] KeyError、.get() on None .get() + isinstance(dict) 守卫
SSE buffer 无界增长 无上限,长连接可能 OOM 1MB 上限
tools/content 非 list 假设 list 致 TypeError/KeyError isinstance 类型守卫

生命周期

问题 原版 修复后
关闭时暴力切断活跃流 aclose() 立即断开 5s 排空期 + shutdown 信号
aclose 异常掩盖原始错误 异常覆盖,丢失根因 try/except 独立记录

可运维

问题 原版 修复后
root logger 污染 uvicorn 日志 清除全局 handler,日志混乱 专用 app logger 隔离
content-encoding 错误剥离 剥离压缩头,压缩数据当明文返回 保留 content-encoding

快速开始

pip install git+https://github.com/snowspruce/ds-cc-proxy.git

# 启动代理
ds-cc-proxy

# 停止代理
ds-cc-proxy --stop

配置 Claude Code

~/.claude/settings.jsonenv 中添加:

"ANTHROPIC_BASE_URL": "http://localhost:16889"

环境变量

变量 默认值 说明
PROXY_UPSTREAM https://api.deepseek.com/anthropic DeepSeek API 地址
PROXY_HOST 127.0.0.1 监听地址
PROXY_PORT 16889 监听端口
PROXY_LOG_LEVEL warning 日志级别 (debug/info/warning/error)
PROXY_LOG_FILE (空) 日志文件路径
PROXY_POOL_MAX_CONNECTIONS 50 上游连接池最大连接数
PROXY_POOL_MAX_KEEPALIVE 20 最大保活连接数
PROXY_POOL_TIMEOUT 120.0 池满时等待空闲连接的超时(秒)
PROXY_UPSTREAM_TIMEOUT 600.0 单次上游请求总超时(秒)
PROXY_CONNECT_TIMEOUT 10.0 上游 TCP 连接超时(秒)
PROXY_DUMP_DIR (空) 流量捕获目录(含敏感数据,仅调试用)

健康检查

curl http://localhost:16889/health
# {"status":"ok","version":"1.9.0","upstream":"https://api.deepseek.com/anthropic"}

与本地代理的关系

ds-cc-proxy 监听 127.0.0.1:16889,仅处理 Claude Code 通过 ANTHROPIC_BASE_URL 显式发来的请求,与 Clash Verge、V2Ray 等系统级代理互不冲突:

  • Clash Verge / V2Ray:作为系统 HTTP/SOCKS5 代理(通常 127.0.0.1:7890),接管浏览器和大部分应用的出站流量
  • ds-cc-proxy:应用层代理,Claude Code 直连 localhost:16889,不经过系统代理

两者工作在不同网络层,可同时运行,无需任何特殊配置。

许可证

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ds_cc_proxy-0.1.22.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ds_cc_proxy-0.1.22-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file ds_cc_proxy-0.1.22.tar.gz.

File metadata

  • Download URL: ds_cc_proxy-0.1.22.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for ds_cc_proxy-0.1.22.tar.gz
Algorithm Hash digest
SHA256 60b7f077f30f1dcf3da019952b3470fc03a0630ac036be13d956a9c962530ec1
MD5 c3bda8acadfb2770265c87cadd8dd9bc
BLAKE2b-256 6355a6306ce5a7c1228d70203957b994ce86b8fe16637f08fcc2ec7c0e8d9d0a

See more details on using hashes here.

File details

Details for the file ds_cc_proxy-0.1.22-py3-none-any.whl.

File metadata

  • Download URL: ds_cc_proxy-0.1.22-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for ds_cc_proxy-0.1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 33013e5eca5cac998acdf37d454dc2ea9383ab21509272f6f0b96edf686d2e60
MD5 e639846a4bfab01560ca8b3475a85045
BLAKE2b-256 3866b04ac1282051639bb145a735c8631b7283217b034db4602a53c3b503bf64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page