Skip to content

joachimBrindeau/claude-proxy-multi

Repository files navigation

Claude Code Proxy Multi-Account

Claude Code Proxy with Multi-Account Rotation & Rate Limit Failover

Python 3.11+ License: MIT Claude API


This fork adds: Multi-account rotation with automatic failover


Features · Quick Start · Multi-Account Setup · API Reference · Configuration


Features

Core (Inherited from CaddyGlow)

  • Claude API Proxy — Access via Claude Max subscription
  • OpenAI Format — Accepts requests in OpenAI chat completions format
  • Dual Modes — SDK mode (with MCP tools) and API mode (direct proxy)
  • OAuth2 PKCE — Automatic credential management and token refresh

Multi-Account (This Fork)

  • 3x+ throughput by distributing requests across multiple Claude accounts
  • Zero downtime with automatic failover when accounts hit rate limits
  • Proactive token refresh before expiration via background scheduler
  • Hot-reload — add/remove accounts without restart

Quick Start

Docker (Recommended)

docker run -d -p 8000:8000 -v ccproxy-data:/data/home \
  --name ccproxy ghcr.io/joachimbrindeau/claude-proxy-multi:latest

Or with Docker Compose (deploy/docker-compose.yaml):

docker compose -f deploy/docker-compose.yaml up -d

Open http://localhost:8000 to add accounts via the web UI.

Local Development

# Install dependencies
uv sync --all-extras --dev

# Start dev server
make dev

Multi-Account Rotation

How It Works

  1. Request arrives at proxy
  2. Rotation pool selects next available account
  3. Request forwarded with account's auth token
  4. On success: response returned, rotation advances
  5. On 429: automatic retry with next account

Setup

cat > ~/.claude/accounts.json << 'EOF'
{
  "version": 1,
  "accounts": {
    "primary": {
      "accessToken": "sk-ant-oat01-...",
      "refreshToken": "sk-ant-ort01-...",
      "expiresAt": 1747909518727
    },
    "secondary": {
      "accessToken": "sk-ant-oat01-...",
      "refreshToken": "sk-ant-ort01-...",
      "expiresAt": 1747909518727
    }
  }
}
EOF

Configuration

Variable Default Description
CCPROXY_ACCOUNTS_PATH ~/.claude/accounts.json Accounts file location
CCPROXY_ROTATION_ENABLED true Enable/disable rotation
CCPROXY_HOT_RELOAD true Watch file for changes
CCPROXY_REFRESH_BUFFER 600 Seconds before expiry to refresh

Status API

Endpoint Method Description
/status GET Pool aggregate status
/status/accounts GET All accounts list
/status/accounts/{name} GET Single account details
/status/accounts/{name}/refresh POST Force token refresh
/status/accounts/{name}/enable POST Re-enable disabled account

API Endpoints

Claude Endpoints

Endpoint Format Mode
POST /api/v1/messages Anthropic Direct Proxy
POST /api/v1/chat/completions OpenAI Direct Proxy
POST /sdk/v1/messages Anthropic SDK with Tools
POST /sdk/v1/chat/completions OpenAI SDK with Tools
GET /api/v1/models - List Models

Utility Endpoints

Endpoint Description
GET /health Health check
GET /status Rotation pool status

Configuration

Environment Variables

# For Anthropic-compatible clients
export ANTHROPIC_BASE_URL="http://localhost:8000/api"
export ANTHROPIC_API_KEY="dummy"

# For OpenAI-compatible clients
export OPENAI_BASE_URL="http://localhost:8000/api/v1"
export OPENAI_API_KEY="dummy"

API Key Authentication

# Enable API key authentication
export CCPROXY_SECURITY_API_KEYS_ENABLED=true
export CCPROXY_SECURITY_API_KEY_SECRET=$(openssl rand -hex 32)

# Create a key
ccproxy auth create-key --user john --expires 90

# Use it
curl -H "Authorization: Bearer <token>" http://localhost:8000/v1/chat/completions

License

MIT License - see LICENSE.

Acknowledgments

Built on claude-code-proxy by @CaddyGlow.

About

Multi-account Claude Code proxy with automatic rotation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages