Skip to content

Repository files navigation

WorkBuddy2API

WorkBuddy CN(CodeBuddy / copilot.tencent.com)的 OpenAI 兼容反向代理,支持 OAuth 登录、多账号轮转、工具调用与流式响应。

功能特性

  • 🔐 OAuth 登录 — 通过 /v2/plugin/auth/state 设备授权流程获取凭证,支持 token 自动刷新
  • 🔄 多账号轮转 — 按积分降序选号,自动冷却 / 禁用 / 恢复,防雪崩设计
  • 🛠 工具调用 — 完整支持 OpenAI tools/tool_choice,流式 tool_calls 按 index 合并
  • 📡 流式 + 非流式 — 上游 SSE 透传,非流式聚合 tool_calls + reasoning_content
  • 定时签到 — 每日 09:00 / 21:00 自动签到 + 积分查询
  • 📊 积分监控credit.sh 一键查询全部账号剩余/总量/百分比
  • 🔑 登录工具login.sh 交互式登录,落盘即生效
  • 🏗 Docker 部署 — 一键 docker compose up,healthcheck 常驻

快速开始

1. 克隆 & 配置

git clone https://github.com/Sliverkiss/workbuddy2api.git
cd workbuddy2api
cp config.example.json config.json
# 编辑 config.json,设置 api_key

2. 添加账号

./login.sh
# 打开浏览器登录 → 按 y → 自动落盘 auths/ → 重启容器

3. 启动服务

docker compose up -d --build

4. 验证

curl -s http://localhost:7863/v1/models -H "Authorization: Bearer your-api-key"
curl -s http://localhost:7863/v1/chat/completions \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"auto","messages":[{"role":"user","content":"hi"}]}'

配置说明

{
  "listen": ":7863",
  "api_key": "your-api-key",
  "auth_dir": "./auths",
  "state_file": "./data/state.json",
  "region": "cn",
  "cooldown": {
    "hard_credit": "12h",
    "soft_rate": "60s",
    "err_threshold": 5,
    "err_cooldown": "10m"
  },
  "schedule": {
    "checkin_hours": [9, 21],
    "keepalive_hours": [22]
  },
  "upstream": {
    "timeout_seconds": 120
  }
}

工具脚本

脚本 用途
./login.sh OAuth 登录,落盘 auth 文件
./credit.sh 积分日报(美化输出)
./credit.sh -json 积分原始 JSON

稳定性设计

  • 防雪崩:上游 4xx/5xx 轮转重试(不直接返回),404 短冷却 60s 不累计 errCount
  • 请求日志chat_stream uid=...: upstream %d %s body=... 便于排查
  • 连接池MaxIdleConnsPerHost=20 减少 TLS 握手
  • 凭证续期:token 临近过期自动 refresh,失败禁用账号

免责声明

本项目仅供学习和研究使用。使用者需遵守 WorkBuddy / CodeBuddy 的服务条款,自行承担使用风险。作者不对任何因使用本项目产生的直接或间接损失负责。

License

MIT

About

No description, website, or topics provided.

Resources

Stars

104 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages