How to Use ANTHROPIC_BASE_URL to Cut API Costs
The ANTHROPIC_BASE_URL environment variable lets you route all Anthropic API calls through a local proxy, without changing any code. RelayPlane uses this to route simple tasks to cheaper models, saving you 40-60% on API costs.
What is ANTHROPIC_BASE_URL?
Every Anthropic SDK (Python, TypeScript, and tools like OpenClaw and Claude Code) checks for the ANTHROPIC_BASE_URL environment variable before making API calls. If set, all requests go to that URL instead of api.anthropic.com.
This means you can intercept every API call your agent makes, and make intelligent decisions about which model to actually use.
Quick Setup (60 seconds)
Step 1: Install the RelayPlane proxy
npm install -g @relayplane/proxyStep 2: Initialize the proxy (first-time setup)
relayplane initSets up your config and API keys on first run.
Step 3: Start the proxy
relayplane startStarts on port 4100 by default. Runs locally on your machine.
Step 4: Set the environment variable
export ANTHROPIC_BASE_URL=http://localhost:4100Step 5: Use your tools normally
openclawThat's it. All requests now route through RelayPlane. Simple tasks go to Haiku. Complex tasks stay on Opus/Sonnet.
Tools That Support ANTHROPIC_BASE_URL
OpenClaw
Full support. Just set the env var and run.
Claude Code
Full support via ANTHROPIC_BASE_URL.
Cursor
Supports custom API endpoints in settings.
Aider
Respects ANTHROPIC_BASE_URL automatically.
Python SDK
anthropic.Anthropic() checks the env var.
TypeScript SDK
new Anthropic() checks the env var.
How This Saves You Money
When your agent sends a request for claude-4-opus, RelayPlane analyzes the request metadata (task type, token count, complexity) and decides whether a cheaper model like Haiku would work just as well.
Common Questions
Does this add latency?
Less than 5ms for local routing. The proxy runs on your machine, no network hop.
What if the cheap model fails?
RelayPlane automatically retries with a better model. Your agent never sees the failure.
Can I see what's being routed?
Run relayplane --audit to see every routing decision in real-time.
Does RelayPlane see my prompts?
No. The proxy runs locally on your machine. Your prompts go directly to Anthropic. Telemetry is on by default: only anonymous metadata (task type, token count) is shared. Disable: relayplane telemetry off
Ready to start saving?
Free tier saves 30%+. Pro tier saves 60%+. No credit card required.