Anthropic API key rotation proxy for Claude Code — seamlessly switch keys when one account's quota runs out.
claude-api-proxy setup # add your API keys
claude-api-proxy # start proxy + launch Claude Code
claude-api-proxy status # see which key is active
claude-api-proxy runs a local HTTP proxy on port 3131. It starts Claude Code as a child process with ANTHROPIC_BASE_URL pointing at the proxy. Every API request is forwarded to api.anthropic.com with the currently active key injected.
When a quota or credit exhaustion error is detected (402, 429, 529 / credit_balance_too_low, rate_limit_error, overloaded_error), the proxy silently rotates to the next configured key and retries — without interrupting your Claude Code session.
[claude-api-proxy] ⚡ KEY ROTATED: work → personal
If all keys are exhausted, the original error is passed back to Claude Code unchanged.
- Node.js 18+
- Claude Code installed and in your PATH
npm install -g claude-api-proxy1. Add your API keys:
claude-api-proxy setup[claude-api-proxy] Setup — Add your Anthropic API keys
Keys are stored in ~/.claude-api-proxy.json
Key label (e.g. "work", "personal") [leave blank to finish]: work
API key for "work" (sk-ant-...): sk-ant-api03-...
✓ Added key "work"
Add another key? (y/N): y
Key label (e.g. "work", "personal") [leave blank to finish]: personal
API key for "personal" (sk-ant-...): sk-ant-api03-...
✓ Added key "personal"
Add another key? (y/N): n
✓ Saved 2 key(s) to ~/.claude-api-proxy.json
2. Start the proxy and Claude Code:
claude-api-proxyThat's it. Claude Code launches automatically with the proxy configured. When the first key hits its quota, the proxy rotates to the next key transparently.
Interactive wizard to add API keys. Stores them in ~/.claude-api-proxy.json.
List all configured keys with their labels and which one is currently active.
[claude-api-proxy] Configured API keys:
[1] work sk-ant-api03...xxxx ← active
[2] personal sk-ant-api03...yyyy
Start the proxy on port 3131 and launch claude with the correct environment variables injected (ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY).
Start the proxy only. Useful if you want to launch Claude Code manually or connect another tool.
claude-api-proxy --no-launch
# Proxy running. Launch claude manually:
# ANTHROPIC_BASE_URL=http://127.0.0.1:3131 ANTHROPIC_API_KEY=proxy claudeUse a custom port instead of the default 3131.
claude-api-proxy --port 8080Log each forwarded request and which key is being used to stderr.
[claude-api-proxy] → POST /v1/messages (key: work)
Keys are stored in ~/.claude-api-proxy.json:
{
"keys": [
{ "label": "work", "key": "sk-ant-...", "active": true },
{ "label": "personal", "key": "sk-ant-...", "active": true }
],
"currentIndex": 0
}The proxy rotates currentIndex forward on exhaustion. After cycling through all keys, it resets. The file is updated on disk after each rotation so the active key persists across restarts.
| Platform | Status |
|---|---|
| Linux | ✅ Supported |
| macOS | ✅ Supported |
| Windows | ✅ Supported |
See CONTRIBUTING.md for local dev setup, architecture notes, and the release process.
MIT — see LICENSE.