Triển khai CLIProxyAPI + CPA-Manager bằng Docker Compose
Bài viết này hướng dẫn dựng stack gồm CLIProxyAPI và CPA-Manager (seakee) theo mô hình:
- CLIProxyAPI: proxy server chính, expose API tương thích OpenAI/Claude/Gemini, chạy ở port
8317. - CPA-Manager: WebUI quản lý + Usage Service, kết nối vào CLIProxyAPI, chạy ở port
18317.
Bước 1 - Tạo cấu trúc thư mục
mkdir cpa-stack && cd cpa-stack
mkdir -p config auths logs
Bước 2 - Tạo config.yaml cho CLIProxyAPI
Nếu có file mẫu:
cp config.example.yaml config/config.yaml
Hoặc tạo cấu hình tối thiểu:
# config/config.yaml
host: ""
port: 8317
remote-management:
allow-remote: true
secret-key: "your-secret-management-key"
api-keys:
- "your-api-key-1"
usage-statistics-enabled: true
debug: false
allow-remote: true và secret-key là bắt buộc để CPA-Manager kết nối tới CLIProxyAPI.
Bước 3 - Tạo docker-compose.yml tích hợp cả hai service
# docker-compose.yml
services:
cli-proxy-api:
image: eceasy/cli-proxy-api:latest
pull_policy: always
container_name: cli-proxy-api
restart: unless-stopped
volumes:
- ./config/config.yaml:/CLIProxyAPI/config.yaml
- ./auths:/root/.cli-proxy-api
- ./logs:/CLIProxyAPI/logs
ports:
- "8317:8317"
- "8085:8085"
networks:
- cpa-net
cpa-manager:
image: seakee/cpa-manager:latest
pull_policy: always
container_name: cpa-manager
restart: unless-stopped
environment:
CPA_UPSTREAM_URL: "http://cli-proxy-api:8317"
CPA_MANAGEMENT_KEY: "your-secret-management-key"
ports:
- "18317:18317"
volumes:
- cpa-manager-data:/data
depends_on:
- cli-proxy-api
networks:
- cpa-net
networks:
cpa-net:
driver: bridge
volumes:
cpa-manager-data:
Lưu ý: CPA_MANAGEMENT_KEY phải khớp với secret-key trong config/config.yaml.
Bước 4 - Khởi động stack
docker compose up -d
Kiểm tra log:
docker compose logs -f
Bước 5 - Truy cập service
| Service | URL |
|---|---|
| CLIProxyAPI endpoint | http://localhost:8317/v1/chat/completions |
| CPA-Manager WebUI | http://localhost:18317/management.html |
Khi mở WebUI lần đầu, nhập:
- CPA URL:
http://cli-proxy-api:8317(nếu mở từ browser cùng máy host thì dùnghttp://localhost:8317). - Management Key:
your-secret-management-key.
Lưu ý quan trọng
Nếu CLIProxyAPI chạy trực tiếp trên host (không dùng Docker), đổi URL trong service cpa-manager:
CPA_UPSTREAM_URL: "http://host.docker.internal:8317"
và thêm vào cpa-manager:
extra_hosts:
- "host.docker.internal:host-gateway"