跪拜 Guibai
← Back to the summary

Magpie Turns Stray Free-Tier AI Tokens Into Failover-Ready Routing Groups

magpie: 让薅到的 AI 羊毛物尽其用

Now many vendors offer free tokens, but they are scattered across various Agents or token plans. Managing these "wool" (freebies) centrally has always been a headache.

Recently magpie has been getting attention on Twitter. At first I dismissed it — just a local proxy for forwarding, I thought. My own config files made it unnecessary.

But as it gained popularity, my contrarian side kicked in: "Let me see what you've got." With that mindset I started using it and got hooked — because it really works. The core idea is indeed to connect these models to Agents. Providers offer models, magpie sits in the middle, receives requests, and forwards them.

But it nails two things well: 1. It merges multiple models or accounts into routing groups — when one runs out, it switches to the next without interruption. 2. It divides work by intent — you add intent rules so different tasks go to different models.

Now the stray freebies I collected piecemeal get used up in time!

Back to business, let's look at how to use it:

1. Add providers

Go to the Providers page and add the services you plan to use. This step configures where models come from; which Agent uses it is determined in the next step.

Add provider panel: subscription, vendor, relay, local, and custom URL

2. Pick a model for your Agent

On the Agents page, each installed or configured Agent has its own row, showing the model it currently uses.

Agent page: connected Agents show their current model; below are non-connected Agents and installation entries

3. One group manages several models

Selecting a model for an Agent completes the setup. You only need routing groups if you want to use credits from other accounts or have a backup when the current model can't answer.

A routing group merges several models or accounts under one name. Agents select it like a single model by writing group/<id>. If one model can't answer, it switches to the next.

Routing page: four Agents send requests through three routing groups; rate-limited providers temporarily step aside

First build a primary group

My suggestion is to start with one primary coding group and configure only the key rules. There's no need to set up all groups and rules from the beginning.

Set the routing method to smart or order: if you mix multiple subscriptions and want to minimize wasted credits, use the former; if you already have a clear primary and backup order, use the latter.

Set session persistence to auto or session; long coding sessions rely on it to stay on the same account, and then you can consider whether the prompt cache can be reused.

After the primary group stabilizes, split by purpose.

Group Purpose and allocation
Primary coding group For Claude Code main sessions or the opus tier; use strong models and route by intent rules.
Fast or sub-agent group Use cheap, fast models for Explore, sub-agents, or the haiku tier.
Architecture or review group Use a stronger model or a different model family, e.g., GPT / Astra, for another perspective.
Fallback group Use free or low-cost models to keep backup options.

Route a given type of conversation to a specified model by rule

A rule can filter by conversation length, image or reasoning requirements, and can also restrict to source Agent, intent, compressed context, or active folder. Conditions can stack, so a rule like "in ~/work/acme, and long enough" is expressible.

Routing group config: add member models, choose routing method and session persistence; the red box shows a time rule preferring Hy4 preview from 18:00 to 06:00 daily

On each new message, magpie checks rules from top to bottom. The first match decides which model gets top priority; the rest act as failover. If none match, routing happens according to the group's default, staying on the original account.

Let different tasks find different models

Intent rule config example: separate descriptions for independent review, architecture design, troubleshooting, and everyday small tasks; at the bottom, select the intent-judgment model

How to read that log

The Routing page shows who answered each group's most recent request, with the reason written below the log.

Intent hit log: a "write tests" request from Claude Code hits rule 2, putting GLM-5.3 first; below is the judgment model's answer and its 964 ms latency

In the image, a message asks to write tests. The judging model says "writing or fixing tests" after 964 ms, and rule 2 puts live/aihubmix/glm-5.3 first. This log and the config screenshot above come from different examples; the model and rule numbers refer to each screenshot.

The judgment model's calls are recorded under the magpie Agent on the Usage page, with token counts and costs. To know the cost of intent judgment, look there.

Some frequently asked questions

Does magpie have to stay running?

Models used through magpie need the gateway to run alongside your applications. If you close the window, magpie stays in the menu bar or tray.

How do I restore everything?

Select the Agent's built-in model from the picker, or run magpie <agent> default. magpie will remove what it inserted and give you back your original values, e.g., ANTHROPIC_BASE_URL.

I changed the model, but the Agent still uses the old one?

Running sessions have their model set at launch. Start a new session. If it's Codex, restart the Codex app.

Start with one working group

First connect the providers you use often, configure a primary group for one Agent, then add backup models as needed. Confirm requests complete normally and you can read the routing logs, then consider splitting into a fast group, review group, or adding intent rules.

Intent judgment itself has overhead. The Usage page shows whether it's worth keeping. Get your common tasks running smoothly first, then adjust the division of labor based on actual use. Only then can you see which configurations are genuinely useful.

Magpie quick-start infographic: provider access, Agent model selection, routing groups, session persistence, and rule priority