Route each Claude Code model tier to different providers! Use GLM for Haiku/Opus and keep Sonnet on your Claude subscription - all at the same time.
Apparently I'm one of the "2%" of users that should encounter or be affected by Anthropic's new weekly limits. So I built this proxy to route certain models to LLM providers of your choice - welcome to the good ol days when we didn't need to worry about hitting our weekly limit. These models work with agents too!
- ✨ 3 independent providers - Route Haiku, Opus, and Sonnet to different APIs simultaneously
- 🔄 Mix and match - GLM for speed/cost, Claude for premium
- 💰 Cost optimized - Route cheap tasks to alternatives, premium to Claude
- 🔐 OAuth preserved - Keep your Claude subscription active for Sonnet
- 🎯 Dead simple - Each tier configured with just 2 environment variables
- 🌐 Cross-platform - Works on macOS, Linux, and Windows
Claude Code UI Proxy Routes To
───────────────── ───────────────────────────────
Haiku (glm-4.6) → GLM API
Opus (glm-4.5-air) → GLM API
Sonnet (claude-sonnet) → Real Anthropic (OAuth)
The proxy intercepts Claude Code's API requests:
- You set:
ANTHROPIC_BASE_URL=http://localhost:8082 - Claude Code sends requests to:
localhost:8082instead ofapi.anthropic.com - Proxy checks model name:
glm-4.6→ Routes to GLM (HAIKU_PROVIDER_BASE_URL)glm-4.5-air→ Routes to GLM (OPUS_PROVIDER_BASE_URL)claude-sonnet-4-5→ Routes to real Anthropic (OAuth passthrough)
macOS/Linux:
# 1. Install dependencies
pip install -r requirements.txt
# 2. Configure providers - Create .env file with:
cat > .env << 'EOF'
# Provider configurations
HAIKU_PROVIDER_API_KEY=sk-glm-xxx
HAIKU_PROVIDER_BASE_URL=https://api.z.ai/api/anthropic
OPUS_PROVIDER_API_KEY=sk-glm-xxx
OPUS_PROVIDER_BASE_URL=https://api.z.ai/api/anthropic
# Sonnet uses OAuth (leave commented)
# SONNET_PROVIDER_API_KEY=
# SONNET_PROVIDER_BASE_URL=
# Model name configuration
ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-4.6
ANTHROPIC_DEFAULT_OPUS_MODEL=glm-4.5-air
EOF
# 3. Configure Claude Code (add to ~/.zshrc or ~/.bashrc)
export ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-4.6
export ANTHROPIC_DEFAULT_OPUS_MODEL=glm-4.5-air
export ANTHROPIC_BASE_URL=http://localhost:8082 # ⚠️ CRITICAL
# 4. Start proxy & use Claude Code
python proxy.py &
claudeWindows (PowerShell):
# 1. Install dependencies
pip install -r requirements.txt
# 2. Configure providers - Create .env file with:
@"
# Provider configurations
HAIKU_PROVIDER_API_KEY=sk-glm-xxx
HAIKU_PROVIDER_BASE_URL=https://api.z.ai/api/anthropic
OPUS_PROVIDER_API_KEY=sk-glm-xxx
OPUS_PROVIDER_BASE_URL=https://api.z.ai/api/anthropic
# Sonnet uses OAuth (leave commented)
# SONNET_PROVIDER_API_KEY=
# SONNET_PROVIDER_BASE_URL=
# Model name configuration
ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-4.6
ANTHROPIC_DEFAULT_OPUS_MODEL=glm-4.5-air
"@ | Out-File -FilePath .env -Encoding utf8
# 3. Configure Claude Code (add to PowerShell $PROFILE)
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "glm-4.6"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "glm-4.5-air"
$env:ANTHROPIC_BASE_URL = "http://localhost:8082" # ⚠️ CRITICAL
# 4. Start proxy & use Claude Code
Start-Process python -ArgumentList "proxy.py" -WindowStyle Hidden
claudeWhat goes where:
.envfile → Provider configs + model name mappings (read by proxy)- Shell env vars → Model names (
ANTHROPIC_DEFAULT_*_MODEL) + base URL pointing to localhost:8082
- GLM (via Z.AI) - Fast, cheap Chinese models
- Claude - Premium Anthropic models via OAuth
- Any Anthropic-compatible API - Works with any provider supporting
/v1/messages
Haiku → GLM (glm-4.6) # $0.02/1M tokens
Opus → GLM (glm-4.5-air) # $0.01/1M tokens
Sonnet → Claude (real) # Your subscription| Benefit | Description |
|---|---|
| ✅ Keep your Claude subscription | Uses OAuth, no API key needed |
| ✅ 3 providers simultaneously | Different provider for each tier |
| ✅ Native Claude Code support | Uses built-in environment variables |
| ✅ Update-proof | No SDK modifications, survives updates |
| ✅ Transparent | /model command shows actual routed model names |
| ✅ Simple | Just environment variables, no complex config |
- Python 3.8+
- Claude Code installed globally
- Provider(s) with Anthropic-compatible API
Agents automatically use your configured models:
---
name: my-agent
model: haiku # Uses glm-4.6 (your ANTHROPIC_DEFAULT_HAIKU_MODEL)
---The proxy implements the following Anthropic API endpoints:
| Endpoint | GLM Providers | Real Anthropic | Notes |
|---|---|---|---|
POST /v1/messages |
✅ Full support | ✅ Full support | Main chat completion endpoint |
POST /v1/messages/count_tokens |
✅ Full support | Token counting before sending. GLM doesn't support this - use token counts from message responses instead | |
GET /health |
✅ Proxy health | ✅ Proxy health | Proxy status endpoint (not forwarded to providers) |
About Token Counting:
- Sonnet (Real Anthropic): Token counting works normally via
/v1/messages/count_tokens - Haiku/Opus (GLM): Token counting returns HTTP 501 with a helpful message. Token usage is still available in every
/v1/messagesresponse under theusagefield.
Proxy not intercepting requests?
macOS/Linux:
echo $ANTHROPIC_BASE_URL # Should output: http://localhost:8082
echo $ANTHROPIC_DEFAULT_HAIKU_MODEL # Should output: glm-4.6
echo $ANTHROPIC_DEFAULT_OPUS_MODEL # Should output: glm-4.5-air
# If empty, add to ~/.zshrc or ~/.bashrc:
# export ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-4.6
# export ANTHROPIC_DEFAULT_OPUS_MODEL=glm-4.5-air
# export ANTHROPIC_BASE_URL=http://localhost:8082Windows:
echo $env:ANTHROPIC_BASE_URL # Should output: http://localhost:8082
echo $env:ANTHROPIC_DEFAULT_HAIKU_MODEL # Should output: glm-4.6
echo $env:ANTHROPIC_DEFAULT_OPUS_MODEL # Should output: glm-4.5-air
# If empty, add to PowerShell $PROFILE:
# $env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "glm-4.6"
# $env:ANTHROPIC_DEFAULT_OPUS_MODEL = "glm-4.5-air"
# $env:ANTHROPIC_BASE_URL = "http://localhost:8082"Check if proxy is running:
curl http://localhost:8082/healthExpected response:
{
"status": "healthy",
"haiku": {"model": "glm-4.6", "provider_set": true},
"opus": {"model": "glm-4.5-air", "provider_set": true},
"sonnet": {"uses_oauth": true}
}Models not routing correctly?
- Verify model names in
.envmatchANTHROPIC_DEFAULT_*_MODELvars - Check proxy logs for routing info
- Test provider API keys directly with
curl
Sonnet OAuth not working?
claude --login # Refresh your Claude sessionMIT