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/proxy

Step 2: Start the proxy

$relayplane-proxy

Starts on port 4801 by default. Runs locally on your machine.

Step 3: Set the environment variable

$export ANTHROPIC_BASE_URL=http://localhost:4801

Step 4: Use your tools normally

$openclaw

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

# Typical agent session with RelayPlane:
[09:41:02] Reading file... → haiku ($0.001) was opus ($0.06)
[09:41:03] Listing directory... → haiku ($0.001) was opus ($0.06)
[09:41:04] Planning refactor... → sonnet ($0.02) was opus ($0.06)
[09:41:06] Complex architecture... → opus ($0.06) kept as-is
Session savings: $0.16 → $0.08 (50% saved)

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-proxy --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 opt-in and disabled by default — when enabled, only anonymous metadata (task type, token count) is shared.

Ready to start saving?

Free tier saves 30%+. Pro tier saves 60%+. No credit card required.