Use AMP's free $10/day grant first. When exhausted, switch to your own subscriptions (Claude, Gemini, Codex, GitHub Copilot, Kiro, etc.) — all from within AMP CLI. No restart needed.
CLIProxyAPI / CLIProxyAPIPlus doesn't include the prefer-upstream feature out of the box. You need to add it first.
Drop IMPLEMENT-PREFER-UPSTREAM.md into your AI coding agent (Claude Code, AMP, Cursor, etc.) and ask it to implement the changes. It's 7 small edits that follow the existing ForceModelMappings pattern.
Or apply manually — the file has exact code snippets for each change.
AMP CLI --> CLIProxyAPIPlus (localhost:8317) --> ampcode.com (free tier)
|
v (any 4xx/5xx = auto-fallback)
Local OAuth providers
(Claude, Gemini, Codex, Copilot, Kiro...)
Two modes, switchable live from AMP CLI:
- Free mode (default): All requests go to ampcode.com. On any error, auto-falls back to local.
- Local mode: Requests go directly to your OAuth subscriptions. Zero ampcode.com usage.
git clone https://github.com/router-for-me/CLIProxyAPIPlus.git
cd CLIProxyAPIPlus
go build -o cli-proxy-api ./cmd/serverRun whichever logins match your subscriptions:
# Google (Gemini)
./cli-proxy-api --login
# Claude (Anthropic)
./cli-proxy-api --claude-login
# Codex (OpenAI / ChatGPT Plus/Pro)
./cli-proxy-api --codex-login
# GitHub Copilot
./cli-proxy-api --github-copilot-login
# Kiro (AWS CodeWhisperer)
./cli-proxy-api --kiro-aws-authcode
# or: --kiro-login (Google OAuth), --kiro-import (from Kiro IDE)
# Qwen
./cli-proxy-api --qwen-loginTokens are saved to ~/.cli-proxy-api/. You can log in to multiple providers — more fallback options.
In the CLIProxyAPIPlus/ directory:
port: 8317
# Secret key AMP uses to authenticate with this proxy (change this!)
api-keys: ["YOUR_PROXY_SECRET_KEY"]
# Amp integration
ampcode:
upstream-url: "https://ampcode.com"
upstream-api-key: "sgamp_user_XXXX_YYYY" # Your ampcode.com API key
prefer-upstream: true # Start in free tier mode
restrict-management-to-localhost: false
# Management API (needed for the mode-toggle skill)
remote-management:
allow-remote: true
secret-key: "YOUR_MANAGEMENT_KEY" # Auto-hashed on first startup (change this!)
disable-control-panel: true
# Auth token directory
auth-dir: "~/.cli-proxy-api"
# Recommended settings
request-retry: 3
quota-exceeded:
switch-project: true
switch-preview-model: trueWhere to find your ampcode.com API key: Check
~/.local/share/amp/secrets.json— the value after"apiKey@https://ampcode.com/"is your key.
Edit ~/.config/amp/settings.json — add amp.url:
{
"amp.url": "http://localhost:8317"
}Keep your existing settings (mcpServers, git settings, etc.) — just add the
amp.urlline.
Edit ~/.local/share/amp/secrets.json — add the proxy entry:
{
"apiKey@https://ampcode.com/": "sgamp_user_XXXX_YYYY",
"apiKey@http://localhost:8317": "YOUR_PROXY_SECRET_KEY"
}The YOUR_PROXY_SECRET_KEY must match the api-keys value in your config.yaml.
AMP uses skills for custom functionality. Create this skill so you can say "switch to local mode" or "switch to free tier" directly in AMP.
mkdir -p ~/.config/agents/skills/amp-mode
cat > ~/.config/agents/skills/amp-mode/SKILL.md << 'SKILL'
---
name: amp-mode
description: Switch AMP routing mode between free tier (ampcode.com) and local OAuth providers (Claude, Gemini, Codex, Copilot, Kiro). Use when the user says "switch to local", "switch to free", "check mode", "use local providers", "use free tier", or anything about changing the routing mode.
---
# AMP Routing Mode Toggle
You can switch AMP's routing mode by calling the CLIProxyAPI management API.
## Check current mode
```bash
curl -s http://localhost:8317/v0/management/ampcode/prefer-upstream -H "Authorization: Bearer YOUR_MANAGEMENT_KEY"If prefer-upstream is true → FREE TIER mode (ampcode.com first, auto-fallback to local on any error).
If prefer-upstream is false → LOCAL OAUTH mode (uses your subscriptions directly).
curl -s -X PUT http://localhost:8317/v0/management/ampcode/prefer-upstream \
-H "Authorization: Bearer YOUR_MANAGEMENT_KEY" \
-H "Content-Type: application/json" \
-d '{"value": false}'Tell the user: "Switched to LOCAL OAUTH mode. Requests now go directly to your subscriptions."
curl -s -X PUT http://localhost:8317/v0/management/ampcode/prefer-upstream \
-H "Authorization: Bearer YOUR_MANAGEMENT_KEY" \
-H "Content-Type: application/json" \
-d '{"value": true}'Tell the user: "Switched to FREE TIER mode. Requests route to ampcode.com first (auto-falls back to local on any error)."
- The change takes effect immediately — no restart needed.
- Always confirm the action to the user after running the curl command.
- If the user just says "switch mode" without specifying, check the current mode first and switch to the opposite. SKILL
> Replace `YOUR_MANAGEMENT_KEY` with the plaintext `secret-key` from your `config.yaml` (before it gets hashed).
After creating the skill, restart AMP. It will appear under **skill: invoke** in the command palette, and AMP can also use it autonomously when you say things like "switch to local".
## 6. Start & Use
```bash
cd CLIProxyAPIPlus
./cli-proxy-api
Then open AMP CLI and start coding. That's it.
| Time | What happens | Action |
|---|---|---|
| Start of day | Free tier active | Just code normally |
| Free tier exhausted | Auto-fallback kicks in | Nothing to do — it just works |
| Want to skip upstream? | Tell AMP: "switch to local mode" | Skips ampcode.com round-trip |
| Next day | Tell AMP: "switch to free tier" | Back to ampcode.com |
- "switch to free tier" — use ampcode.com free grant
- "switch to local mode" — use your OAuth subscriptions directly
- "check mode status" — see which mode is active
In free tier mode, if ampcode.com returns any error (402 payment required, 429 rate limit, 5xx server error, etc.), the proxy automatically falls back to your local providers for that request. No manual intervention needed — you can keep coding without interruption.
| Provider | Login Command | Subscription |
|---|---|---|
| Google Gemini | --login |
Free / Google One AI |
| Claude | --claude-login |
Pro / Max |
| Codex (OpenAI) | --codex-login |
ChatGPT Plus / Pro |
| GitHub Copilot | --github-copilot-login |
Copilot subscription |
| Kiro (AWS) | --kiro-aws-authcode |
AWS Builder ID |
| Qwen | --qwen-login |
Free |
| Vertex AI | --vertex-import key.json |
GCP account |
The more providers you authenticate, the more fallback options you have.
AMP can't connect:
Check that amp.url in settings.json matches the proxy port, and the API key in secrets.json matches api-keys in config.yaml.
Mode toggle skill not showing:
Make sure the skill is at ~/.config/agents/skills/amp-mode/SKILL.md and restart AMP. Skills are discovered at startup.
No local fallback happening:
Run your OAuth logins first (--login, --claude-login, etc.). Check proxy logs for "using local provider" vs "forwarding to ampcode.com".
Revert to direct AMP (no proxy):
Remove "amp.url" from settings.json and the "apiKey@http://localhost:8317" line from secrets.json.
- CLIProxyAPIPlus (this fork — GitHub Copilot, Kiro support)
- CLIProxyAPI (upstream)
- CLIProxyAPI Docs
- AMP CLI Setup Guide