CLIProxyAPI 是面向 CLI 模型的轻量 API 代理,提供 OpenAI、Gemini、Claude、Codex、Grok 兼容接口,支持 OAuth、API Key、多账号轮询与流式响应
本文使用 Docker + Portainer + Nginx Proxy Manager 部署,并沿用 external
proxy 网络🟢部署前准备
mkdir -p /opt/cliproxyapi/{auths,logs,plugins}
chmod 700 /opt/cliproxyapi /opt/cliproxyapi/auths
openssl rand -hex 32
openssl rand -hex 32分别保存两次输出,用作 Management Key 和下游 API Key
创建
/opt/cliproxyapi/config.yaml:host: ""
port: 8317
remote-management:
allow-remote: true
secret-key: "REPLACE_WITH_MANAGEMENT_KEY"
disable-control-panel: false
auth-dir: "~/.cli-proxy-api"
api-keys:
- "REPLACE_WITH_API_KEY"
替换两个占位值后执行:
chmod 600 /opt/cliproxyapi/config.yaml
Management Key 首次启动后会被转换为 hash 并写回
config.yaml,登录面板仍使用原始明文。该文件不能挂载为只读🟢CLIProxyAPI Compose
services:
cli-proxy-api:
image: eceasy/cli-proxy-api:latest
container_name: cliproxyapi
hostname: cliproxyapi
restart: always
networks:
- proxy
ports:
- "127.0.0.1:8085:8085"
- "127.0.0.1:1455:1455"
- "127.0.0.1:54545:54545"
- "127.0.0.1:51121:51121"
- "127.0.0.1:11451:11451"
expose:
- "8317"
volumes:
- /opt/cliproxyapi/config.yaml:/CLIProxyAPI/config.yaml
- /opt/cliproxyapi/auths:/root/.cli-proxy-api
- /opt/cliproxyapi/logs:/CLIProxyAPI/logs
- /opt/cliproxyapi/plugins:/CLIProxyAPI/plugins
environment:
TZ: Asia/Shanghai
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
networks:
proxy:
external: true
name: proxy
在 Portainer 中进入
Stacks -> Add stack,Stack name 填 cliproxyapi,粘贴 Compose 后选择 Deploy the stack8317 不映射到宿主机,只通过 proxy 网络提供给 NPM。OAuth callback 端口仅绑定 127.0.0.1,需要远程授权时使用 SSH tunnel,不要直接暴露到公网🟢NPM 反代设置
Domain Names:你的 CPA 域名
Scheme:
httpForward Hostname / IP:
cliproxyapiForward Port:
8317Cache Assets:关闭
Websockets Support:开启
SSL 页面开启 Force SSL 和 HTTP/2 Support
Advanced:
proxy_buffering off;
proxy_request_buffering off;
proxy_cache off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
保存后访问:
https://YOUR_CPA_DOMAIN/management.html
使用 Management Key 登录,在面板中添加上游账号、维护下游 API Key、调整路由和模型映射
🟢最小验证
docker ps --filter name=cli-proxy-api
docker logs --tail 100 cli-proxy-api
curl -fsS https://YOUR_CPA_DOMAIN/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"
能返回模型列表即表示 API、共享网络和反向代理已连通
项目地址
https://github.com/router-for-me/CLIProxyAPI
使用手册
https://help.router-for.me/cn/
🤣 涉及容器互通时参考 Nginx Proxy Manager 反向代理避雷指南
😂 Docker
#Docker #CLIProxyAPI #CPA #AI #API #中转站