relayplaneopenclawai-proxycost-controltutorial

OpenClaw Proxy Setup: How to Route All AI Requests Through RelayPlane

Matt Turley··7 min read

Running an AI agent setup with OpenClaw is powerful. Running it without any cost visibility is a slow-motion budget problem. By default, every model call your agents make goes directly to Anthropic with no tracking, no routing intelligence, and nothing stopping a runaway loop from torching your monthly budget overnight.

RelayPlane fixes that. It sits between OpenClaw and your AI providers, intercepts every request, and gives you cost data, smart routing, and budget controls, all without changing a single line of agent code.


Why Route OpenClaw Through a Proxy

Cost visibility. When you're running multiple agents concurrently, costs compound in non-obvious ways. A coding agent running on Claude Opus for two hours burns significantly more than a research agent hitting Sonnet for the same time. Without per-request tracking, you're flying blind. RelayPlane shows you exactly what each model call costs, broken down by model and provider, in real time.

Smart routing. Not every request needs your most expensive model. Checking a file's contents, formatting output, or summarizing a short document doesn't require Opus. RelayPlane can automatically route simple tasks to cheaper models and save the heavy calls for work that actually needs it. This is where the real cost reduction happens.

Budget enforcement. Set daily, hourly, or per-request limits. When a limit is hit, RelayPlane can block the request, downgrade it to a cheaper model, or fire an alert. If an agent gets stuck in a loop and starts hammering the API at 2 AM, it hits the wall instead of your credit card.

Cascade fallbacks. If a provider is rate-limited or down, requests can automatically fall through to the next provider on your list. Your agents keep running without you having to intervene.


3-Line Setup

Install RelayPlane globally:

npm install -g @relayplane/proxy
relayplane init
relayplane start

The proxy is now running at http://localhost:4100. Open that URL and you'll see the dashboard: model breakdown, recent runs, provider status, routing configuration.

Now point OpenClaw at it:

openclaw config set models.providers.anthropic.baseUrl http://localhost:4100

That's the entire integration. Every anthropic/* model call from every agent in your OpenClaw setup now flows through RelayPlane. No agent code changes. No model name changes. Your API credentials pass through as-is.

To run RelayPlane as a background service that starts automatically:

relayplane autostart

What RelayPlane Does Behind the Scenes

When a request hits the proxy, here's what happens:

  1. Routing decision. RelayPlane checks the request against your routing config. In complexity mode (the default), it classifies the request as simple, moderate, or complex and maps it to the corresponding model. In cascade mode, it tries your first-choice model and falls back automatically if needed.
  2. Cost calculation. Input and output tokens are counted and multiplied against current model pricing. If you're using Anthropic's prompt caching, RelayPlane tracks both the cache read savings and cache creation costs separately.
  3. Budget check. If you have a budget configured, RelayPlane checks whether this request would breach your limits and applies whatever action you specified: block, warn, downgrade, or alert.
  4. Anomaly detection. RelayPlane watches for patterns that look like runaway loops: repeated identical requests, sudden cost spikes, token explosion. When it spots one, it fires an alert before it becomes a problem.
  5. Cache check. If aggressive caching is enabled, identical requests return cached responses instead of hitting the API at all.

The whole thing is transparent to your agents. From OpenClaw's perspective, it made a normal Anthropic API call and got a normal response.


Configuration Options

Complexity-Based Routing

Edit ~/.relayplane/config.json to set up model mapping by request complexity:

{
  "routing": {
    "mode": "complexity",
    "models": {
      "simple": "claude-haiku-3-5",
      "moderate": "claude-sonnet-4-5",
      "complex": "claude-opus-4-6"
    }
  }
}

Cascade (Cheap-to-Expensive Fallback)

{
  "routing": {
    "mode": "cascade",
    "cascade": ["claude-haiku-3-5", "claude-sonnet-4-5", "claude-opus-4-6"]
  }
}

Budget Caps

relayplane budget set --daily 20 --action downgrade
relayplane budget set --per-request 0.50 --action warn

Or directly in config:

{
  "budget": {
    "daily": 20,
    "perRequest": 0.50,
    "actions": {
      "onDailyBreach": "downgrade",
      "onRequestBreach": "warn"
    }
  }
}

Available actions: block, warn, downgrade, alert.

Multi-Provider Setup

RelayPlane supports 11 providers with native routing: Anthropic, OpenAI, Google Gemini, xAI/Grok, OpenRouter, DeepSeek, Groq, Mistral, Together, Fireworks, and Perplexity. For cross-provider fallbacks, configure each provider's API key:

relayplane config set providers.openai.apiKey sk-your-key
relayplane config set providers.gemini.apiKey your-key

Before and After: Cost Comparison

To illustrate the difference, here's roughly what running five agents concurrently over one day looks like with and without routing.

Without routing (everything hits Opus):

ModelRequestsAvg TokensCost
claude-opus-4-68402,400~$42

With complexity routing:

ModelRequestsAvg TokensCost
claude-haiku-3-55201,200~$0.75
claude-sonnet-4-52402,800~$4.80
claude-opus-4-6804,100~$8.00
Total840~$13.55

These are illustrative estimates based on published model pricing, not a guaranteed outcome. Your actual savings depend on your workload mix. RelayPlane's dashboard shows your real numbers after a few sessions of data.


Getting Started

If you're running OpenClaw and paying Anthropic bills without knowing what's driving them, the three-command install is worth doing today:

npm install -g @relayplane/proxy
relayplane init
relayplane start

Then point OpenClaw at the proxy:

openclaw config set models.providers.anthropic.baseUrl http://localhost:4100

Open http://localhost:4100, watch your first session come through, and you'll immediately see where the cost is going. From there, routing config and budget caps take about five minutes to set up.


RelayPlane is free. Local-only, no account required, no usage limits on the free tier. The dashboard, routing, budgets, and anomaly detection are all included. Install it here or read the docs at relayplane.com.