### Arch Linux Configuration Setup Source: https://help.router-for.me/cn/introduction/quick-start Creates the configuration directory and copies an example configuration file for CLIProxyAPI. ```bash mkdir -p ~/.cli-proxy-api cp /usr/share/doc/cli-proxy-api-bin/config.example.yaml ~/.cli-proxy-api/config.yaml ``` -------------------------------- ### macOS Installation with Homebrew Source: https://help.router-for.me/cn/introduction/quick-start Installs CLIProxyAPI using Homebrew and starts it as a service. ```bash brew install cliproxyapi brew services start cliproxyapi ``` -------------------------------- ### Linux One-Click Install Script Source: https://help.router-for.me/cn/introduction/quick-start Installs CLIProxyAPI on Linux using a provided script from GitHub. ```bash curl -fsSL https://raw.githubusercontent.com/router-for-me/cliproxyapi-installer/refs/heads/master/cliproxyapi-installer | bash ``` -------------------------------- ### Arch Linux (AUR) Installation Source: https://help.router-for.me/cn/introduction/quick-start Installs CLIProxyAPI on Arch Linux using AUR helpers like yay or paru. ```bash # 使用 yay yay -S cli-proxy-api-bin # 使用 paru paru -S cli-proxy-api-bin ``` -------------------------------- ### Example config.yaml for CLIProxyAPI setup Source: https://help.router-for.me/agent-client/amp-cli This snippet provides a comprehensive example of a config.yaml file for setting up CLIProxyAPI, including port, auth directory, API keys, and Amp integration settings. ```yaml port: 8317 auth-dir: "~/.cli-proxy-api" # API keys for clients (e.g., Amp CLI) to use api-keys: - "your-client-secret-key" # You can change this secret # Amp integration ampcode: upstream-url: "https://ampcode.com" # Your personal API key from ampcode.com upstream-api-key: "paste-your-ampcode-api-key-here" restrict-management-to-localhost: false # Other standard settings... debug: false logging-to-file: true ``` -------------------------------- ### Minimal Configuration Example Source: https://help.router-for.me/hands-on/tutorial-5 An example of a minimal configuration file for CLIProxyAPI. ```yaml port: 8317 # Please fill in the folder location according to your actual situation auth-dir: "~/.cli-proxy-api" request-retry: 3 quota-exceeded: switch-project: true switch-preview-model: true api-keys: # Please set the Key yourself, used for client access to the proxy - "ABC-123456" ``` -------------------------------- ### Example Amp Usage Source: https://help.router-for.me/cn/agent-client/amp-cli Example command to use Amp after configuration. ```bash amp "用 Python 写一个 hello world 程序" ``` -------------------------------- ### Minimal Configuration Example Source: https://help.router-for.me/cn/hands-on/tutorial-5 Example of a minimal configuration for CLIProxyAPI. ```yaml port: 8317 # 文件夹位置请根据你的实际情况填写 auth-dir: "~/.cli-proxy-api" request-retry: 3 quota-exceeded: switch-project: true switch-preview-model: true api-keys: # Key 请自行设置,用于客户端访问代理 - "ABC-123456" ``` -------------------------------- ### Build Program (Windows) Source: https://help.router-for.me/cn/introduction/quick-start Builds the CLIProxyAPI executable for Windows using Go. ```bash go build -o cli-proxy-api.exe ./cmd/server ``` -------------------------------- ### Clone Repository Source: https://help.router-for.me/cn/introduction/quick-start Clones the CLIProxyAPI GitHub repository and navigates into the directory. ```bash git clone https://github.com/router-for-me/CLIProxyAPI.git cd CLIProxyAPI ``` -------------------------------- ### Install Docker Source: https://help.router-for.me/cn/hands-on/tutorial-5 Command to install Docker using the official one-click script. ```bash bash <(curl -fsSL https://get.docker.com) ``` -------------------------------- ### Start the Proxy Source: https://help.router-for.me/cn/agent-client/amp-cli Command to start the CLIProxyAPI with a configuration file. ```bash ./cli-proxy-api --config config.yaml ``` -------------------------------- ### Arch Linux (AUR) Installation Source: https://help.router-for.me/introduction/quick-start Install CLIProxyAPI on Arch Linux using an AUR helper like yay or paru. ```bash # Using yay yay -S cli-proxy-api-bin # Using paru paru -S cli-proxy-api-bin ``` -------------------------------- ### Start the service (recommended) Source: https://help.router-for.me/docker/docker-compose Starts the service in detached mode using the pre-built image from Docker Hub. ```bash docker compose up -d ``` -------------------------------- ### Configuration for Remote Management Source: https://help.router-for.me/cn/hands-on/tutorial-6 This YAML configuration snippet shows how to enable remote management and set a secret key for the WebUI. ```yaml port: 8317 auth-dir: "~/.cli-proxy-api" request-retry: 3 quota-exceeded: switch-project: true switch-preview-model: true api-keys: - "ABC-123456" # 本次添加的远程管理部分 remote-management: allow-remote: true # 用于远程管理的KEY,和上边的api-keys要区分开 secret-key: "MGT-123456" disable-control-panel: false ``` -------------------------------- ### Build Program (Linux/macOS) Source: https://help.router-for.me/cn/introduction/quick-start Builds the CLIProxyAPI executable for Linux and macOS using Go. ```bash go build -o cli-proxy-api ./cmd/server ``` -------------------------------- ### Arch Linux Systemd Service Management Source: https://help.router-for.me/cn/introduction/quick-start Commands to start and enable the CLIProxyAPI service on Arch Linux using systemd. ```bash # 启动服务 systemctl --user start cli-proxy-api # 设置开机自启 systemctl --user enable cli-proxy-api ``` -------------------------------- ### OpenAI Compatibility Configuration Example Source: https://help.router-for.me/cn/configuration/provider/openai-compatibility Example configuration for an OpenAI-compatible provider, demonstrating per-key proxy configuration. ```yaml openai-compatibility: - name: "openrouter" disabled: false base-url: "https://openrouter.ai/api/v1" api-key-entries: - api-key: "sk-or-v1-...b780" proxy-url: "socks5://proxy.example.com:1080" - api-key: "sk-or-v1-...b781" models: - name: "moonshotai/kimi-k2:free" alias: "kimi-k2" ``` -------------------------------- ### Start the Docker service Source: https://help.router-for.me/hands-on/tutorial-11 This command builds and starts the Docker Compose service in detached mode. ```bash docker compose up -d --build ``` -------------------------------- ### Install Git Source: https://help.router-for.me/cn/hands-on/tutorial-5 Command to update package list and install Git on Debian-based systems. ```bash apt update && apt install git -y ``` -------------------------------- ### Example Gemini CLI Login Command Source: https://help.router-for.me/cn/hands-on/tutorial-2 An example of the Gemini CLI login command with a specific project ID. ```bash cli-proxy-api --login --project_id mimetic-planet-473413-v7 ``` -------------------------------- ### Minimal config.yaml example Source: https://help.router-for.me/hands-on/tutorial-2 A minimal configuration file for CLIProxyAPI. ```yaml port: 8317 # Please fill in the folder location according to your actual situation auth-dir: "Z:\\CLIProxyAPI\\auths" request-retry: 3 quota-exceeded: switch-project: true switch-preview-model: true api-keys: # Please set the Key yourself, used for client access to the proxy - "ABC-123456" ``` -------------------------------- ### OpenCode Configuration Source: https://help.router-for.me/agent-client/opencode Example configuration file for the OpenCode CLIProxyAPI server. ```json { "$schema": "https://opencode.ai/config.json", "provider": { "openai": { "options": { "baseURL": "http://127.0.0.1:8317/v1", "apiKey": "sk-dummy" } } }, "model": "gpt-5.3-codex" } ``` -------------------------------- ### Example config.yaml for Amp integration Source: https://help.router-for.me/agent-client/amp-cli This snippet shows an example configuration for the ampcode section in config.yaml, including upstream URL, API key, and localhost restriction settings. ```yaml ampcode: # Amp upstream control plane (required for management routes) upstream-url: "https://ampcode.com" # API key for CLIProxyAPI to authenticate with ampcode.com # Get this from https://ampcode.com/settings upstream-api-key: "your-ampcode-api-key-goes-here" # Optional: restrict management routes to localhost (default: false) restrict-management-to-localhost: false # Optional: map missing Amp models to local ones # model-mappings: # - from: "claude-opus-4.5" # to: "claude-sonnet-4" ``` -------------------------------- ### AI Studio config.ts example for authentication Source: https://help.router-for.me/cn/configuration/provider/ai-studio Example of how to set the JWT_TOKEN in AI Studio's config.ts for authenticated WebSocket connections. ```typescript const JWT_TOKEN = "your-authentication-token"; ``` -------------------------------- ### Gemini API Key Configuration Example Source: https://help.router-for.me/configuration/provider/gemini-compatibility Example of configuring upstream Gemini compatible providers using `gemini-api-key`. ```yaml gemini-api-key: - api-key: "AIzaSy...01" base-url: "https://generativelanguage.googleapis.com" headers: X-Custom-Header: "custom-value" proxy-url: "socks5://proxy.example.com:1080" - api-key: "AIzaSy...02" # use the official Gemini API key, no need to set the base url ``` -------------------------------- ### Client Usage Endpoint Source: https://help.router-for.me/cn/hands-on/tutorial-5 Example of how to configure the client endpoint. ```string http://YOUR_SERVER_IP:8317 ``` -------------------------------- ### AI Studio config.ts example for remote connection Source: https://help.router-for.me/cn/configuration/provider/ai-studio Example of how to update the WEBSOCKET_PROXY_URL in AI Studio's config.ts to connect to a remote CLIProxyAPI service. ```typescript const WEBSOCKET_PROXY_URL = "ws://your-remote-cli-proxy-api-url:8317"; // Or wss:// if SSL is enabled ``` -------------------------------- ### Get Full Configuration Source: https://help.router-for.me/cn/management/api Retrieves the complete configuration of the service. ```bash curl -H 'Authorization: Bearer ' http://localhost:8317/v0/management/config ``` -------------------------------- ### Get Auth Status Request Source: https://help.router-for.me/cn/management/api Example curl request to poll the OAuth flow status. ```bash curl -H 'Authorization: Bearer ' \ 'http://localhost:8317/v0/management/get-auth-status?state=' ``` -------------------------------- ### Prepare the configuration file Source: https://help.router-for.me/docker/docker-compose Copies the example configuration file to a new file named config.yaml. ```bash cp config.example.yaml config.yaml ``` -------------------------------- ### Get Auth Status Response - Error Source: https://help.router-for.me/cn/management/api Example JSON response indicating an error during the OAuth flow. ```json { "status": "error", "error": "Authentication failed" } ``` -------------------------------- ### Docker Run Command Source: https://help.router-for.me/cn/introduction/quick-start Runs CLIProxyAPI as a Docker container, mapping ports and volumes for configuration and authentication data. ```bash docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.yaml -v /path/to/your/auth-dir:/root/.cli-proxy-api eceasy/cli-proxy-api:latest ``` -------------------------------- ### Get Auth Status Response - Waiting Source: https://help.router-for.me/cn/management/api Example JSON response indicating the OAuth flow is still in progress. ```json { "status": "wait" } ``` -------------------------------- ### Minimal config.yaml Example Source: https://help.router-for.me/cn/hands-on/tutorial-2 A minimal configuration file for CLIProxyAPI, specifying port, authentication directory, request retries, and quota exceeded behavior. ```yaml port: 8317 # 文件夹位置请根据你的实际情况填写 auth-dir: "Z:\\CLIProxyAPI\\auths" request-retry: 3 quota-exceeded: switch-project: true switch-preview-model: true api-keys: # Key请自行设置,用于客户端访问代理 - "ABC-123456" ``` -------------------------------- ### Payload Schema Example Source: https://help.router-for.me/management/redis-usage-queue An example of the JSON payload structure for each queue item. ```json { "timestamp": "2026-04-25T00:00:00Z", "latency_ms": 1500, "source": "user@example.com", "auth_index": "0", "tokens": { "input_tokens": 10, "output_tokens": 20, "reasoning_tokens": 0, "cached_tokens": 0, "total_tokens": 30 }, "failed": false, "provider": "openai", "model": "gpt-5.4", "alias": "client-gpt", "endpoint": "POST /v1/chat/completions", "auth_type": "apikey", "api_key": "test-key", "request_id": "ctx-request-id", "response_headers": { "X-Upstream-Request-Id": ["upstream-req-1"], "Retry-After": ["30"] } } ``` -------------------------------- ### Configure environment variables Source: https://help.router-for.me/hands-on/tutorial-11 This command copies the example environment file and opens it for editing. You need to fill in CAMOUFOX_INSTANCE_URL and USER_COOKIE_1. ```bash cp .env.example .env nano .env ``` -------------------------------- ### WebUI Configuration Example Source: https://help.router-for.me/hands-on/tutorial-6 This YAML configuration snippet shows how to enable the remote management part for WebUI by adding the 'remote-management' section to the existing configuration. ```yaml port: 8317 auth-dir: "~/.cli-proxy-api" request-retry: 3 quota-exceeded: switch-project: true switch-preview-model: true api-keys: - "ABC-123456" # The remote management part added this time remote-management: allow-remote: true # The KEY for remote management, which should be distinguished from the api-keys above secret-key: "MGT-123456" disable-control-panel: false ``` -------------------------------- ### Get the proxy URL string Source: https://help.router-for.me/management/api Endpoint to get the proxy URL string. ```bash curl -H 'Authorization: Bearer ' http://localhost:8317/v0/management/proxy-url ``` -------------------------------- ### Clone Project and Initialize Configuration Source: https://help.router-for.me/cn/hands-on/tutorial-5 Commands to clone the CLIProxyAPI repository and copy the example configuration file. ```bash git clone https://github.com/router-for-me/CLIProxyAPI.git cd CLIProxyAPI cp config.example.yaml config.yaml ``` -------------------------------- ### macOS Homebrew Configuration Override Source: https://help.router-for.me/cn/introduction/quick-start Stops the service, backs up the default config, creates a symlink to a user-defined config, and restarts the service. ```bash brew services stop cliproxyapi mv "$(brew --prefix)/etc/cliproxyapi.conf" "$(brew --prefix)/etc/cliproxyapi.conf.bak" ln -s ~/.cli-proxy-api/config.yaml "$(brew --prefix)/etc/cliproxyapi.conf" brew services start cliproxyapi ``` -------------------------------- ### Get the proxy URL string response Source: https://help.router-for.me/management/api Response for getting the proxy URL string. ```json { "proxy-url": "socks5://user:pass@127.0.0.1:1080/" } ``` -------------------------------- ### Nginx Configuration Example Source: https://help.router-for.me/cn/agent-client/amp-cli Example Nginx configuration to block external access to management routes when `ampcode.restrict-management-to-localhost` is false. ```nginx location /api/auth { deny all; } location /api/user { deny all; } location /api/threads { deny all; } location /api/internal { deny all; } ``` -------------------------------- ### CLIProxyAPI Configuration File Source: https://help.router-for.me/hands-on/tutorial-0 This is a sample configuration file for the CLIProxyAPI project, detailing various settings for port, remote management, authentication directories, debugging, logging, proxy settings, request retries, and quota management. ```yaml # Port number, CLIProxyAPI runs an HTTP server and needs a port number for access port: 8317 # Remote management configuration, used with EasyCLI or WebUI remote-management: # Switch to enable remote management. If you deploy it on a server, # you need to set it to true to use EasyCLI or WebUI to connect to CLIProxyAPI # for management. # If you only use the API for local management, you can keep it as false. allow-remote: false # If you want to use EasyCLI or WebUI to manage CLIProxyAPI through the API, # you must set a Key. # If it is not set, it is considered that the API management function is # disabled, and you cannot use EasyCLI or WebUI to connect. # If you do not need to use EasyCLI or WebUI for management, you can leave it # blank. secret-key: "" # Switch to integrate WebUI. # Set to false, you can open WebUI through # http://YOUR_SERVER_IP:8317/management.html disable-control-panel: false # Directory for storing authentication files, used to store authentication files # for Gemini CLI, Gemini Web, Claude Code, and Codex. # The default setting is the .cli-proxy-api folder in your current account # directory, which is compatible with Windows and Linux environments. # The program will automatically create this folder when it starts for the first # time. # The default in Windows is C:\Users\your_username\.cli-proxy-api # The default in Linux is /home/your_username/.cli-proxy-api # If you use a non-default location in a Windows environment, you need to # modify it in this format "Z:\\CLIProxyAPI\\auths" auth-dir: "~/.cli-proxy-api" # Whether to enable Debug information in the log, it is disabled by default. # You only need to turn it on when the author needs to cooperate in # troubleshooting. debug: false # Hidden configuration, which can record every request and response and save it # to the logs directory. # The size of each log may be as high as 10MB+. Please do not enable it if your # hard disk is not large enough. request-log: false # Whether to redirect the log to a log file. # It is enabled by default, and the log will be saved in the logs folder in the # program directory. # If it is turned off, the log will be displayed in the console. logging-to-file: true # Switch for usage statistics, enabled by default. # You need to use the API to view the usage, you can use EasyCLI or WebUI to # view it. usage-statistics-enabled: true # If you want to use a proxy, you need to make the following settings, which # support socks5/http/https protocols. # Fill in according to this format "socks5://user:pass@192.168.1.1:1080/" proxy-url: "" # The number of times the program automatically retries the request when it # encounters error codes such as 403, 408, 500, 502, 503, 504. request-retry: 3 # Processing behavior after the model is restricted. quota-exceeded: # The core configuration of multi-account polling. # When set to true, for example, if an account triggers a 429, the program # will automatically switch to the next account to re-initiate the request. # When set to false, the program will send the 429 error message to the # client and end the current request. # That is to say, when it is set to true, as long as at least one of the # polling accounts is normal, the client will not report an error. # When it is set to false, the client needs to retry or abort the operation. switch-project: true # Gemini CLI exclusive configuration, applicable to Gemini 2.5 Pro and # Gemini 2.5 Flash models. # When the official version quota is used up, it will automatically switch to # the Preview model. Just keep it on. switch-preview-model: true # Hidden configuration, you can turn off the interval time during retries, and # set it as needed. # For example, after a model triggers 429, the program will temporarily disable # it, and each time it is triggered again, the deactivation time will be # increased, up to a maximum of 30 minutes. # By default, the model will be skipped during the deactivation period. # After setting it to true, the request will still be sent to the model every # time, regardless of whether the model is in the deactivation period, and it # will no longer be skipped. disable-cooling: false # The keys required for various AI clients to access CLIProxyAPI are set here. # Do not confuse them with the various keys below. # In layman's terms, the Key here is what CLIProxyAPI needs to set as a # server. # The various keys below are what CLIProxyAPI needs as a client to access the ``` -------------------------------- ### Codex API Key Configuration Example Source: https://help.router-for.me/configuration/provider/codex-compatibility Example configuration for upstream Codex compatible providers using `codex-api-key`. ```yaml codex-api-key: - api-key: "sk-atSM..." base-url: "https://www.example.com" # use the custom codex API endpoint proxy-url: "socks5://proxy.example.com:1080" # optional: per-key proxy override ``` -------------------------------- ### Get quota exceeded switch-preview-model status response Source: https://help.router-for.me/management/api Response for getting the quota exceeded switch-preview-model status. ```json { "switch-preview-model": true } ``` -------------------------------- ### CLI command to add Gemini Web authentication Source: https://help.router-for.me/hands-on/tutorial-3 This command initiates the process of adding Gemini Web authentication by prompting the user to paste their Cookie value. ```bash cli-proxy-api --gemini-web-auth ``` -------------------------------- ### Get quota exceeded switch-preview-model status Source: https://help.router-for.me/management/api Endpoint to get the status of the quota exceeded switch-preview-model setting. ```bash curl -H 'Authorization: Bearer ' http://localhost:8317/v0/management/quota-exceeded/switch-preview-model ``` -------------------------------- ### Get quota exceeded switch-project status response Source: https://help.router-for.me/management/api Response for getting the quota exceeded switch-project status. ```json { "switch-project": true } ``` -------------------------------- ### Get quota exceeded switch-project status Source: https://help.router-for.me/management/api Endpoint to get the status of the quota exceeded switch-project setting. ```bash curl -H 'Authorization: Bearer ' http://localhost:8317/v0/management/quota-exceeded/switch-project ``` -------------------------------- ### Claude Code Compatibility Configuration Example Source: https://help.router-for.me/configuration/provider/claude-code-compatibility Example configuration for upstream Claude Code compatible providers using YAML. ```yaml claude-api-key: - api-key: "sk-atSM..." # use the official claude API key, no need to set the base url - api-key: "sk-atSM..." base-url: "https://www.example.com" # use the custom claude API endpoint proxy-url: "socks5://proxy.example.com:1080" # optional: per-key proxy override models: - name: "claude-3-5-sonnet-20241022" # upstream model name alias: "claude-sonnet-latest" # client alias mapped to the upstream model ``` -------------------------------- ### View server logs Source: https://help.router-for.me/docker/docker-compose Follows the server logs in real-time. ```bash docker compose logs -f ``` -------------------------------- ### Configure Custom Web UI from GitHub Repository Source: https://help.router-for.me/cn/management/webui Example configuration to set a custom GitHub repository for the management panel. ```yaml remote-management: panel-github-repository: "https://github.com/your-org/your-management-ui" ``` -------------------------------- ### List all OpenAI compatibility providers Source: https://help.router-for.me/management/api Retrieves a list of all configured OpenAI compatibility providers. ```bash curl -H 'Authorization: Bearer ' http://localhost:8317/v0/management/openai-compatibility ``` -------------------------------- ### Codex API KEY - List all Source: https://help.router-for.me/management/api Lists all configured Codex API keys. ```bash curl -H 'Authorization: Bearer ' http://localhost:8317/v0/management/codex-api-key ``` ```json { "codex-api-key": [ { "api-key": "sk-a", "base-url": "https://codex.example.com/v1", "proxy-url": "socks5://proxy.example.com:1080", "headers": { "X-Team": "cli" }, "excluded-models": ["gpt-4o-mini"] } ] } ``` -------------------------------- ### CLIProxyAPI Configuration Source: https://help.router-for.me/cn/agent-client/amp-cli Example configuration for the CLIProxyAPI in config.yaml. ```yaml port: 8317 auth-dir: "~/.cli-proxy-api" # 供客户端(例如 Amp CLI)使用的 API 密钥 api-keys: - "your-client-secret-key" # 你可以更改此密钥 # Amp 集成 ampcode: upstream-url: "https://ampcode.com" # 你在 ampcode.com 的个人 API 密钥 upstream-api-key: "paste-your-ampcode-api-key-here" restrict-management-to-localhost: false # 其他标准设置... debug: false logging-to-file: true ``` -------------------------------- ### Gemini CLI Login Command Source: https://help.router-for.me/hands-on/tutorial-2 Command to initiate Gemini CLI login with a project ID. ```bash cli-proxy-api --login --project_id [your project ID] ``` -------------------------------- ### Management Endpoint Source: https://help.router-for.me/cn/agent-client/amp-cli Example cURL command to access a management endpoint. ```bash curl http://localhost:8317/api/user \ -H "Authorization: Bearer " ``` -------------------------------- ### Using redis-cli Source: https://help.router-for.me/management/redis-usage-queue Examples of using redis-cli to interact with the Redis Usage Queue. ```bash # pop one item (prints JSON) redis-cli -h 127.0.0.1 -p 8317 -a "" --no-auth-warning --raw LPOP queue # pop up to 50 items redis-cli -h 127.0.0.1 -p 8317 -a "" --no-auth-warning --raw RPOP queue 50 # subscribe to live usage records redis-cli -h 127.0.0.1 -p 8317 -a "" --no-auth-warning --raw SUBSCRIBE usage ``` -------------------------------- ### Clone the AIStudioBuildWS repository Source: https://help.router-for.me/hands-on/tutorial-11 This command clones the necessary project files for deployment. ```bash git clone https://github.com/hkfires/AIStudioBuildWS.git cd AIStudioBuildWS ``` -------------------------------- ### Get Debug Status Source: https://help.router-for.me/cn/management/api Retrieves the current debug status of the service. ```bash curl -H 'Authorization: Bearer ' http://localhost:8317/v0/management/debug ``` -------------------------------- ### Basic Amp CLI Usage Source: https://help.router-for.me/agent-client/amp-cli Example of using the Amp CLI to write a program after configuring the proxy. ```bash amp "Write a hello world program in Python" ``` -------------------------------- ### General Error Response - Not Found Source: https://help.router-for.me/cn/management/api Example of a 404 Not Found error response. ```json { "error": "item not found" } ```