# CLIProxyAPI Plus
面向 AI 编程工具的轻量级智能网关:支持 Claude Code、Codex、Gemini CLI、Antigravity、Kimi、OpenAI 兼容客户端等。
简体中文 | English
CLIProxyAPI Plus 是基于 [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI) 的社区增强版。它保留原项目的多供应商代理能力、OpenAI 兼容接口、管理 API 与轻量部署方式,同时针对 Codex 多账号池增加了更适合日常运营的配额能力。 核心增强: - Codex 配额卡片显示套餐、余额、5 小时额度、周额度和恢复窗口。 - 认证文件卡片在健康状态下方直接显示剩余配额。 - 认证文件列表支持按 Codex 周额度剩余排序,高额度账号排前面。 - Codex 返回 `usage_limit_reached` 后可自动持久停用该认证文件。 - Codex 周额度低于指定阈值时可提前停用,例如剩余 `3%` 或 `5%` 即停止使用。 - OAuth 登录等待时间更长,远程 VPS 浏览器登录更友好。 推荐部署方式仍然是最省资源的方式:下载一个二进制文件,用 `systemd` 跑起来,然后通过单文件管理面板操作。Docker 和源码构建仍然保留,方便不同用户选择。 ## 项目结构 Plus 版按一个仓库发布,用户只需要关注一个项目:根目录是后端,`management-center/` 是管理面板源码。Release 会同时提供多平台二进制和 `management.html`。 | 路径 | 作用 | | --- | --- | | `/` | Go 后端、网关、Management API、二进制 release、可选 Docker 镜像 | | `management-center/` | React 管理面板,release 为单文件 `management.html` | 默认面板更新源会指向本仓库的最新 Release。如果你发布自己的面板,也可以改成自己的仓库: ```yaml remote-management: disable-control-panel: false disable-auto-update-panel: false panel-github-repository: "https://github.com/ztx888/CLIProxyAPI-Plus" ``` ## 为什么需要 Plus 版 Codex 多账号池最麻烦的不是能不能跑,而是能不能清楚知道哪个账号还剩多少额度,以及低额度账号是否会继续被请求命中。CLIProxyAPI Plus 解决的是运营体验: - 高额度账号一眼可见,并且能排序靠前。 - 低额度账号可以在达到阈值后自动停用。 - 真正触发 `usage_limit_reached` 的账号可以自动持久停用。 - 已停用账号会尽量显示预计恢复时间。 - 保持二进制部署方式,不强依赖 Docker,不引入额外数据库。 ## 功能概览 ### 网关能力 - 提供 OpenAI 兼容接口,适配常见 Chat Completions / Responses 客户端。 - 支持 Claude、Codex、Gemini、Gemini CLI、Antigravity、Kimi、Vertex、Qwen、OpenAI 兼容上游等。 - 多认证文件池,支持优先级、前缀路由、重试、回退和自动刷新。 - Management API 支持配置、认证文件、OAuth 登录、额度检测、日志、模型信息等。 - 可选请求日志、Redis 兼容使用队列和运行状态统计。 ### Codex 配额增强 - 显示 Free、Plus、Pro、Team、Pro Lite 等套餐信息。 - 显示 Codex 余额和本地/云端可用次数估算。 - 显示 5 小时和周额度窗口,包括剩余百分比、已用百分比、恢复时间和窗口长度。 - 认证文件卡片直接展示剩余额度,不必进入详情页。 - 新增“周限额剩余”排序,高额度账号排在前面。 - 新增 `usage_limit_reached` 后自动停用。 - 新增按周额度剩余百分比提前停用。 ### 轻量部署 - 单二进制运行,适合小 VPS。 - 基础网关不依赖数据库。 - 不需要 Docker。 - 管理面板是单文件 HTML,通过 `/management.html` 访问。 - 适合 `systemd` 托管,运行目录清晰,可控可迁移。 ## 快速开始:二进制 + systemd 这是推荐的小 VPS 部署方式。 ### 1. 创建用户和目录 ```bash sudo useradd --system --create-home --home-dir /var/lib/cliproxyapi --shell /usr/sbin/nologin cliproxyapi sudo install -d -o cliproxyapi -g cliproxyapi /opt/cliproxyapi /etc/cliproxyapi /var/lib/cliproxyapi /var/log/cliproxyapi ``` ### 2. 下载 release 在 GitHub Releases 下载对应系统架构的压缩包。普通 Linux VPS 通常是 `linux_amd64`。 ```bash export CPA_REPO="ztx888/CLIProxyAPI-Plus" export CPA_VERSION="v0.1.0" curl -fL "https://github.com/${CPA_REPO}/releases/download/${CPA_VERSION}/CLIProxyAPI-Plus_${CPA_VERSION}_linux_amd64.tar.gz" -o /tmp/cliproxyapi.tar.gz sudo tar -xzf /tmp/cliproxyapi.tar.gz -C /opt/cliproxyapi sudo chmod +x /opt/cliproxyapi/cli-proxy-api ``` 如果实际 release 文件名不同,以 Releases 页面为准,只要最终把 `cli-proxy-api` 放到: ```text /opt/cliproxyapi/cli-proxy-api ``` ### 3. 创建配置 ```bash sudo cp /opt/cliproxyapi/config.example.yaml /etc/cliproxyapi/config.yaml sudo chown -R cliproxyapi:cliproxyapi /etc/cliproxyapi /var/lib/cliproxyapi /var/log/cliproxyapi sudo chmod 750 /etc/cliproxyapi /var/lib/cliproxyapi sudo chmod 640 /etc/cliproxyapi/config.yaml ``` 最小远程管理配置示例: ```yaml port: 8317 allow-remote-management: true remote-management: disable-control-panel: false disable-auto-update-panel: false panel-github-repository: "https://github.com/ztx888/CLIProxyAPI-Plus" secret-key: "change-this-management-key" quota-exceeded: switch-project: true switch-preview-model: true antigravity-credits: true auto-disable-codex-usage-limit: true auto-disable-codex-weekly-remaining-threshold: 5 ``` ### 4. 安装 systemd 服务 ```bash sudo tee /etc/systemd/system/cliproxyapi.service >/dev/null <<'EOF' [Unit] Description=CLIProxyAPI Plus After=network-online.target Wants=network-online.target [Service] Type=simple User=cliproxyapi Group=cliproxyapi WorkingDirectory=/opt/cliproxyapi Environment=HOME=/var/lib/cliproxyapi Environment=WRITABLE_PATH=/var/lib/cliproxyapi ExecStart=/opt/cliproxyapi/cli-proxy-api -config /etc/cliproxyapi/config.yaml Restart=always RestartSec=5 NoNewPrivileges=true PrivateTmp=true ProtectHome=true ProtectSystem=full ReadWritePaths=/var/lib/cliproxyapi /var/log/cliproxyapi /etc/cliproxyapi LimitNOFILE=65535 [Install] WantedBy=multi-user.target EOF sudo systemctl daemon-reload sudo systemctl enable --now cliproxyapi systemctl status cliproxyapi --no-pager ``` 打开管理面板: ```text http://