Skip to content

Uruba-Software/claude-api-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

claude-api-proxy

Anthropic API key rotation proxy for Claude Code — seamlessly switch keys when one account's quota runs out.

npm version npm downloads CI Node.js version License

Linux macOS Windows


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

How 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 → personal

If all keys are exhausted, the original error is passed back to Claude Code unchanged.


Requirements


Install

npm install -g claude-api-proxy

Quick 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.json

2. Start the proxy and Claude Code:

claude-api-proxy

That'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...yyyy

claude-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 claude

claude-api-proxy --port <n>

Use a custom port instead of the default 3131.

claude-api-proxy --port 8080

claude-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.

About

Anthropic API key rotation proxy for Claude Code — seamlessly switch keys when one account's quota runs out

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors