Advanced Workflows

Virtual Routing Groups & 429 Auto-Failover

Resilient routing pools with automated rate-limit interception and silent retries for uninterrupted long tasks.

During intensive coding sessions with CLI agents like Claude Code or Codex, few things are more frustrating than hitting an unexpected HTTP 429 (Too Many Requests / Rate Limit) or an upstream server crash (HTTP 500 / 502 / 503) midway through a complex task. Rate limits interrupt automated test executions, abort full-repo refactors, and wipe out active contextual momentum.

Magpie AI introduces Virtual Routing Groups (group/[id]). By assembling multiple commercial API keys, third-party proxies, and linked web accounts into a resilient upstream pool, Magpie intercepts rate-limit errors and transparently retries requests against healthy backup accounts within milliseconds—delivering continuous, uninterrupted agent execution.

This tutorial explores the mechanics of virtual routing groups, configuration commands, and failover best practices.


How Routing Groups Work

Conventional proxies merely forward traffic to a single fixed upstream. Magpie AI embeds a dynamic state machine and request replay pipeline inside its local Go gateway:

text
[ Developer CLI (Claude Code) ]
           │
           ▼ (Target: group/opus-anywhere)
[ Magpie AI Local Gateway (127.0.0.1:3425) ]
  ┌────────────────────────────────────────────────────────┐
  │         Routing Group Dispatcher                       │
  │  1. Primary call: Claude Pro Account A (Returns 429!)  │
  │  2. Interception: Gateway traps 429, hides from client │
  │  3. Silent retry: Replays context payload to Account B │
  │  4. Graceful fallback: If Account B limits, routes R1  │
  └────────────────────────┬───────────────────────────────┘
                           │
                           ▼ (Successful 200 OK stream)
[ Developer CLI (Claude Code continues without error) ]

Core Architecture Benefits:

  • Completely Transparent to Clients: Claude Code simply communicates with the virtual endpoint group/[id]. It remains entirely unaware of internal retries or account rotations.
  • Idempotent In-Memory Replay: The gateway buffers the request payload in RAM. When a 429 is encountered, it dispatches an identical request to the next healthy channel immediately.
  • Dynamic Health Tracking: Rate-limited accounts are automatically placed in a temporary cooldown cooldown pool until their quota windows reset, eliminating redundant retries.

Manage groups cleanly using the magpie group command suite:

1. Create a Resilient Group

bash
# Create a multi-channel group named "opus-anywhere"
# Primary: official Claude, Secondary: Copilot, Fallback: DeepSeek R1
magpie group add "opus-anywhere" \
  models=claude/claude-opus-5-5,copilot/claude-opus-5.5,deepseek/deepseek-r1 \
  routing=smart

Routing Strategy Options:

  • routing=smart (Recommended): Routes to the primary endpoint first; automatically cascades to backup routes on 429, 500, or connection timeouts, dynamically ranking routes by response latency.
  • routing=fallback: Strictly cascades down the list in designated order.
  • routing=round-robin: Evenly balances requests across accounts, ideal for distributing workloads across team seats.

2. Bind an Agent to the Routing Group

Assign the virtual route just like any normal model:

bash
# Route Claude Code through the routing group
magpie claude group/opus-anywhere

# Route Codex through a dedicated cluster
magpie codex group/codex-cluster

The terminal confirms the route:

text
✓ Switched Claude Code to group/opus-anywhere (3 upstream candidates)

3. Inspect Active Groups

bash
# List all configured routing groups
magpie groups

# Inspect member statuses and failover metrics
magpie group show opus-anywhere

Method 2: macOS Menu Bar & GUI

For visual configuration:

  1. Open the Dashboard: Click the Magpie icon in your menu bar and launch the desktop console.
  2. Navigate to Routing Groups: Click the 「Routing Groups」 tab in the sidebar.
  3. Click 「Create Group」:
    • Name your routing group (e.g., DeepSeek Backup Pool).
    • Check off provider and model nodes from your inventory.
    • Drag handles to arrange trial priority.
    • Choose Smart Failover as the policy.
  4. Select from Dropdown: Once saved, the new group appears directly inside the agent model selector dropdown in your menu bar.

Tailor your routing pools to match your operational requirements:

Scenario 1: Cost-Saver Cascade

  • Purpose: Spend 90% of development on high-speed economical models; gracefully elevate to frontier reasoning on difficult tasks or service hiccups.
  • Nodes: deepseek/deepseek-v4-pro -> kimi/kimi-k2.5 -> claude/claude-3-5-sonnet
  • Policy: routing=smart

Scenario 2: Team Web Subscription Pool

  • Purpose: Aggregate multiple Claude Pro accounts across team members to overcome 5-hour quota windows.
  • Nodes: claude-account-1 -> claude-account-2 -> claude-account-3
  • Policy: routing=smart (automatic handoff upon rate limit)

Scenario 3: Deep Reasoning Resilience

  • Purpose: Ensure extended algorithmic reasoning sessions never abort due to network anomalies.
  • Nodes: deepseek/deepseek-r1 -> openai/o3-mini -> anthropic/claude-3-5-sonnet
  • Policy: routing=fallback

FAQ & Diagnostics

Q: Will I lose in-progress code output during a failover?

A: If a rate limit or 5xx occurs during the initial handshake before tokens stream, the gateway replays the prompt completely invisibly. If a connection drops midway through streaming, Magpie attaches the received token checkpoint to request continuity from the backup provider.

Q: How can I verify that a failover actually occurred?

A: Check real-time traffic in magpie tui or run magpie logs. Failover events are prominently highlighted: [FAILOVER] Upstream #1 returned 429, silently switched to upstream #2 in 45ms.

Q: When does a rate-limited account become eligible to receive requests again?

A: Magpie parses upstream Retry-After headers and tracks vendor sliding-window durations. When the rate-limit window resets, the gateway scheduler automatically restores the account to Ready status and re-includes it in the dispatch rotation without requiring manual action.