claude-api-proxy
v0.1.0
Published
CLI proxy for Claude Code that rotates Anthropic API keys automatically on quota exhaustion
Maintainers
Readme
claude-api-proxy setup # add your API keys
claude-api-proxy # start proxy + launch Claude Code
claude-api-proxy status # see which key is activeHow it works
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 → personalIf all keys are exhausted, the original error is passed back to Claude Code unchanged.
Requirements
- Node.js 18+
- Claude Code installed and in your PATH
Install
npm install -g claude-api-proxyQuick start
1. 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.json2. 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.
Commands
claude-api-proxy setup
Interactive wizard to add API keys. Stores them in ~/.claude-api-proxy.json.
claude-api-proxy status
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...yyyyclaude-api-proxy
Start the proxy on port 3131 and launch claude with the correct environment variables injected (ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY).
claude-api-proxy --no-launch
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 claudeclaude-api-proxy --port <n>
Use a custom port instead of the default 3131.
claude-api-proxy --port 8080claude-api-proxy --verbose / -v
Log each forwarded request and which key is being used to stderr.
[claude-api-proxy] → POST /v1/messages (key: work)Key storage
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 support
| Platform | Status | |---|---| | Linux | ✅ Supported | | macOS | ✅ Supported | | Windows | ✅ Supported |
Contributing
See CONTRIBUTING.md for local dev setup, architecture notes, and the release process.
License
MIT — see LICENSE.
