Routing Rules

A routing rule decides which gateway serves each request for a FreeRouter key. Two strategies: a weighted %-split, or a priority order with failover. Attach one rule per key.

How rules work

Every FreeRouter key is bound to exactly one routing rule. A rule references the providers you've added to the workspace and lists them as targets. When a request arrives, FreeRouter evaluates the rule, picks a target, swaps in that provider's key, and forwards the request. If a model isn't available on the chosen target, FreeRouter skips to the next eligible target.

Edit live, no redeploy Rules are evaluated per request. Change weights or reorder priorities in the dashboard and the next request already follows the new rule — your application never changes.

Percentage split

A split rule distributes requests across targets by weight. Use it to run a cost/performance blend, A/B two gateways, or gradually shift traffic. Weights are relative; FreeRouter normalizes them to 100%.

Example — 70/30 cost blend

Send most traffic to a cheaper gateway, the rest to a faster one:

{
  "strategy": "split",
  "targets": [
    { "provider": "openrouter", "weight": 70 },
    { "provider": "vercel",     "weight": 30 }
  ]
}

Roughly 7 in 10 requests go to OpenRouter, 3 in 10 to the Vercel AI Gateway. Selection is per request, so both gateways see live traffic continuously.

Example — canary a new gateway

Start a new provider at a small share, then raise its weight as you gain confidence:

{
  "strategy": "split",
  "targets": [
    { "provider": "openrouter", "weight": 95 },
    { "provider": "cloudflare", "weight": 5 }
  ]
}
Procurement leverage Splitting traffic lets you honor a volume commitment on one gateway while proving out a competing bid on another — and shift the ratio the moment terms change. No migration required.

Priority with failover

A failover rule lists targets in priority order. FreeRouter always tries the first healthy target; if it errors, times out, or is rate limited, FreeRouter automatically retries the next target down the list, and so on.

Example — primary + backups

{
  "strategy": "failover",
  "targets": [
    { "provider": "openrouter", "priority": 1 },
    { "provider": "vercel",     "priority": 2 },
    { "provider": "cloudflare", "priority": 3 }
  ]
}

OpenRouter serves normally. If a request to it fails, FreeRouter retries the same request against Vercel, then Cloudflare, before returning an error. The X-FreeRouter-Attempts response header reports how many targets were tried.

What triggers a failover

  • Connection errors or timeouts from the upstream gateway.
  • 5xx responses from the gateway.
  • 429 rate-limit responses.
  • The requested model isn't offered by that target.

Client errors that would recur everywhere — like a malformed body (400) — are not retried; FreeRouter returns them immediately.

Split vs. failover

Use %-split when
Split
Blending cost and performance
Honoring volume commitments
A/B testing gateways
Canarying a new provider
Use failover when
Failover
Maximizing availability
You have a preferred primary
Surviving gateway outages
Absorbing rate-limit spikes

One rule per key

Because each FreeRouter key carries its own rule, you can run different strategies side by side without touching code. A common setup:

  • Production keyfailover for maximum uptime.
  • Batch/offline keysplit weighted toward the cheapest gateway.
  • Evaluation keysplit 50/50 to compare two gateways head-to-head.
Configured in the dashboard You build rules visually at app.freerouter.com; the JSON shown here is the underlying representation for reference. Attach a rule to a key when you create it, or reassign it anytime.
Next Providers