OpenClawRouter

March 24, 2026 · View on GitHub

OpenClaw plugin that routes AI model requests to the cheapest x402 provider with automatic failover and smart model selection.

Install

openclaw plugins add --source git --url https://github.com/obulai/OpenClawRouter

Or manually:

git clone https://github.com/obulai/OpenClawRouter ~/.openclaw/extensions/openclawrouter
cd ~/.openclaw/extensions/openclawrouter && npm install && npm run build

Configure

Add to ~/.openclaw/openclaw.json:

{
  "plugins": {
    "entries": {
      "openclawrouter": {
        "enabled": true,
        "config": {
          "mode": "obul",
          "routingProfile": "auto",
          "obulApiKey": "your-key-here"
        }
      }
    }
  }
}

Or just set the env var:

export OBUL_API_KEY=your-key-here

What It Does

Once installed, the plugin:

  1. Registers /v1/chat/completions on the gateway — an OpenAI-compatible endpoint that routes through 6 x402 providers
  2. Hooks into before_model_resolve — when an agent requests model: "auto", the 14-dimension classifier picks the optimal model tier
  3. Registers slash commands/providers and /routing for visibility

How Routing Works

Agent sends LLM request


Smart Routing (14-dimension classifier)
  ├─ Explicit model → use it
  └─ "auto" → classify → pick tier → pick model


Provider Selection
  ├─ Find all providers for model
  ├─ Probe x402 pricing (parallel, 2s timeout)
  ├─ Sort cheapest-first
  └─ Spend control check


Failover Loop (up to 4 attempts)
  ├─ Translate request to provider format
  ├─ Send via payment backend (Obul proxy or direct x402)
  ├─ Translate response back to OpenAI format
  └─ On 5xx/429/timeout → next provider


Response + headers (x-provider, x-mode, x-failover-count, x-routing-tier)

Config Options

OptionTypeDefaultDescription
mode"obul" | "wallet""obul"Payment mode
routingProfile"auto" | "eco" | "premium" | "agentic""auto"Smart routing profile
obulApiKeystringObul API key (or OBUL_API_KEY env)
obulBaseUrlstringhttps://obul.polymerdao.xyzObul proxy URL
walletMnemonicstringBIP-39 mnemonic for wallet mode
maxPerRequestintegerMax spend per request (USD cents)
maxHourlyintegerMax hourly spend (USD cents)
maxDailyintegerMax daily spend (USD cents)

Payment Modes

Obul mode (recommended): Routes through Obul's proxy. Obul handles x402 payment. You just need an API key.

Wallet mode: Routes directly to providers. A local BIP-39 wallet signs x402 payments with USDC on Base.

Routing Profiles

ProfileSimpleMediumComplexReasoning
autogemini-3.1-flash-liteclaude-sonnet-4-6claude-opus-4-6claude-opus-4-6
ecogemini-3.1-flash-litedeepseek-v3.2claude-sonnet-4-6claude-sonnet-4-6
premiumclaude-sonnet-4-6claude-opus-4-6gpt-5claude-opus-4-6
agenticclaude-sonnet-4-6claude-sonnet-4-6claude-opus-4-6claude-opus-4-6

Providers

ProviderHostFormatDynamic Pricing
x402enginex402engine.appx402engineNo
BlockRunblockrun.aiblockrunYes
Daydreamsai.xgate.runopenaiYes
AskClaudeaskclaude.shopaskclaudeNo
Spraaygateway.spraay.appspraayNo
MiniMaxxingminimaxxing.x402endpoints.comopenaiNo

Slash Commands

  • /providers [model] — list providers (or all models if no argument)
  • /routing — show current mode, profile, and cache stats

Standalone Mode

For non-OpenClaw usage, a standalone proxy is available:

OBUL_API_KEY=your-key npx openclawrouter start
curl http://localhost:8402/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "messages": [{"role": "user", "content": "Hello"}]}'

Development

npm install
npm test        # 263 tests
npm run lint    # type check
npm run build

License

MIT