# magpie

> magpie is a free, open-source (MIT) desktop app for macOS, Windows and Linux that lets every AI coding agent use every model. Add a provider once (DeepSeek, Kimi, GLM, Qwen, MiniMax, OpenRouter, Ollama, or the Claude and ChatGPT subscriptions you already pay for), then pick it in Codex, Claude Code, Gemini CLI or any other agent. It runs a local gateway that speaks the OpenAI, Anthropic and Gemini APIs and translates between them, with streaming, tool calls and reasoning intact.

magpie lives in the menu bar (tray on Windows and Linux), with a full window, a TUI and a CLI. The Mac download is about 15 MB, built on the system WebView (no Electron). It is signed and notarised on macOS and updates itself.

Key facts:

- Website: https://usemagpie.ai/ (English), https://usemagpie.ai/zh/ (中文), https://usemagpie.ai/ja/ (日本語), https://usemagpie.ai/de/ (Deutsch)
- Source code: https://github.com/yetone/magpie
- Downloads: https://github.com/yetone/magpie-releases/releases/latest
- Install from a terminal (macOS, Linux): `curl -fsSL https://usemagpie.ai/install.sh | sh`
- Community: Discord, linked from the website
- Price: free
- Full text of every docs page in one file: https://usemagpie.ai/llms-full.txt

This file holds the full text of every English docs page. The index is https://usemagpie.ai/llms.txt.

---

Source: https://usemagpie.ai/docs/start

# Get started

magpie is one place to choose the model each of your agents uses. Add the providers you have, then pick a model per agent; magpie writes it into that agent’s own config.

Behind it is a small gateway on your machine, at `127.0.0.1:3425`. It speaks the OpenAI, Anthropic and Gemini APIs and translates between them, streaming and tool calls included, so any agent can use any provider’s models: Claude Code on a GPT model from your ChatGPT plan, Codex on DeepSeek, OpenCode on your Claude plan.

### Providers

Where models come from: subscriptions you sign in to, vendors you have an API key for, and your own endpoints. Each model is named `provider/model`.

### Agents

The tools that use them: Claude Code, Codex, Gemini CLI, OpenCode and the rest. One row each, with the model it is set to.

### Gateway

The local endpoint every agent is pointed at when you pick a model through magpie. It sends each request to whoever serves that model.

### Routing groups

Optional. Several models or accounts an agent picks as one, `group/<id>`, for when one runs out of quota.

1. **Add providers.** Sign in to your subscriptions, paste API keys. Once is enough.
2. **Pick a model for each agent.** Click the agent’s model, choose one. magpie rewrites that agent’s config.
3. **Start a new session.** Agents read their config when they start; the next session uses the new model.

## 1 · Add your providers

Open the Providers tab and press ＋ Add provider. Pick a tile, or type a vendor’s name to find it.

### Subscriptions · sign in, no key

Claude (Pro, Max, Team), ChatGPT (Plus, Pro, Business), Copilot, Gemini (Code Assist) and Antigravity; Cursor, Grok (SuperGrok), Devin and others are added from the Plugins page. Click the tile and magpie opens the vendor’s own sign-in page in your browser; the account shows up as soon as you finish (Copilot gives you a code to enter on GitHub’s page). Subscriptions are added here, in magpie, not by logging in inside another agent.

- **More than one account..** Click the Claude or ChatGPT tile again to add another; each is listed under the provider, one click from being the one in use.
- **Already signed in?.** An agent you are signed in to on this machine shows up as a provider too, *signed in as …*.
- **Every agent can use it..** A subscription’s models are `claude/…`, `codex/…`, `copilot/…`, `antigravity/…` in every other agent’s picker: to run Antigravity’s Claude or Gemini models in Codex or Claude Code, sign in to Antigravity here and pick an `antigravity/…` model on the agent’s row. Nothing else to set up. Google may suspend an Antigravity account it sees used outside Antigravity, so use one you can afford to lose. Claude subscription requests run through the Claude Code installed on this machine, so keep it installed.

### Vendors

Anthropic, OpenAI, Google Gemini, DeepSeek, Kimi, Zhipu GLM, MiniMax, Qwen, Mistral, Groq, xAI and more. Pick one, paste the key (Get a key ↗ links to the vendor’s key page), save. magpie asks the vendor which models it serves and offers those; open the provider’s row to choose which ones agents see, or Test it.

### On this machine

Ollama and LM Studio. No key.

### Custom · any compatible URL

For anything else: a Name, an OpenAI compatible base URL (ending in `/v1`), an Anthropic compatible one (the root, what `ANTHROPIC_BASE_URL` would take), or both, and the key. Give every API the endpoint speaks; each agent uses the one it speaks natively and magpie translates for the rest.

> **Already set up providers in Claude Code or Codex?** Import… at the top of the sheet reads Claude Code’s `settings.json` and Codex’s `config.toml`, changes nothing in them, and brings over the providers you tick.

Keys live in `~/.config/magpie/providers.json`, readable by you alone. magpie never reads keys from your shell environment: what you add is what it uses.

## 2 · Pick a model for each agent

The Agents tab has a row for each agent installed or configured on this machine. magpie knows Claude Code, Codex, Gemini CLI, OpenCode, MiMo Code, DevEco Code, Pi, Goose, Cursor CLI, Copilot CLI, Crush, DeepSeek Harness, Command Code, omp, OmO, Devin, Hermes Agent, MiniMax Code, Grok Build, ZCode, OpenHanako and Alma.

- **Click the model.** to open the picker. Models are grouped: the agent’s own, your routing groups, then each provider you added. Type to filter, or type any model id that is not listed.
- **Reasoning effort.** , where the agent has it (Codex’s *effort*, Pi’s *thinking*), is a slider under the list.
- **Fast mode..** A model with a fast mode has a bolt on its row, beside its star; it shows on the picked row and under the pointer. That is a GPT model of a ChatGPT (Codex) account, a GPT or o-series model on an OpenAI key, Cursor’s models with a fast variant, Claude Opus on an Anthropic key, and a plugin’s or another magpie’s model that says it is served at priority. Click it, and every request this agent sends that model goes in its vendor’s fast mode, quicker at a higher price: `service_tier: "priority"`, as Codex’s own `/fast` sends it, or Claude’s `speed: "fast"`, whatever API the agent speaks. Click again for Ultrafast, where a ChatGPT account offers it on the model, and again for the usual speed. Each agent is switched apart, and the model’s fallbacks go as they are. In a routing group, each member has the same switch in its row.
- **Claude Code through magpie.** can also give its opus, sonnet and haiku tiers models of their own; by default they follow the main model.

Picking a model writes it into the agent’s own config file. Only the keys magpie needs change; comments, ordering and indentation survive, and writes are atomic.

| Agent | What a model through magpie writes |
| --- | --- |
| Claude Code | `~/.claude/settings.json`: `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` and the model variables in its `env` block |
| Codex | `~/.codex/config.toml`: a `[model_providers.magpie]` table and the model, with the list in `magpie-models.json`. Your ChatGPT sign-in is left alone |
| OpenCode, MiMo Code, DevEco Code, Pi, Crush | A `magpie` provider entry, and `magpie/provider/model` |
| AtomCode | `~/.atomcode/config.toml`: a `magpie` provider account and one model entry per catalog model |
| Snow CLI | `~/.snow/profiles/magpie.json`: a `magpie` profile, made the active one (Snow App takes it in with "Sync Snow CLI API config") |
| QwenPaw | A `magpie` provider in `~/.qwenpaw.secret/providers/custom/magpie.json`, and each agent's `active_model` in its `agent.json`. Restart QwenPaw after the first connect |
| Gemini CLI | `GOOGLE_GEMINI_BASE_URL` pointed at the gateway, API-key auth, and the model |

**A running session keeps the model it started with.** Agents read their config when they start, so the change applies to the next session. Codex builds its model list at start-up too: restart the Codex app and open `codex` sessions after a switch.

> **Paseo, editor extensions and other front-ends** that run Claude Code or Codex for you start the same CLI, which reads the same `~/.claude` or `~/.codex` config. Set the model once in magpie and they get it too, from their next session.

> **`claude-magpie`: Claude Code through magpie, `claude` left as it is.** To keep a plain `claude` on your own Claude account and start magpie's Claude Code only when you ask for it, leave Claude Code unconnected and run `claude-magpie` instead. It starts the same `claude` with magpie's settings over yours for that session (the gateway, the model and its tiers), so `~/.claude/settings.json` is never rewritten. Every argument goes to Claude Code: `claude-magpie --resume`, `claude-magpie -p "…"`. magpie puts it beside the `magpie` command when you add that in Settings › Command line; with the command there already, run `magpie claude launcher add` once. `magpie claude run` does the same. A model you pick with `/model` in it is kept for the next `claude-magpie`, and your own `claude` keeps its model. magpie has to be running.

## 3 · Optional: routing groups

With one account per provider you can skip this. It matters once you have several: two ChatGPT accounts, or the same model from a subscription and from a key.

### Several accounts or keys in one provider

Open the provider’s row and tick every account or key to use. Routing says how requests spread over them: Smart (the default), In order, Until used up, staying on the next once one is used up even after the first renews, In turn, Least used first, Use before expiry, By weight, each account or key taking its share by the weight set beside it (a Max account 5, a Pro one 1), or Speed first, the key that answered fastest lately first. Fallback lists models to use instead when the provider is out of quota, rate limited or down.

### One model over several providers

A group is several models, from one provider or many, that an agent picks as one: `group/<id>`, under *Routing groups* in the picker. A model two of your providers serve under the same name becomes a group on its own; New group in the Routing tab makes one of any models you like. The first model answers for what the group can do.

> **Groups you get without doing anything.** Add a second provider that serves a model you already have — Claude Opus from your Claude subscription and from Copilot, DeepSeek from its own API and from OpenRouter — and magpie makes it a group by itself, `auto/<model>` (the model's own id, as in `auto/claude-opus-4.6`; the older `group/auto-…` id still works), over every provider that serves it. The name is matched however each vendor spells it (`deepseek/deepseek-chat`, `deepseek-chat`). Pick it for an agent to spread its requests over all of them; `magpie group rm` hides one you don’t want.

> **One model under the provider's odd id.** Some providers serve a model under an id of their own, `deepseek-v4.1-flash-1017` or `grok-4.6@500k`. Give it the id you want in the provider's editor, under Names, prices & levels, in Listed as beside Same as, then Save; or run `magpie model id relay/grok-4.6@500k grok-4.6`. magpie then lists it, routes it, joins it to the `auto/grok-4.6` group with your other providers' `grok-4.6`, holds gateway keys to it and counts its usage as `grok-4.6`, and still asks the provider for `grok-4.6@500k`. One id is one model of a provider: the last one you give it to has it, and the provider's own model of that id is left out of the list while it does. `magpie model id relay/grok-4.6 --reset` takes it back, and `magpie model ids` lists them. It works for a subscription you signed in to and a plugin's provider too (`magpie model id cursor/deepseek-v41-flash-1017 deepseek-v4.1-flash`): the account or the plugin is still asked for its own id.

| Routing | What goes first |
| --- | --- |
| Smart `smart` | The default. Over the members’ accounts and keys together (a group in the group as one, see below): of the subscriptions with quota to spare, the one whose allowance renews soonest. The week decides; an account with five hours and no week (Claude Enterprise) goes by its five hours, so ahead of every week renewing later. Credits with no reset (WorkBuddy’s packages, each ending on its own day) count as renewing when the soonest of those left run out, so the WorkBuddy account whose credits end first goes first; accounts renewing together (free ones at the month’s end) go by whose credits left end first after that. One resting after a failure goes last. |
| In order `order` | The first model until it can’t answer, then the next. |
| Until used up `drain` | One account or key until it is used up, then the next, which keeps the requests: one before it that renews meanwhile doesn’t take them back. One rate limited or failing is passed over only while it rests. |
| In turn `rotate` | Each conversation’s next turn goes to the next member’s account or key, spreading the load. |
| Least used `usage` | The account or key with the most of its allowance left. |
| Use before expiry `pace` | The account with the most of its week left per hour until it renews — the one with the most to lose at its reset — so less of each member’s week is lost at its reset; an account with five hours and no week (Claude Enterprise) by what its five hours have left per hour until they renew, so almost always first. Credits in an account that expire before it resets count too: those that expire first, per hour until they do, when that is the more (WorkBuddy’s check-in credits). One at 90% or more waits until the others can’t answer. A key by the tokens sent it lately. |
| By weight `weight` | Each model takes its share of the requests by the weight set beside it in the group editor (1 to 1000, 1 if unset): one weighing 3 takes three for every one a model weighing 1 takes, spread out rather than in bursts. Each model is tried whole over its own accounts or keys, as its provider routes them, and a group in the group counts as one. One resting after a failure leaves the round; the next model is the fallback when one fails. |
| Speed first `fast` | The member, account or key that answered this model fastest lately: the time to its first token and how fast it writes, newer answers counting more. Those within a tenth of each other keep their order. One not measured in the last hour gets one request in five, so a channel that was slow once is tried again; one resting after a failure goes last. Only streamed replies are measured, and a restart measures again from scratch. |
| Cheapest first `cheap` | Groups only. The member whose model costs least now, by its price a million tokens in and out at this hour as Usage counts it: your own price for it, else its list price, at the provider’s price rate and rate windows. DeepSeek’s own API, Command Code’s and OpenCode Go’s DeepSeek models cost double in their peak hours (weekdays 01:00–04:00 and 06:00–10:00 UTC), and Ollama Cloud’s DeepSeek V4.1 Flash and V4 Pro in its own (weekdays 12:00–18:00 UTC, half price the rest of the time), so a DeepSeek model listed on two providers goes to the one cheaper at that hour. Members that cost the same keep their order; one with no known price goes last. |

| Stays | How long a conversation stays with the account or key that answered it |
| --- | --- |
| Auto `auto` | The default. Within a turn always, across turns while what the vendor cached of it is worth keeping. |
| Session `session` | The whole session, while it can answer. With Smart, Least used first or Use before expiry, a new session goes to the account or key the fewest other sessions are on, so sessions side by side each keep one of their own. |
| Within a turn `turn` | While the agent sends tool results back; when you speak again, routing decides afresh. |
| Off `off` | Every request is routed afresh. |
| Strict `strict` | Never moves to another account or key, even past its usage cap: when that one is rate limited or out of quota, the error goes to the agent. New conversations are spread as with Session. |

### Rules · a turn to a chosen model

A group’s Rules send a turn to one of its models when the turn is of a kind you name: long (`tokens ≥ N`), carrying an image, asking for reasoning (on, or at least a level), from certain agents, asking for something you describe (an *intent*), the agent compacting its context, or working in one of some folders (a project). A rule’s conditions all have to hold, so one can say “in ~/work/acme, and long”. They are looked at top first when you send a message; the first that matches puts its model first, with the group’s others behind it if it fails. A turn no rule matches is routed as the group always routes, and keeps to where it was.

- A rule decides as a turn begins, and the turn stays on that model while the agent sends tool results back, so what the vendor cached isn’t lost halfway. The one exception: a turn that grows past its model’s context moves to a member that takes it.
- Tokens are estimated from the request’s size, or what the vendor counted for the conversation’s last request, whichever is more. Leave some margin: a rule at 150k for a 200k model, not 199k.
- A subagent is a conversation of its own, so a rule can send it elsewhere while its agent keeps where it is.
- An intent is a few words for what the user asks for — “writing or fixing tests”, “a quick question”. As a turn begins, the group’s classifier — any model magpie has; a small, fast one without reasoning is best — is asked once which of the intents that could match the user’s message is. Only the message is sent, not the conversation. If it fails, exceeds the configured timeout (8 s by default; set in Settings → Models → Replies → Intent classifier timeout) or can’t say, no intent matches and the turn goes by the other rules. It isn’t asked when a rule without an intent would decide anyway, and the same message isn’t asked about twice. Its calls show in Usage as magpie’s own. Exactly what it is asked, how its answer is used and what happens when it fails: [Intent routing](https://usemagpie.ai/docs/intent).
- compacting matches an agent compacting its conversation — Claude Code’s `/compact` and auto-compact, Codex, OpenCode, Pi, Gemini CLI, Qwen Code, Kimi Code — so a cheaper, faster model writes the summary while the conversation stays on its own. A compaction is decided on its own: the turn it happens in, and its cache, stay where they were. When the conversation is longer than the rule’s model takes, the next rule that matches, or the group’s order, decides instead.
- **Hours and days..** A rule can hold only at some hours, on some days, by this computer’s clock — a vendor’s peak hours, say. A rule that sends those turns elsewhere still leaves the vendor’s model behind it for failover. To keep a model out entirely, choose Pause the model instead from the rule’s ⋯ menu: while it holds (its hours and days, its agents), that model is left out of the group — never first, never a fallback, not kept for the conversation it was in — and it is back once they end. A pause holds by hours, days and agents only; if every model of the group is paused, the agent is told so.
- **Folders..** in folder matches a turn from an agent working in one of the folders you list, or a folder inside one: `~/work/acme` takes `~/work/acme/web`, not `~/work/acme-old`. The folder is the one the agent tells its model in the request — Claude Code, Codex, OpenCode and Pi say it — so an agent that doesn’t say its folder matches no folder rule. `~` is your home folder, `C:\work` is also WSL’s `/mnt/c/work`, and on macOS and Windows case doesn’t count.
- **Reasoning..** A rule can also set the reasoning its model is asked for, so an intent picks the model and the effort as a pair: Set its reasoning in the rule’s ⋯ menu, or `use-effort=low` from a terminal. The model is asked for it whatever the agent asked, at the model’s nearest level; a model whose levels magpie doesn’t know, and the models behind it for failover, are asked as the agent asked. See [Intent routing](https://usemagpie.ai/docs/intent#effort).
- The Routing tab says which rule sent each turn where, what the classifier said, and the folder the agent said it was in.

### Groups in groups

A group’s models can include another group: pick it under *Routing groups* in Add a model, or `models+=group/<id>` from a terminal. The group in it takes its place in the order and routes among its own models by its own routing and rules. So Coder can be `deepseek-v4-pro` then *Fast*, and Fast its own order of cheap models. A Coder rule can send a turn to `group/fast`, and Fast’s own rules then pick which of its models goes first.

- **No loops..** A group can’t be in itself, directly or through the groups in it. Saving Fast with Coder in it, while Coder has Fast, is refused, and the picker doesn’t offer such a group. Groups go at most 8 deep. A group can’t be removed while another has it: take it out there first.
- **Each group routes by its own routing..** Whatever the outer group’s routing, it never reaches inside a group in it: Smart, In turn, Least used or Use before expiry weighs the inner group as one member, by the account or key the inner group would try first, and where it lands the inner group is tried whole, in its own order. Coder on Smart with Claude (In order) and GPT (In order) in it compares Claude’s first with GPT’s first, not all of their accounts together.
- **So does a provider routed its own way..** A model whose provider routes its accounts or keys In order, In turn, by Least used, Use before expiry or Weight keeps that inside any group, weighed as one by the account or key it would try first and tried whole in its own order. One left on Smart, the default, has its accounts weighed with the group’s others as one pool, so the one whose allowance renews soonest goes first whichever provider it is of.
- **Failover goes through..** If every model in the inner group fails, the outer group’s next member answers, as with any member.
- A model that appears twice (on its own and in a group in it) is asked once, at its first place.

The Routing tab shows the gateway’s decisions live: who answered each request, and why. The same groups from a terminal:

```
magpie groups                        # yours, then those magpie found
magpie group add "Opus anywhere" models=claude/claude-opus-5-5,copilot/claude-opus-5.5 routing=order stays=session
magpie group set opus-anywhere models+=openrouter/anthropic/claude-opus-5.5
magpie group set opus-anywhere routing=weight weight=claude/claude-opus-5-5=3  # three of every four requests to it
magpie group rule add opus-anywhere use=openrouter/anthropic/claude-opus-5.5 tokens=150k  # long turns to it first
magpie group rule add opus-anywhere use=copilot/claude-opus-5.5 intent="a quick question" classifier=groq/llama-3.1-8b-instant
magpie group rule add opus-anywhere use=deepseek/deepseek-v4-flash compact  # /compact summaries to a cheap model
magpie group rule add opus-anywhere use=kimi/kimi-k2.6 folders=~/oss,"~/My Project"  # turns in those projects to it first
magpie group rule add opus-anywhere pause=copilot/claude-opus-5.5 time=14:00-18:00 days=mon-fri  # left out in those hours
magpie group rule add opus-anywhere pause=claude/claude-opus-5-5 except-folders=~/big-task  # the model kept for the task in ~/big-task: left out of every other folder
magpie group set coder models+=group/opus-anywhere  # a group in a group
magpie group rule opus-anywhere      # its rules; rule rm|mv <n>, rule classifier <group> <model>
magpie group copy opus-anywhere "Opus test"  # the same models, routing and rules, to change on its own
magpie group rm opus-anywhere        # one magpie found is hidden; magpie group restore <id>
magpie claude group/opus-anywhere    # use it
```

## Usage and profiles

**Usage.** The Usage tab counts tokens, cache hits and cost for each agent and model, from every call through the gateway, for Today, 7 days, 30 days or All; your subscriptions’ allowance used, and when it resets, sits on top. Calls an agent makes to its own vendor directly don’t pass through magpie and aren’t counted.

**Context.** Usage’s Context tab shows what each agent’s prompts hold, read as they pass through the gateway: its system prompt, tool definitions (an MCP server’s as one), instruction files and skills, the files its tools read, their other output and the conversation, as parts of the model’s context window. Each agent gets a score out of 100 — how much of its prompt the cache reads, how lean it starts, how fast it fills and how often it fails — and tags such as *Lean start* or *MCP-heavy* that say what the score was told by. Open a session to see its latest request’s window, cell by cell; the Routing page shows the same for any request you pick. Click a part, a cell or an item to read its text as magpie sent it, masked where masking is on. That text is kept for the last 10 requests only, in memory while magpie runs; what is saved keeps names only, never your prompt’s text, and nothing of it is sent anywhere.

**Profiles.** At the bottom of the Agents tab, ＋ Save current snapshots every agent’s settings under a name; click the chip to switch everything back in one move. The profile in use is ticked, and the tray panel’s Profiles button shows its name; a setting changed by hand since clears the tick.

## From the terminal

`magpie tui` is the whole app in a terminal, and every step above has a command. `magpie help` lists them all.

| Command | Does |
| --- | --- |
| `magpie ls` | Every agent found and its settings |
| `magpie presets` | The vendors magpie knows |
| `magpie provider add deepseek sk-…` | Add a preset with its key |
| `magpie accounts add codex` | Sign in to one more Claude or ChatGPT subscription |
| `magpie accounts switch claude next` | Sign Claude Code (or `codex`) in to the next of your accounts that has room, or the one with the most left when none has |
| `magpie accounts discovery off` | Never read your agents’ sign-ins (Claude Code’s and Codex’s files, the Keychain); `on` reads them again |
| `magpie providers` | Your providers: host, key, models, who uses them |
| `magpie models` | Every model agents can pick, as `provider/model` |
| `magpie claude codex/gpt-5.5` | Set an agent’s model |
| `claude-magpie` | Claude Code through magpie for one session, a plain `claude` left on your account (`magpie claude run`; `magpie claude launcher add` puts it on PATH) |
| `magpie codex effort high` | Set another field |
| `magpie codex default` | Back to the agent’s own default, magpie’s wiring removed |
| `magpie save work` · `use work` | Save and apply a profile |
| `magpie usage 7d` | Tokens and cost per agent and model |
| `magpie tools` · `magpie tool generate_image "…" -o hero.png` | The tools magpie gives agents over MCP (image generation, image recognition, web search, plugins’), listed and called directly; an image it makes is saved |
| `magpie tray` | Start with the menu bar icon only |
| `magpie log` · `magpie log -f` | Where magpie’s logs are, to send with a report; `-n 200` prints the app log’s last lines, `-f` follows it |

## FAQ

### Do I need to export `OPENAI_BASE_URL` or `ANTHROPIC_BASE_URL`?

No. For the agents magpie lists, it writes the gateway’s address and token into the agent’s own config file. Those variables are only for other tools with a base-URL setting: the Gateway tab’s Connect section has them as copy buttons and snippets.

### Does magpie have to be running?

For a model through magpie, yes: the gateway runs with the app. Closing the window leaves it running in the menu bar or tray; `magpie tray` starts the icon alone (put it in your login items), and `magpie serve` runs just the gateway, and `magpie daemon install` keeps it running as a service (systemd on Linux, launchd on the Mac), from login or boot, with no window; `magpie daemon install --web` has it serve the browser page too, and `magpie daemon status` prints the page’s link. An agent on its own model and its own sign-in doesn’t go through magpie.

### How do I put an agent back the way it was?

Pick one of the agent’s own models in the picker, or run `magpie <agent> default`. magpie removes what it wrote and restores the values it replaced, such as an `ANTHROPIC_BASE_URL` you had before.

### I switched models, but my agent still uses the old one.

A running session keeps what it started with. Start a new one; for Codex, restart the Codex app too.

### Does editing the agent’s config by hand break anything?

No. magpie reads the files each time and touches only the keys it sets, so your other settings and comments stay. Providers brought over with Import… are copies: later changes in the agent’s settings aren’t copied again.

### Installing or updating behind a firewall, or without access to GitHub?

Give the installer and `magpie update` a proxy: `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --proxy http://127.0.0.1:7890`, or `magpie update --proxy socks5://127.0.0.1:1080` (http, https, socks5 and socks5h; `HTTPS_PROXY` and `ALL_PROXY` are honoured too). Release files come from usemagpie.ai (Cloudflare R2), and from github.com when that fails. `--mirror <prefix>` fetches the release file from a GitHub download mirror you choose, as `<prefix>https://github.com/…`, when the site’s copy fails; `magpie update mirror <prefix>` keeps it for every update, the app’s too, and `magpie update mirror off` removes it. No mirror is used unless you give one, and the file’s SHA-256 still comes from usemagpie.ai, never from the mirror: a file the mirror changed is refused. The app’s own updates go through Settings → Proxy.

### Which build does the installer put on Linux?

The desktop app (window, tray icon and a menu entry) when GTK 3 and WebKitGTK 4.1 are installed. On a computer with a desktop but without them, the installer installs WebKitGTK 4.1 with your package manager (apt, dnf, pacman or zypper), through `sudo`, which asks for your password, and then the app; it says what it installs before it asks. Run without a terminal (CI, a Dockerfile), without `sudo`, on another distribution or when that install fails, it installs the terminal build (`magpie tui`, `magpie web` and the CLI) and ends with the command that installs them, such as `sudo apt install libwebkit2gtk-4.1-0` on Debian and Ubuntu or `sudo dnf install webkit2gtk4.1` on Fedora; run the installer again afterwards for the app. A desktop counts whether you run it there or over ssh: a graphical session, your graphical login, or a desktop installed to log in to. A server without one gets the terminal build. To choose yourself, add `--gui` (the app even when its libraries can't be installed now) or `--tui` (the terminal build, and no package installed): `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --tui`.

### How do I uninstall magpie?

Installed with the script: `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall` has magpie disconnect every agent and put back what each had first, then takes off what the script put there: the `magpie` command, and the app on macOS or its menu entry, icon and `magpie://` handler on Linux, with magpie’s service and opening at login there, which would start a magpie that is gone. Your settings, providers and usage in `~/.config/magpie` stay, for when you install again. Add `--purge` to delete them too (`magpie uninstall --yes`). Installed another way, `magpie uninstall` or Settings → Uninstall magpie does what `--purge` does and leaves the program itself for you to delete.

Deleted magpie already (the app in the Trash, the folder removed) and an agent still says it can’t connect? On macOS and Linux run the same `--uninstall` line: with no magpie left it downloads the newest to a temporary folder, checked like an install, and that one puts your agents back while magpie’s record of what each had is still in `~/.config/magpie`. On Windows, download magpie again and use Settings → Uninstall magpie. To put Codex back by hand, quit it, then in `~/.codex/config.toml` delete each line under a `# magpie:` comment (`openai_base_url`, `model_provider = "magpie"`, `model_catalog_json`) and set `model` to one of Codex’s own; the `[model_providers.magpie]` table can go too once no thread you keep was started on magpie. Delete `~/.codex/magpie-models.json`, and open Codex again.

### Can magpie keep its files on another disk, so reinstalling the system doesn’t lose them?

Installed, magpie keeps its settings, providers, usage and library in `~/.config/magpie` (`C:\Users\<you>\.config\magpie` on Windows). It backs them up by itself once a day, into `auto-backups` in that same folder, so a reinstalled system loses the backups too; Settings → Sync and backup says so under Backup folder. Click Change… there and pick a folder on another disk (`D:\magpie-backups`) or one a cloud drive syncs. After a reinstall, install magpie, pick the same folder there and Restore… the newest version. Backups hold no API keys; Sign-ins in backups adds subscription accounts and plugin sign-ins, sealed with a passphrase. To carry the keys too, sync to a WebDAV folder, an S3 bucket or a GitHub repository, sealed with a passphrase, in the same place.

To keep everything on that disk, run magpie portable: put `magpie.exe` in a folder there with an empty folder named `data` beside it (`D:\magpie\magpie.exe` and `D:\magpie\data`). magpie then keeps everything in `data`, its caches and log too, and writes nothing of its own to your user folder; Settings → About → Config folder says Portable. Open it, and restore a backup into it as above. After a reinstall, open `D:\magpie\magpie.exe` again. The agents’ own configs (`~/.claude`, `~/.codex`…) stay where each agent reads them.

### Where is magpie’s log?

The app (its window, the menu bar or tray icon and the panel, however it was opened) writes `app.log`: `~/Library/Logs/magpie/app.log` on macOS, `%LOCALAPPDATA%\magpie\logs\app.log` on Windows, `~/.local/state/magpie/app.log` on Linux (`$XDG_STATE_HOME/magpie` when that is set), and `logs` in a portable magpie’s data folder. Settings → About → Log has its path and an Open that shows its folder; `magpie log` prints it, and `magpie log -f` follows it. At 5 MiB it becomes `app.old.log` beside it, so two files at most are kept. It holds what magpie did and the errors it met (a provider refusing a request, a retry, a plugin that failed to start), not your keys, prompts or replies; what looks like a key or token is masked anyway. `magpie serve` run as a service logs elsewhere: `~/Library/Logs/magpie/serve.log` on macOS, `journalctl --user -u magpie` on Linux; `magpie log` names it too.

### What does magpie send about me?

Your prompts, replies, keys and accounts go only to the providers you use; magpie has no server of its own in the path. Once a day a released magpie tells us it is in use, so we know how many people use it and what to look after first: a random id made up on your computer, magpie’s version and your system, and which agents, providers and models it is used with, by magpie’s own ids (`claude`, `deepseek`, `deepseek/deepseek-v4`) with how many of each. A provider you added yourself, and a model on it, is only `custom`. For each partner listed first in the add sheet, how many times a day it was shown, opened and added from goes with them, as counts only. No names, base URLs, accounts, keys, prompts or usage are sent. Settings → Privacy → Share the agents, providers and models I use leaves out the agents, providers and models, and the partner counts; Count me as a user, `DO_NOT_TRACK=1` or `MAGPIE_NO_STATS=1` turns it all off. Builds from source never send it. A partner's website and key-page links go through `usemagpie.ai/go/…`, which counts the click (the partner, which link, and a country) before sending you on, and usemagpie.ai counts how many times the partner list is fetched. The server sees these whatever the settings say, as any website sees its visits; no id, address or account is kept with them. Icons named by a plugin, an import link or the library are fetched through `usemagpie.ai/api/icon`, so their hosts see Cloudflare's address, not yours; the server only passes the picture on, and counts and keeps nothing. The [Privacy page](https://usemagpie.ai/docs/privacy) lists everything magpie sends by itself, with an example of the daily count, the files it keeps and every switch.

### The agent gets 502 or can’t connect, and nothing shows in magpie’s Routing tab?

A proxy app (Surge, Clash, mihomo and the like, with system proxy, TUN or enhanced mode on) has taken the agent’s request to `http://127.0.0.1:3425` and sent it somewhere else, so it never reaches magpie. The bypass list (`skip-proxy`, “bypass”) isn’t always enough: some agents, Codex among them, send it through the proxy anyway. Add rules that send the local addresses direct, ahead of your other rules:

```
IP-CIDR,127.0.0.0/8,DIRECT,no-resolve
IP-CIDR6,::1/128,DIRECT,no-resolve
```

In a Clash or mihomo config the same lines go under `rules:`, each starting with `- `. Then send the agent a new request.

### Can DeepSeek Harness keep its own DeepSeek row and go through magpie?

Yes, by hand. Connecting dsh adds magpie’s routes and leaves dsh’s DeepSeek row (`llm-deepseek`) to dsh. That row keeps DeepSeek’s cache when dsh’s prompt or tools change mid-session. To send it through magpie, add this to `~/.dsh/profiles/<profile>/cordis.patch.yml`:

```
- id: llm-deepseek
  config:
    baseURL: http://127.0.0.1:3425
    apiKeyEnv: MAGPIE_DS_KEY
    maxInlineRequestImageBytes: 67108864
    models:
      - id: deepseek/deepseek-flash
        name: DeepSeek V4.1 Flash (magpie)
        contextWindow: 1000000
        inputModalities: [text, image]
        systemPromptUpdate: in-history
        toolUpdate: addition-only
      - id: deepseek/deepseek-v4-pro
        name: DeepSeek V4 Pro (magpie)
        contextWindow: 1000000
```

`baseURL` has no `/anthropic`. The model ids are magpie’s (`magpie models`), and a `models` list replaces dsh’s defaults, so keep the two update lines. `MAGPIE_DS_KEY` holds the gateway key (`magpie` on this computer), not your DeepSeek key: export it, put it in `~/.dsh/.env`, or enter it on the DeepSeek row in dsh’s Models page. Pick the model in dsh; Disconnect leaves the entry alone. magpie has no Files API, so dsh sends images inline as base64 each turn, up to `maxInlineRequestImageBytes` (20 MiB by default, 64 MiB above). Keep the row on DeepSeek’s own models. [More in the reference](https://github.com/yetone/magpie/blob/main/docs/reference.md#deepseek-harness-the-deepseek-row-by-hand).

### Can Trae or Trae CN use magpie’s models?

Users report that this works. Trae keeps custom models in your Trae account, on its servers, so magpie can’t set it up for you, and Trae may not reach `127.0.0.1`. So:

1. In magpie, turn on Settings → Network and sharing → Share on local network, and note the Address it shows.
2. Take a gateway key (Gateway → Gateway keys, or `magpie gateway-key add "Trae"`).
3. In Trae’s custom model settings, enter that address as the address and the gateway key as the API key.

The model id is magpie’s (`magpie models`). Sharing lets other computers on your network in with a gateway key; see [Remote magpie](https://usemagpie.ai/docs/remote#share).

Stuck, or have a setup worth sharing? Ask on [Discord](https://discord.gg/vGSnD3ZKQF). Vendors who want to hand their users a ready-made provider: see [Add to magpie](https://usemagpie.ai/docs/import).

---

Source: https://usemagpie.ai/docs/claude-code-models

# Use DeepSeek, Kimi, GLM, Qwen or any model in Claude Code

Claude Code speaks one API, Anthropic Messages. magpie puts a gateway on your computer that speaks it for every provider you add, and points Claude Code at it. You pick the model in magpie or in Claude Code’s `/model`.

The gateway runs at `127.0.0.1:3425`. It speaks the Anthropic, OpenAI and Gemini APIs. When a provider speaks Anthropic Messages itself, as DeepSeek, Kimi, Zhipu GLM, MiniMax and Qwen do, Claude Code’s request is passed on as it is. When it doesn’t, as with a GPT model from your ChatGPT plan, magpie translates the request and the reply, streaming and tool calls included.

### Chinese models

DeepSeek, Kimi and Kimi Code, Zhipu GLM (pay as you go or Coding Plan), Z.ai, MiniMax and Qwen, each with its China endpoint where it has one.

### Subscriptions

The models of a ChatGPT, Copilot or Antigravity account you sign in to in magpie.

### Anything else

Any OpenAI- or Anthropic-compatible URL and key, Ollama and LM Studio.

## Set it up

1. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick DeepSeek, Kimi, Zhipu GLM, MiniMax or Qwen, paste your API key and save. magpie asks the vendor which models it serves.
2. **Pick the model for Claude Code.** In the Agents tab, click the model on the Claude Code row and choose one, such as `deepseek/deepseek-v4-pro`. magpie writes it into `~/.claude/settings.json`.
3. **Start a new session.** Claude Code reads its settings when it starts. A session already open keeps the model it started with.

The same from a terminal:

```
magpie provider add deepseek sk-…
magpie models                       # every model, as provider/model
magpie claude deepseek/deepseek-v4-pro
```

Model ids are magpie’s, `provider/model`. Inside Claude Code, `/model` lists magpie’s models too, marked “via magpie”, so you can switch there.

> **Zhipu GLM Coding Plan.** When you add Zhipu GLM or Z.ai, pick the plan your key is for. A Coding Plan key has its own endpoints, and sent to the pay-as-you-go one it is told it has no balance.

> **Keep `claude` on your own account.** Leave Claude Code unconnected in magpie and run `claude-magpie` when you want it on another model. It starts the same `claude` with magpie’s settings for that session only, and `settings.json` is not rewritten. See [Get started](https://usemagpie.ai/docs/start#agents).

## How Opus, Sonnet and Haiku map

Claude Code asks for models by tier: `opus`, `sonnet`, `haiku` and `fable`. Its own small jobs, such as a session’s title and Explore subagents, go to the haiku tier. magpie writes a model into each tier’s variable:

| Tier | Variable in `env` | By default |
| --- | --- | --- |
| opus | `ANTHROPIC_DEFAULT_OPUS_MODEL` | The main model |
| sonnet | `ANTHROPIC_DEFAULT_SONNET_MODEL` | The main model |
| haiku | `ANTHROPIC_DEFAULT_HAIKU_MODEL`, `ANTHROPIC_SMALL_FAST_MODEL` | The main model; on a Claude model, the Haiku its provider serves |
| fable | `ANTHROPIC_DEFAULT_FABLE_MODEL` | Left unset unless the main model is a Fable model |

So with DeepSeek as the main model, every tier runs on DeepSeek. To give a tier a model of its own, say a cheaper one for haiku, set it on the Claude Code row in magpie, or from a terminal:

```
magpie claude haiku deepseek/deepseek-v4-flash   # one tier on its own model
magpie claude haiku ""                           # back to the main model
```

A tier takes a model through magpie, and only once the main model is one.

## What changes in settings.json

Claude Code reads its endpoint from the `env` block of `~/.claude/settings.json`. magpie changes only the keys it needs there. Comments and your other settings stay.

| Key | Set to |
| --- | --- |
| `env.ANTHROPIC_BASE_URL` | The gateway’s address |
| `env.ANTHROPIC_AUTH_TOKEN` | The gateway’s key (not your vendor key; that stays in magpie) |
| `model` | The main model |
| `env.ANTHROPIC_DEFAULT_*_MODEL`, `env.ANTHROPIC_SMALL_FAST_MODEL` | The tiers, as above |
| `env.CLAUDE_CODE_MAX_OUTPUT_TOKENS` | The longest reply the model can write. Claude Code asks a model it doesn’t know for 32000 at most |
| `env.CLAUDE_CODE_MAX_CONTEXT_TOKENS`, `env.CLAUDE_CODE_AUTO_COMPACT_WINDOW` | Where needed, the model’s window and where to compact. Claude Code takes a model it doesn’t know for 200K. A 1M model is marked `[1m]` |
| `modelPicker` | magpie’s models, for `/model`. A picker you wrote yourself is left alone |

A value you set yourself, such as your own output limit, stays yours. `ANTHROPIC_MODEL` is taken out, because it would outrank a pick in `/model`. A cloud switch in that file, such as `CLAUDE_CODE_USE_BEDROCK`, is set aside while Claude Code runs through magpie and put back afterwards.

### Going back to Claude’s own models

Pick one of Claude Code’s own models on its row, or run `magpie claude default`. magpie takes out what it wrote and puts back what it replaced the first time: your own base URL, token and tier models. You don’t edit the file by hand.

## GPT models from a ChatGPT or Copilot subscription

Sign in to the subscription in magpie: ＋ Add provider, then the ChatGPT or Copilot tile. magpie opens the vendor’s own sign-in page. The account’s models then show in Claude Code’s picker as `codex/…` or `copilot/…`.

```
magpie accounts add codex      # sign in to a ChatGPT account
magpie claude codex/gpt-5.5
```

Claude Code still speaks Anthropic Messages. magpie translates each request for the GPT model and the reply back, tool calls included. Antigravity accounts work the same way, as `antigravity/…`.

## Routing over several keys

With several keys or accounts, magpie can spread Claude Code’s requests over them and move on when one runs out.

- **Several keys for one vendor..** Add them all to the provider and tick each one. Routing on the provider says how requests spread, and Fallback lists models to use when it is out of quota or down.
- **One model from several providers..** When two of your providers serve the same model, such as DeepSeek from its own API and from a relay, magpie makes the group `auto/<model>` by itself. Pick it for Claude Code.
- **Your own group..** New group in the Routing tab puts any models behind one name, `group/<id>`.

The routing modes are in [Get started](https://usemagpie.ai/docs/start#routing).

**By provider:** [DeepSeek](https://usemagpie.ai/docs/deepseek) · [Kimi and Kimi Code](https://usemagpie.ai/docs/kimi) · [GLM Coding Plan](https://usemagpie.ai/docs/glm) · [Qwen](https://usemagpie.ai/docs/qwen) · [MiniMax](https://usemagpie.ai/docs/minimax)

## FAQ

### Do I set `ANTHROPIC_BASE_URL` myself?

No. magpie writes it into Claude Code’s `settings.json`. If `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX` or another cloud switch is set in your shell’s environment, Claude Code sends its requests to that cloud and not to magpie; magpie tells you so, and you take it out of your shell profile.

### Can I switch models inside Claude Code?

Yes. While Claude Code runs through magpie, `/model` lists magpie’s models and routing groups, and a pick there persists.

### Which Chinese models can Claude Code use?

Any that a provider you add serves. magpie has presets for DeepSeek, Kimi, Kimi Code, Zhipu GLM, Z.ai, MiniMax and Qwen, with China endpoints for Kimi, Kimi Code, MiniMax and Qwen. Others can be added as a custom URL.

### Does magpie have to be running?

Yes, while Claude Code is on a model through magpie: the gateway runs with the app. `magpie daemon install` keeps it running as a service with no window.

### Can I keep my claude.ai sign-in?

The Claude Code row has a sign-in setting. With magpie’s key, the default, Claude Code is signed out of claude.ai while it runs through magpie, so the plan limits in `/usage`, connectors, voice and `/teleport` are off. With claude.ai it keeps its sign-in, which magpie never passes on. Remote Control and ultrareview stay off either way.

### Can I use my Claude subscription and DeepSeek side by side?

Yes. Sign in to Claude in magpie and its models are `claude/…` in the same picker. Requests on a Claude subscription run through the Claude Code installed on your computer.

### How do I undo it?

Pick one of Claude Code’s own models in magpie, or run `magpie claude default`. What magpie wrote comes out, and what it replaced comes back.

Using Codex too? See [Use any model in Codex](https://usemagpie.ai/docs/codex-models). Stuck? Ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/codex-models

# Use DeepSeek, Kimi, GLM, Claude or any model in Codex

Codex speaks one API, OpenAI Responses. magpie puts a gateway on your computer that speaks it for every provider you add, and writes Codex’s `config.toml` for you. The models then show in Codex’s `/model`, with their reasoning efforts.

The gateway runs at `127.0.0.1:3425`. When a provider serves the Responses API itself, as DeepSeek and the Zhipu GLM Coding Plan do, Codex’s request is passed on as it is. When it serves only Chat Completions or Anthropic Messages, as Kimi, MiniMax and Qwen do, or a Claude subscription, magpie translates the request and the reply, streaming and tool calls included.

### Chinese models

DeepSeek, Kimi and Kimi Code, Zhipu GLM (pay as you go or Coding Plan), Z.ai, MiniMax and Qwen, each with its China endpoint where it has one.

### Claude

Your Claude subscription’s models, or an Anthropic key’s.

### Anything else

Any OpenAI- or Anthropic-compatible URL and key, Copilot and Antigravity accounts, Ollama and LM Studio.

## Set it up

1. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick DeepSeek, Kimi, Zhipu GLM, MiniMax or Qwen, paste your API key and save. magpie asks the vendor which models it serves.
2. **Pick the model for Codex.** In the Agents tab, click the model on the Codex row and choose one, such as `deepseek/deepseek-v4-pro`. The effort slider under the list sets its reasoning effort. magpie writes both into `~/.codex/config.toml`.
3. **Restart Codex.** Codex builds its model list when it starts. Restart the Codex app, and open new `codex` sessions, after a switch.

The same from a terminal:

```
magpie provider add deepseek sk-…
magpie models                        # every model, as provider/model
magpie codex deepseek/deepseek-v4-pro
magpie codex effort high
```

> **Zhipu GLM Coding Plan.** When you add Zhipu GLM or Z.ai, pick the plan your key is for. A Coding Plan key has its own endpoints, and sent to the pay-as-you-go one it is told it has no balance.

## The models in Codex’s /model

magpie’s models are listed in Codex’s `/model` beside its own, so you can switch there too. Each one carries what Codex needs to run it: its reasoning efforts and default effort, its context window and the base instructions Codex sends with it.

How they get there depends on how Codex is signed in:

- **Signed in to ChatGPT..** Codex keeps its own OpenAI provider and your sign-in. magpie points it at the gateway with `openai_base_url`; Codex’s own models still go to OpenAI on your account, and magpie’s models join them in `/model`.
- **Not signed in, or signed in with an API key..** magpie becomes Codex’s provider, and the list comes from a catalog file magpie writes, `magpie-models.json` beside `config.toml`.

## What changes in config.toml

magpie changes only the keys it needs in `~/.codex/config.toml`. Comments, ordering and your other settings stay.

| Key | Set to |
| --- | --- |
| `model` | The model you picked |
| `model_reasoning_effort` | The effort, when you set one |
| `openai_base_url` | The gateway’s address. A base URL of your own stays |
| `model_provider` | `"magpie"`, when magpie is the provider |
| `model_catalog_json` | The path of the catalog file, `magpie-models.json`, when magpie is the provider |
| `[model_providers.magpie]` | `name`, `base_url` (the gateway’s `/v1`), `wire_api = "responses"`, and the gateway’s key. Your vendor keys stay in magpie |

```
model = "deepseek/deepseek-v4-pro"
model_provider = "magpie"
model_catalog_json = "/Users/you/.codex/magpie-models.json"

[model_providers.magpie]
name = "magpie"
base_url = "http://127.0.0.1:3425/v1"
wire_api = "responses"
```

That is the shape when magpie is the provider; the table also carries the gateway’s key and a header. Signed in to ChatGPT, only `openai_base_url` and `model` are set at the top. The `[model_providers.magpie]` table stays once written. A Codex thread keeps the provider it was started on, and a thread started on magpie can’t be opened again without it.

### Going back to OpenAI’s models

Pick one of Codex’s own models on its row, or run `magpie codex default`. magpie takes `model_provider`, `model_catalog_json` and the base URL back out and puts back the provider and model you had. A provider of your own at the top stays. Threads started on magpie are moved back to the provider Codex is on, so Codex lists them, and a copy is kept in magpie’s trash.

## Claude in Codex

Sign in to your Claude subscription in magpie: ＋ Add provider, then the Claude tile. Its models are `claude/…` in Codex’s picker. magpie translates Codex’s Responses requests into Anthropic Messages and the replies back.

```
magpie accounts add claude     # sign in to a Claude account
magpie models | grep '^claude/'
magpie codex claude/…
```

Requests on a Claude subscription run through the Claude Code installed on your computer, so keep it installed. An Anthropic API key works too: add Anthropic as a vendor and pick an `anthropic/…` model.

## Routing over several keys

- **Several keys for one vendor..** Add them all to the provider and tick each one. Routing on the provider says how requests spread, and Fallback lists models to use when it is out of quota or down.
- **One model from several providers..** When two of your providers serve the same model, magpie makes the group `auto/<model>` by itself. Pick it for Codex.
- **Your own group..** New group in the Routing tab puts any models behind one name, `group/<id>`.

The routing modes are in [Get started](https://usemagpie.ai/docs/start#routing).

**By provider:** [DeepSeek](https://usemagpie.ai/docs/deepseek) · [Kimi and Kimi Code](https://usemagpie.ai/docs/kimi) · [GLM Coding Plan](https://usemagpie.ai/docs/glm) · [Qwen](https://usemagpie.ai/docs/qwen) · [MiniMax](https://usemagpie.ai/docs/minimax)

## FAQ

### Do I write `[model_providers]` myself?

No. magpie writes Codex’s `config.toml` when you pick a model. You don’t export `OPENAI_BASE_URL` either.

### Does my ChatGPT sign-in still work?

Yes. Signed in to ChatGPT, Codex keeps its own provider and sign-in. Its own models go to OpenAI on your account, and magpie’s are added beside them.

### I picked a model, but Codex’s /model doesn’t show it.

Codex reads its model list when it starts. Restart the Codex app and open a new `codex` session.

### Can I set the reasoning effort?

Yes, on the Codex row’s effort slider, with `magpie codex effort high`, or in Codex’s `/model`, which lists each model’s efforts.

### Which Chinese models can Codex use?

Any that a provider you add serves. magpie has presets for DeepSeek, Kimi, Kimi Code, Zhipu GLM, Z.ai, MiniMax and Qwen. Others can be added as a custom URL.

### Does magpie have to be running?

Yes, while Codex is on a model through magpie: the gateway runs with the app. `magpie daemon install` keeps it running as a service with no window.

### How do I undo it?

Pick one of Codex’s own models in magpie, or run `magpie codex default`. magpie’s keys come out, and your provider and model come back.

Using Claude Code too? See [Use any model in Claude Code](https://usemagpie.ai/docs/claude-code-models). Stuck? Ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/gemini-cli-models

# Use DeepSeek, Kimi, GLM, Claude or GPT in Gemini CLI

Gemini CLI speaks only Google’s Gemini API. magpie puts a gateway on your computer that serves the Gemini API for every provider you add, and points Gemini CLI at it. You pick the model on Gemini CLI’s row in magpie.

The gateway runs at `127.0.0.1:3425`. It serves the Gemini API’s `generateContent`, `streamGenerateContent` and `countTokens` calls and its model list, beside the OpenAI and Anthropic APIs. A request goes straight through when the provider speaks the Gemini API, and is translated when it doesn’t, as with DeepSeek, Kimi, Zhipu GLM or a Claude or ChatGPT subscription: the request and the reply, streaming, tool calls, images and reasoning included.

### Chinese models

DeepSeek, Kimi and Kimi Code, Zhipu GLM (pay as you go or Coding Plan), Z.ai, MiniMax and Qwen.

### Subscriptions

The models of a Claude, ChatGPT, Copilot or Antigravity account you sign in to in magpie.

### Anything else

Any OpenAI- or Anthropic-compatible URL and key, Ollama and LM Studio.

## Set it up

1. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick DeepSeek, Kimi, Zhipu GLM, MiniMax or Qwen, paste your API key and save. magpie asks the vendor which models it serves.
2. **Pick the model for Gemini CLI.** In the Agents tab, click the model on the Gemini CLI row and choose one, such as `deepseek/deepseek-v4-pro`. magpie writes it into `~/.gemini/settings.json` and the gateway’s address into `~/.gemini/.env`.
3. **Restart gemini.** Gemini CLI reads its settings when it starts. A session already open keeps what it started with.

The same from a terminal:

```
magpie provider add deepseek sk-…
magpie models                              # every model, as provider/model
magpie gemini model deepseek/deepseek-v4-pro
```

Model ids are magpie’s, `provider/model`. The Gemini CLI row shows once the `gemini` command is on your `PATH`.

> **Zhipu GLM Coding Plan.** When you add Zhipu GLM or Z.ai, pick the plan your key is for. A Coding Plan key has its own endpoints, and sent to the pay-as-you-go one it is told it has no balance.

## What changes in ~/.gemini

Gemini CLI loads `~/.gemini/.env` and reads `~/.gemini/settings.json`. magpie changes four keys across the two:

| File | Key | Set to |
| --- | --- | --- |
| `.env` | `GOOGLE_GEMINI_BASE_URL` | The gateway’s address |
| `.env` | `GEMINI_API_KEY` | The gateway’s key (not your vendor key; that stays in magpie) |
| `settings.json` | `security.auth.selectedType` | `gemini-api-key`, so Gemini CLI sends that key and not a Google sign-in |
| `settings.json` | `model.name` | The model, as `provider/model` |

The first time, magpie keeps what those keys held before: your own base URL, API key, sign-in choice and model. If the sign-in choice is changed to anything but the API key while the model is one of magpie’s, Gemini CLI asks Google directly, and magpie’s Gemini CLI row says so.

### Going back to Google

Pick one of Gemini CLI’s own Gemini models on its row, or run `magpie gemini default`. magpie takes `GOOGLE_GEMINI_BASE_URL` and `GEMINI_API_KEY` out of `.env` and puts back the base URL, key, sign-in choice and model you had. You don’t edit either file by hand.

The row’s auth setting chooses how Gemini CLI signs in on its own: Google (your Google account), API key or Vertex AI. With Google Gemini added as a provider in magpie, API key writes that key into `.env` for Gemini CLI.

```
magpie gemini default   # magpie’s wiring out, what you had back
magpie gemini google    # sign in with your Google account
```

## Claude and GPT models from a subscription

Sign in to the subscription in magpie: ＋ Add provider, then the Claude, ChatGPT or Copilot tile. magpie opens the vendor’s own sign-in page. The account’s models are then `claude/…`, `codex/…` or `copilot/…` on Gemini CLI’s row.

```
magpie accounts add codex           # sign in to a ChatGPT account
magpie gemini model codex/gpt-5.5
```

Gemini CLI still speaks the Gemini API; magpie translates each request for the model and the reply back. Requests on a Claude subscription run through the Claude Code installed on your computer, so keep it installed. More in [Use your subscription in any agent](https://usemagpie.ai/docs/subscriptions).

## Routing over several keys

- **Several keys for one vendor..** Add them all to the provider and tick each one. Routing on the provider says how requests spread, and Fallback lists models to use when it is out of quota or down.
- **One model from several providers..** When two of your providers serve the same model, magpie makes the group `auto/<model>` by itself. Pick it for Gemini CLI.
- **A cheaper model for compaction..** A routing group’s compacting rule matches Gemini CLI compacting its conversation, so a cheaper, faster model can write the summary.

The routing modes and rules are in [Get started](https://usemagpie.ai/docs/start#routing).

**By provider:** [DeepSeek](https://usemagpie.ai/docs/deepseek) · [Kimi and Kimi Code](https://usemagpie.ai/docs/kimi) · [GLM Coding Plan](https://usemagpie.ai/docs/glm) · [Qwen](https://usemagpie.ai/docs/qwen) · [MiniMax](https://usemagpie.ai/docs/minimax)

## FAQ

### Can Gemini CLI use models that aren’t Gemini?

Yes, through a gateway that serves the Gemini API. magpie runs one on your computer and points Gemini CLI at it, so any model of a provider you add works: DeepSeek, Kimi, GLM, Qwen, MiniMax, or a Claude, ChatGPT or Copilot subscription.

### Do I set `GOOGLE_GEMINI_BASE_URL` myself?

No. magpie writes it and `GEMINI_API_KEY` into `~/.gemini/.env`, and sets Gemini CLI to API-key auth in `~/.gemini/settings.json`. What you had there before is kept and comes back when you switch away.

### Why does Gemini CLI still send requests to Google?

Its sign-in choice is not the API key: with a Google sign-in or Vertex AI, Gemini CLI asks Google directly. Pick the model again in magpie, which sets it back to the API key; magpie’s Gemini CLI row tells you when this happens. Restart open `gemini` sessions after a change.

### Can I use my ChatGPT or Claude subscription in Gemini CLI?

Yes. Sign in to it in magpie and pick a `codex/…` or `claude/…` model on Gemini CLI’s row. Requests on a Claude subscription run through the Claude Code installed on your computer.

### Why doesn’t magpie show Gemini CLI?

magpie shows it when the `gemini` command is on your `PATH`. A `~/.gemini` folder alone doesn’t count, because it stays after Gemini CLI is uninstalled and Antigravity keeps folders there too.

### Does it work for Gemini CLI in WSL?

Yes. magpie sets up Gemini CLI inside a WSL distro the same way, writing the gateway’s address as that distro reaches it.

### How do I switch Gemini CLI back to Google?

Pick one of Gemini CLI’s own models in magpie, or run `magpie gemini default`. What magpie wrote comes out, and your own key, sign-in choice and model come back.

Using Claude Code or Codex too? See [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models) and [Models in Codex](https://usemagpie.ai/docs/codex-models). Stuck? Ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/subscriptions

# Use your Claude Pro/Max, ChatGPT Plus/Pro or GitHub Copilot subscription in any coding agent

Sign in to a subscription once, in magpie. Its models then show in every agent magpie sets up: GPT models from your ChatGPT plan in Claude Code, Claude models from your Claude plan in Codex or OpenCode, Copilot’s models in any of them. No API key.

magpie runs a gateway on your computer, at `127.0.0.1:3425`. It speaks the OpenAI, Anthropic and Gemini APIs and translates between them, streaming and tool calls included, so an agent that speaks one API can use a model served in another. magpie writes the gateway’s address and key into each agent’s own config file.

## Which subscriptions

| Subscription | Models are | Sign in from a terminal |
| --- | --- | --- |
| Claude (Pro, Max, Team) | `claude/…` | `magpie accounts add claude` |
| ChatGPT (Plus, Pro, Business) | `codex/…` | `magpie accounts add codex` |
| GitHub Copilot | `copilot/…` | `magpie accounts add copilot` |
| Gemini (Code Assist) | `gemini/…` | `magpie accounts add gemini` |
| Antigravity | `antigravity/…` | `magpie accounts add antigravity` |

- **Claude..** Requests on a Claude subscription run through the Claude Code installed on your computer, so keep it installed.
- **Copilot..** Copilot gives you a code to enter on GitHub’s page. For GitHub Enterprise on its own domain: `magpie accounts add copilot --host <name>.ghe.com`.
- **Gemini..** This is Gemini CLI’s Google sign-in. Google answers it only for a Code Assist Standard or Enterprise account with a Google Cloud project of its own; `magpie accounts project gemini <email> <project>` names the project.
- **Antigravity..** Its sign-in gives Antigravity’s Claude and Gemini models.

Other subscriptions are added as plugins, from magpie’s Plugins page; see [Plugins](https://usemagpie.ai/docs/plugins).

## Sign in

1. **Open Add provider.** In magpie’s Providers tab, press ＋ Add provider.
2. **Click the subscription’s tile.** magpie opens the vendor’s own sign-in page in your browser. The account shows up as soon as you finish.
3. **Pick its model for an agent.** In the Agents tab, click the model on the agent’s row and choose one of the subscription’s models.

An agent you are already signed in to on this machine, such as Claude Code or Codex, shows up as a provider too, *signed in as …*. `magpie accounts discovery off` stops magpie reading those sign-ins.

## Use it in another agent

A subscription’s models are in every agent’s picker in magpie. A few pairs people ask for:

| Agent | Subscription | From a terminal |
| --- | --- | --- |
| Claude Code | ChatGPT | `magpie claude codex/gpt-5.5` |
| Codex | Claude | `magpie codex claude/claude-opus-5-5` |
| Gemini CLI | ChatGPT | `magpie gemini model codex/gpt-5.5` |
| OpenCode | Claude | Pick a `claude/…` model on OpenCode’s row |

`magpie models` lists every model you can pick, as `provider/model`. Each agent’s guide says what magpie changes in its config and how to undo it: [Claude Code](https://usemagpie.ai/docs/claude-code-models), [Codex](https://usemagpie.ai/docs/codex-models), [Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models). `magpie <agent> default` takes magpie’s wiring out of an agent and puts back what it had.

## Several accounts and failover

- **Add another account..** Click the Claude or ChatGPT tile again, or run `magpie accounts add` again. Each account is listed under the provider.
- **Spread requests over them..** Open the provider’s row and tick every account to use. Routing says how requests spread: Smart, the default, sends them to the account with quota to spare whose allowance renews soonest; In order, Until used up, In turn, Least used first, Use before expiry, By weight (a Max account 5, a Pro one 1) and Speed first are the others.
- **Fall back when they run out..** The provider’s Fallback lists models to use when it is out of quota, rate limited or down.
- **One model on two subscriptions..** Claude Opus from your Claude subscription and from Copilot become one group by themselves, `auto/<model>`. Pick it to use both.
- **See what’s left..** `magpie accounts` lists each account and how much of its allowance is used.

The routing modes are in [Get started](https://usemagpie.ai/docs/start#routing).

## Other tools

Any tool with a base-URL setting can use a subscription through the gateway too. The Gateway tab’s Connect section has the address and key to copy. The base URL is `http://127.0.0.1:3425/v1` for an OpenAI client and `http://127.0.0.1:3425` for an Anthropic or Gemini one. See [Integrate your app](https://usemagpie.ai/docs/integrate).

## FAQ

### Can I use my ChatGPT Plus or Pro subscription in Claude Code?

Yes. Sign in to ChatGPT in magpie and pick a `codex/…` model on Claude Code’s row, or run `magpie claude codex/gpt-5.5`. magpie translates Claude Code’s Anthropic requests for the GPT model and the replies back, tool calls included.

### Can I use my Claude Pro or Max subscription in Codex or OpenCode?

Yes. Sign in to Claude in magpie and pick a `claude/…` model on the agent’s row. Requests on a Claude subscription run through the Claude Code installed on your computer, so keep it installed.

### Can I use GitHub Copilot models outside VS Code?

Yes. Sign in to Copilot in magpie (GitHub gives you a code to enter), and its models are `copilot/…` in Claude Code, Codex, Gemini CLI, OpenCode and the other agents magpie sets up.

### Do I need an API key to use a subscription in another agent?

No. magpie signs in on the vendor’s own page and the agent gets the gateway’s key. Your sign-in stays in magpie.

### Can I use several Claude or ChatGPT accounts and switch when one hits its limit?

Yes. Add each account in magpie and tick them on the provider’s row. Smart routing, the default, uses an account with quota to spare, and moves on when one is out or rate limited. `magpie accounts` shows what each has left.

### Do my requests go through a magpie server?

No. The gateway runs on your computer. Your prompts, replies, keys and accounts go only to the providers you use; magpie has no server of its own in that path.

### Does each agent have to be signed in to the subscription?

No. Subscriptions are added in magpie, not by signing in inside another agent. One sign-in serves every agent you point at it.

Using a key instead? See [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models) and [Models in Codex](https://usemagpie.ai/docs/codex-models). Stuck? Ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/local-models

# Use Ollama or LM Studio models in Claude Code and Codex

Claude Code speaks Anthropic Messages and Codex speaks OpenAI Responses. A local model server speaks OpenAI Chat Completions, and some speak Anthropic Messages too. magpie sits between them on your computer, so Claude Code and Codex can run on the models you pulled in Ollama or loaded in LM Studio.

The gateway runs at `127.0.0.1:3425`. magpie points the agent at it and sends each request on to your server. When the server speaks the agent’s API itself, the request is passed on as it is. When it doesn’t, magpie translates the request and the reply, streaming and tool calls included.

### Ollama, LM Studio

Presets with their default ports and no key. magpie asks the server which models it has.

### oMLX, MLX-Serve

MLX servers for Apple silicon, also presets.

### Anything else

vLLM, llama.cpp’s server or any OpenAI-compatible URL, on this computer or another.

## Supported servers

These are under On this machine when you add a provider:

| Server | Default address | APIs magpie uses |
| --- | --- | --- |
| Ollama | `http://localhost:11434` | Chat Completions, Anthropic Messages |
| LM Studio | `http://localhost:1234` | Chat Completions |
| oMLX | `http://localhost:8000` | Chat Completions, Responses, Anthropic Messages |
| MLX-Serve | `http://localhost:11234` | Chat Completions, Responses, Anthropic Messages |

So Claude Code on Ollama, oMLX or MLX-Serve sends its requests to the server as they are, and on LM Studio magpie translates them. Codex on oMLX or MLX-Serve goes as it is, and on Ollama or LM Studio magpie turns its Responses requests into Chat Completions.

## Set it up

1. **Start the server.** Pull or load a model in Ollama or LM Studio and leave the server running.
2. **Add it in magpie.** In the Providers tab, press ＋ Add provider and pick Ollama or LM Studio under On this machine. No key is needed. magpie asks the server which models it has, and they show as `ollama/…` or `lmstudio/…`.
3. **Pick the model for the agent.** In the Agents tab, click the model on the Claude Code or Codex row and choose the local one. magpie writes Claude Code’s `settings.json` or Codex’s `config.toml`. Start a new session to use it.

The same from a terminal:

```
ollama pull qwen3
magpie provider add ollama
magpie models                     # every model, as provider/model
magpie claude ollama/qwen3        # Claude Code
magpie codex ollama/qwen3         # Codex
```

Inside the agent, Claude Code’s and Codex’s `/model` list magpie’s models too, so you can move between a local model and a cloud one there. What changes in each agent’s config is in [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models#settings) and [Models in Codex](https://usemagpie.ai/docs/codex-models).

## Another port or another computer

If the server listens on another port, or runs on another computer such as a GPU box or a NAS, change Server address in the provider’s editor. Each of its URLs moves there and keeps its path.

```
magpie provider add lmstudio address=http://192.168.1.5:1234
magpie provider set ollama address=192.168.1.20:11434
magpie provider set ollama address=     # back to the default
```

A server behind HTTPS with a self-signed certificate can be reached with Don't check its certificate in the editor; it applies to that provider’s own hosts only.

## vLLM, llama.cpp and other servers

A server with no preset is added as Custom: paste its URL, such as `http://localhost:8080/v1`, and press Detect APIs. magpie sends the smallest request to Chat Completions, Responses, Anthropic Messages and Gemini at that URL and keeps the ones that answer. The key can be left empty for a server that needs none.

## Context window

Agents plan around how long a request the model takes. Claude Code takes a model it doesn’t know for 200K, and Codex compacts a conversation at 90% of the window it is told. A local model is often loaded with a much smaller window, so tell magpie the real one: Context window under Advanced in the provider’s editor, for every model or one of them. magpie passes it on to the agents.

```
magpie provider set ollama context=32k
magpie provider set ollama context.qwen3=128k
```

## Masking

magpie’s [privacy masking](https://usemagpie.ai/docs/masking) replaces keys, tokens and other secrets with placeholders before a request leaves the gateway, a request to a local server too. When the model runs on your own computer or network, you can turn on Send requests unmasked in its editor, or run `magpie provider set ollama unmasked=yes`. It is your call: Ollama’s cloud models, or a relay you run locally, pass a request on to a vendor whatever the address.

## FAQ

### Can Claude Code use Ollama?

Yes. Add Ollama in magpie and pick one of its models for Claude Code. magpie writes the gateway’s address into Claude Code’s `settings.json`, and Ollama’s Anthropic-compatible API takes Claude Code’s requests as they are.

### Can Codex use Ollama or LM Studio?

Yes. Codex speaks only the Responses API, so magpie turns its requests into Chat Completions for Ollama and LM Studio, and the replies back, tool calls included. oMLX and MLX-Serve take Responses themselves.

### Do I need an API key?

No. The local presets take none. A server you secured with a key can have it in the provider’s editor.

### Can the model run on another computer?

Yes. Set the provider’s Server address to that computer, such as `http://192.168.1.20:11434`.

### Why does Claude Code fail on long conversations with a local model?

It assumes a model it doesn’t know takes 200K. Set the real Context window on the provider in magpie, and Claude Code and Codex compact before they reach it.

### How do I go back?

Pick one of the agent’s own models in magpie, or run `magpie claude default` or `magpie codex default`. What magpie wrote comes out, and what it replaced comes back.

Looking for cloud models? See [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models) and [Models in Codex](https://usemagpie.ai/docs/codex-models). Stuck? Ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/opencode-models

# Use DeepSeek, Kimi, GLM or your Claude and ChatGPT subscription in OpenCode

OpenCode reaches a model through a provider in its config. magpie adds one provider, named `magpie`, that leads to a gateway on your computer. Every model you have in magpie is listed under it: DeepSeek, Kimi, GLM and Qwen keys, and the models of a Claude, ChatGPT or Copilot sign-in.

The gateway runs at `127.0.0.1:3425`. OpenCode sends it OpenAI Chat Completions, and magpie passes each request on in the API its provider speaks, translating the request and the reply where they differ, streaming and tool calls included. OpenCode’s own providers stay as they were, next to magpie’s.

### Chinese models

DeepSeek, Kimi and Kimi Code, Zhipu GLM (pay as you go or Coding Plan), Z.ai, MiniMax and Qwen.

### Subscriptions

Claude Pro/Max, ChatGPT Plus/Pro and GitHub Copilot, signed in once in magpie.

### Anything else

Any OpenAI- or Anthropic-compatible URL and key, Ollama and LM Studio.

## Set it up

1. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick DeepSeek, Kimi, Zhipu GLM, MiniMax or Qwen, paste your API key and save. magpie asks the vendor which models it serves.
2. **Pick the model for OpenCode.** In the Agents tab, click the model on OpenCode’s row and choose one, such as `deepseek/deepseek-v4-pro`. magpie writes `"model": "magpie/deepseek/deepseek-v4-pro"` into OpenCode’s config, with the `magpie` provider beside it.
3. **Or pick it in OpenCode.** Once the provider is there, magpie’s models are in OpenCode’s own `/models` list under `magpie`, so you can switch there too.

The same from a terminal:

```
magpie provider add deepseek sk-…
magpie models                                    # every model, as provider/model
magpie opencode deepseek/deepseek-v4-pro         # OpenCode's model
magpie opencode small deepseek/deepseek-v4-flash # its small_model
```

OpenCode’s `small_model` is a field of its own on the row, so it can run on a cheaper model than the main one.

> **Zhipu GLM Coding Plan.** When you add Zhipu GLM or Z.ai, pick the plan your key is for. A Coding Plan key has its own endpoints, and sent to the pay-as-you-go one it is told it has no balance.

## Subscriptions

Sign in once in magpie, from ＋ Add provider or a terminal, and the subscription’s models are listed under `magpie` in OpenCode like any other. No API key.

| Subscription | Models are | From a terminal |
| --- | --- | --- |
| Claude (Pro, Max, Team) | `claude/…` | `magpie accounts add claude` `magpie opencode claude/claude-opus-5-5` |
| ChatGPT (Plus, Pro, Business) | `codex/…` | `magpie accounts add codex` `magpie opencode codex/gpt-5.5` |
| GitHub Copilot | `copilot/…` | `magpie accounts add copilot` |

Requests on a Claude subscription run through the Claude Code installed on your computer, so keep it installed. Copilot gives you a code to enter on GitHub’s page. Several accounts of one subscription can share the load and fail over; see [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions#accounts).

## What changes in opencode.json

magpie writes to the config file OpenCode reads from its config folder, `$OPENCODE_CONFIG_DIR` when that is set and `~/.config/opencode` otherwise: the first of `opencode.jsonc`, `opencode.json` and `config.json` that exists, or a new `opencode.json`. It changes only these keys; your other settings stay.

| Key | Set to |
| --- | --- |
| `model` | `magpie/<provider>/<model>` |
| `small_model` | The same form, when you set one |
| `provider.magpie.npm` | `@ai-sdk/openai-compatible` |
| `provider.magpie.options.baseURL` | `http://127.0.0.1:3425/v1` |
| `provider.magpie.options.apiKey` | The gateway’s key |
| `provider.magpie.models` | Every model magpie lists for OpenCode |

Each model carries its context window and output limit, so OpenCode knows when to compact; whether it takes images; its reasoning levels; and its price. magpie keeps the list up to date as you add providers and accounts. If the file also has the provider under `providers`, where OpenCode 2 keeps it, magpie writes it there as well. OpenCode in a WSL distro on Windows is set up the same way, in the distro’s `~/.config/opencode`.

## Reasoning levels and cost

- **Reasoning levels..** A model’s reasoning efforts are written as its variants in OpenCode, each one asking for that `reasoningEffort`. A model that offers fast processing, such as a GPT model from a ChatGPT plan, also gets a `fast` variant for each level.
- **Cost..** magpie writes each model’s price per million tokens, input, output, cache read and cache write, so OpenCode’s session cost counts, where without it every model costs 0.
- **Prompt caching..** magpie turns on OpenCode’s prompt cache key for its provider, so a provider that caches by it keeps the cache between turns.

## A shorter model list

By default OpenCode is shown every model you have in magpie. To show it only some providers or groups:

```
magpie visible opencode deepseek,claude   # only these providers
magpie visible opencode all               # every model again
```

A model left out of the list still answers when OpenCode asks for it by name.

## Switch back

On OpenCode’s row in magpie, the model picker lists OpenCode’s own providers too, the ones signed in in its `auth.json`. Pick one of them, or run:

```
magpie opencode default
```

It puts back the `model` and `small_model` OpenCode had before magpie, and takes the `magpie` provider out of the file.

**By provider:** [DeepSeek](https://usemagpie.ai/docs/deepseek) · [Kimi and Kimi Code](https://usemagpie.ai/docs/kimi) · [GLM Coding Plan](https://usemagpie.ai/docs/glm) · [Qwen](https://usemagpie.ai/docs/qwen) · [MiniMax](https://usemagpie.ai/docs/minimax)

## FAQ

### How do I use DeepSeek in OpenCode?

Add DeepSeek with your API key in magpie, then pick a DeepSeek model on OpenCode’s row in the Agents tab, or run magpie opencode deepseek/deepseek-v4-pro. magpie adds a magpie provider to `opencode.json` and sets the model.

### Can I use Kimi or GLM in OpenCode?

Yes. Add Kimi or Zhipu GLM in magpie and pick its model for OpenCode. For a GLM Coding Plan key, pick the Coding Plan when you add it, since it has its own endpoints.

### Can I use my Claude Pro or Max subscription in OpenCode?

Yes. Sign in to Claude in magpie (magpie accounts add claude) and pick a claude/… model for OpenCode. Requests on a Claude subscription run through the Claude Code installed on your computer, so keep it installed.

### Can I use my ChatGPT Plus or Pro subscription in OpenCode?

Yes. Sign in to ChatGPT in magpie (magpie accounts add codex) and pick a codex/… model, such as codex/gpt-5.5. Its reasoning levels show as the model’s variants in OpenCode.

### Which file does magpie change?

OpenCode’s config in ~/.config/opencode (or $OPENCODE_CONFIG_DIR): the first of `opencode.json`c, `opencode.json` and config.json, or a new `opencode.json`. It sets model and `small_model` and adds provider.magpie; other settings stay.

### How do I switch back to OpenCode’s own model?

Pick one of OpenCode’s own models on its row in magpie, or run `magpie opencode default`. It puts back the model and `small_model` you had and removes magpie’s provider.

Other agents: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Models in Codex](https://usemagpie.ai/docs/codex-models), [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models). Stuck? Ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/alternatives

# magpie, CC Switch and Claude Code Router compared

magpie, [CC Switch](https://github.com/farion1231/cc-switch) and [Claude Code Router](https://github.com/musistudio/claude-code-router) (CCR) all help you run AI coding agents on the providers and models you choose. They overlap, and each is good at something. This page puts them side by side, using each project’s own README for the other two and magpie’s source for magpie.

### CC Switch

A desktop app (Tauri 2) that manages twelve tools, from Claude Code, Codex and Gemini CLI to OpenCode, OpenClaw, Hermes, Pi and Kimi Code. It switches a tool’s provider by writing only the key fields of its config, backing it up first, and keeps MCP servers, skills and prompts for every tool in one place. An optional local routing mode converts API formats and fails over through a queue. It ships over 90 provider presets.

### Claude Code Router

A local model gateway and control plane at `127.0.0.1:3456`. Agents such as Claude Code, Codex, Kimi CLI, Kilo Code, OpenCode and Pi get one stable endpoint through an agent profile, and routing rules decide where each request goes: conditions on headers and bodies, rewrites, retries, credential pools and ordered fallbacks. It adds tools to models (vision, web search, MCP, browser automation) and logs every request with its cost. Desktop app, npm CLI with a web UI, or Docker.

### magpie

A menu bar (tray) app with a window, a TUI and a CLI. It points each agent at a local gateway at `127.0.0.1:3425` that speaks OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and Gemini and translates between them, so any agent can use any model, including a Claude, ChatGPT, GitHub Copilot or Gemini sign-in. Several keys and sign-ins can stand behind one model, with failover before the agent sees an error.

## Side by side

|  | magpie | CC Switch as of its README, Nov 2026 | Claude Code Router as of its README, Nov 2026 |
| --- | --- | --- | --- |
| Agents | Over 20, among them Claude Code, Codex, Gemini CLI, OpenCode, Pi, Goose, Crush, GitHub Copilot CLI, VS Code, Kimi Code, Hermes Agent and Snow CLI | 12: Claude Code, Claude Desktop, Codex, Gemini CLI, Grok Build, OpenCode, OpenClaw, Hermes, Pi, MiniMax Code, Kimi Code, Oh My Pi | Claude Code, Claude Design, Codex, Grok CLI, Kimi CLI, Kilo Code, OpenCode, Pi, ZCode, WorkBuddy, and compatible API clients |
| How it switches | Edits the one setting it changes in each agent’s config and points the agent at its local gateway | Direct: rewrites the key fields of the tool’s config. Routing (optional): a local proxy, default port 15721 | Local gateway; an agent profile connects the agent to it |
| Protocol translation | OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and Gemini, both directions | In Routing mode, for Claude Code, Codex, Gemini CLI and Grok Build | Providers in OpenAI Chat / Responses, Anthropic Messages or Gemini format behind one endpoint |
| Subscription sign-ins | Claude Pro/Max, ChatGPT Plus/Pro, GitHub Copilot, Gemini Code Assist, Antigravity | Accounts (Beta): GitHub Copilot, ChatGPT, xAI (Grok), Kimi Code | Not stated (providers can import a local login where supported) |
| Routing and failover | Several keys and sign-ins behind one model; picks by intent, order, round robin, least used or quota; rests rate-limited accounts and fails over | Failover queue per tool with a circuit breaker (Routing mode); Aggregation puts several providers’ models in one list | Conditions on headers and bodies, prefixes, rewrites, retries, credential pools, key rotation, ordered fallback models |
| GUI and CLI | Menu bar / tray app with a window, TUI, CLI; Docker | Desktop app with a tray menu; CLI not stated | Desktop app; npm CLI with a browser UI; Docker |
| Platforms | macOS (signed and notarised), Windows, Linux | Windows 10+, macOS 12+ (signed and notarized), Linux (glibc 2.35+, WebKitGTK 4.1) | Windows, Linux (AppImage), macOS (Apple Silicon, Intel); signing not stated |
| License | MIT | MIT | MIT |

The CC Switch and Claude Code Router columns say only what their READMEs said in November 2026; where a README doesn’t say, the cell says “not stated”. Both projects move quickly, so check their pages for what has changed since.

## Which one fits

- **CC Switch.** fits when you mostly switch each tool between providers by hand and want its config left close to how you wrote it, with MCP servers, skills and prompts managed for every tool from one app. Its provider presets are the largest of the three, and it reaches tools the others don’t list, such as Claude Desktop, OpenClaw and Oh My Pi.
- **Claude Code Router.** fits when you want a gateway you can program: rules on headers and bodies, request rewrites, credential pools, client keys with their own quotas, and a log of every request with its cost. It also adds tools such as web search and browser automation to models that lack them, and runs headless from npm or Docker.
- **magpie.** fits when you use several agents and want each on a different model, Codex on DeepSeek and Claude Code on Kimi, say, or a Claude or ChatGPT subscription in another agent. Every agent goes through one translating gateway, and one model can be served by several accounts that take turns and fail over.

They can sit side by side. magpie’s gateway is an OpenAI-, Anthropic- and Gemini-compatible endpoint, so a tool that takes a custom base URL can use it as a provider.

## FAQ

### What is a CC Switch alternative?

magpie and Claude Code Router both cover part of what CC Switch does. magpie switches the model of each agent and runs every agent through one translating gateway with subscription sign-ins and failover; Claude Code Router is a programmable local gateway with routing rules and request logs.

### What is a claude-code-router alternative?

CC Switch, if you mostly want to switch each tool’s provider and keep its config as written; magpie, if you want a translating gateway for many agents with Claude, ChatGPT, Copilot or Gemini sign-ins and accounts that fail over.

### CC Switch vs claude-code-router: what is the difference?

By their READMEs, CC Switch is a desktop manager that rewrites each tool’s config and offers an optional local routing proxy, while Claude Code Router is a local gateway at `127.0.0.1:3456` that agents connect to through profiles and that routes each request by rules.

### Does magpie rewrite my agent’s config like CC Switch?

It edits only the one setting it changes in each agent’s config file, keeping comments and order, and points the agent at its gateway at `127.0.0.1:3425`. Picking the agent’s own model again puts the old value back.

### Is magpie a proxy like claude-code-router?

Yes, magpie runs a local gateway too. It speaks OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and Gemini and translates between them, so Codex, which speaks only Responses, and Claude Code, which speaks only Messages, can use any provider’s model.

### Are all three free and open source?

Yes. magpie, CC Switch and Claude Code Router are each released under the MIT license.

Guides: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Models in Codex](https://usemagpie.ai/docs/codex-models), [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions). Ask on [Discord](https://discord.gg/vGSnD3ZKQF) if you get stuck.

---

Source: https://usemagpie.ai/docs/deepseek

# DeepSeek in Claude Code, Codex, Gemini CLI and OpenCode

DeepSeek serves an OpenAI-compatible API and an Anthropic-compatible one. Add your key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use DeepSeek’s models through magpie’s gateway at `127.0.0.1:3425`.

## Add DeepSeek

1. **Get an API key.** Create one at [platform.deepseek.com/api_keys](https://platform.deepseek.com/api_keys).
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick DeepSeek, paste the key and save. magpie asks DeepSeek which models it serves, such as `deepseek-v4-pro` and `deepseek-v4-flash`.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose a DeepSeek model.

```
magpie provider add deepseek sk-…
magpie models        # every model, as provider/model
```

Model ids in magpie are `provider/model`, so DeepSeek’s are `deepseek/…`. Adding the preset again adds a second DeepSeek provider for another key; to spread requests over several keys, add them all to the one provider instead.

## Endpoints

DeepSeek has one plan, pay as you go, and magpie uses these endpoints for it:

| API | Base URL |
| --- | --- |
| OpenAI Chat Completions and Responses | `https://api.deepseek.com/v1` |
| Anthropic Messages | `https://api.deepseek.com/anthropic` |

## In each agent

Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.

```
magpie claude deepseek/deepseek-v4-pro
magpie codex deepseek/deepseek-v4-pro
magpie gemini model deepseek/deepseek-v4-flash
magpie opencode deepseek/deepseek-v4-pro
```

- **Claude Code.** speaks Anthropic Messages, and so does DeepSeek’s Anthropic endpoint, so its requests are passed on as they are. Every tier (opus, sonnet, haiku) runs on the model you pick unless you give one its own. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses. DeepSeek serves the Responses API itself, so Codex’s requests are passed on as they are. The model shows in Codex’s `/model` with its reasoning efforts. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Gemini’s API. magpie points it at its gateway and translates. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** gets the model in `opencode.json`, with its reasoning variants and cost. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

## Thinking, effort and the prompt cache

- **Thinking on tool turns..** DeepSeek’s Anthropic endpoint wants a thinking block on every assistant turn that calls a tool, and on turns that only answer tool results. When an agent’s history has none, magpie adds one, and turns a Claude `redacted_thinking` block into one. So a routing group can fall back from Claude to DeepSeek in the middle of a conversation.
- **Effort..** DeepSeek thinks at three levels, `low`, `high` and `max`, set in `output_config.effort`, and ignores `budget_tokens`. A token budget an agent sends is fitted to one of the three.
- **Prompt cache..** With several keys, magpie keeps a conversation on the same DeepSeek key for an hour after its last turn, so the next turn reads its prompt from DeepSeek’s cache instead of sending it uncached to another key.
- **Images..** magpie uploads each image an agent sends to DeepSeek’s API once and names it by its file id on later turns. `magpie provider set deepseek image-files=off` sends images inline on every turn instead.

## Balance and usage

The DeepSeek row shows your balance, read from DeepSeek: the total, what was granted and what you topped up. The Usage tab counts tokens, cache hits and cost for each agent and model that went through magpie.

## FAQ

### How do I use DeepSeek in Claude Code?

Add your DeepSeek API key in magpie (Providers, Add provider, DeepSeek), then pick a DeepSeek model such as `deepseek-v4-pro` on Claude Code’s row, or run `magpie claude deepseek/deepseek-v4-pro`. magpie writes Claude Code’s `settings.json` and passes its requests to DeepSeek’s Anthropic endpoint, `https://api.deepseek.com/anthropic`.

### Can Codex use DeepSeek?

Yes. DeepSeek serves the OpenAI Responses API that Codex speaks, so magpie passes Codex’s requests on as they are. Pick the model on Codex’s row or run `magpie codex deepseek/deepseek-v4-pro`; it shows in Codex’s `/model` list.

### Do I need to set ANTHROPIC_BASE_URL to DeepSeek myself?

No. magpie points Claude Code at its own gateway at `127.0.0.1:3425` and keeps your DeepSeek key itself. Picking one of Claude Code’s own models again puts back what you had.

### Can I switch between Claude and DeepSeek in one conversation?

Yes. DeepSeek’s Anthropic endpoint wants a thinking block on tool-calling turns, and a conversation that started on Claude doesn’t have one it can read. magpie adds it, so a routing group can fall back from Claude to DeepSeek mid-conversation.

### Which reasoning effort does DeepSeek take?

DeepSeek thinks at three levels, low, high and max, set in `output_config.effort`, and ignores `budget_tokens`. magpie fits the level or token budget an agent asks for to one of those three.

### Can I use several DeepSeek keys?

Yes. Add them all to the DeepSeek provider and tick each one. magpie spreads requests over them, keeps a conversation on one key so its prompt cache is reused, and moves on when a key runs out of balance.

Every agent: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Models in Codex](https://usemagpie.ai/docs/codex-models), [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models), [Models in OpenCode](https://usemagpie.ai/docs/opencode-models). Ask on [Discord](https://discord.gg/vGSnD3ZKQF) if you get stuck.

---

Source: https://usemagpie.ai/docs/kimi

# Kimi K2 and Kimi Code in Claude Code, Codex, Gemini CLI and OpenCode

Kimi, from Moonshot AI, comes two ways: the Kimi API, paid as you go, and the Kimi Code membership, each with a global and a China endpoint. magpie has a preset for each of the four. Add a key once, and Claude Code, Codex, Gemini CLI, OpenCode and your other agents can use Kimi’s models through magpie’s gateway at `127.0.0.1:3425`.

## Add Kimi

1. **Get a key.** For the Kimi API, from the Kimi platform’s API keys page; for Kimi Code, from the Kimi Code console. The table below links each.
2. **Add the provider.** In Providers, press ＋ Add provider and pick the preset that issued your key: Kimi, Kimi (China), Kimi Code or Kimi Code (China). Paste the key and save. magpie asks Kimi which models it serves.
3. **Pick it for an agent.** In the Agents tab, choose a Kimi model on the agent’s row: `kimi-k2.6` on the API, say, or `kimi-for-coding` on Kimi Code.

```
magpie provider add moonshot sk-…        # Kimi API (platform.kimi.ai)
magpie provider add moonshot-cn sk-…     # Kimi API, China (platform.kimi.com)
magpie provider add kimi-code sk-…       # Kimi Code membership
magpie provider add kimi-code-cn sk-…    # Kimi Code membership, China
```

Model ids are `provider/model`: `moonshot/kimi-k2.6`, `kimi-code/kimi-for-coding`. The models listed are the ones Kimi serves your key at the time.

## Plans and endpoints

| Preset | Plan | OpenAI Chat Completions | Anthropic Messages | Key from |
| --- | --- | --- | --- | --- |
| Kimi | Kimi API, pay as you go | `https://api.moonshot.ai/v1` | `https://api.moonshot.ai/anthropic` | [platform.kimi.ai](https://platform.kimi.ai/console/api-keys?aff=magpie) |
| Kimi (China) | Kimi API, pay as you go | `https://api.moonshot.cn/v1` | `https://api.moonshot.cn/anthropic` | [platform.kimi.com](https://platform.kimi.com/console/api-keys?aff=magpie) |
| Kimi Code | Kimi Code membership | `https://api.kimi.ai/coding/v1` | `https://api.kimi.ai/coding` | [kimi.ai/code/console](https://www.kimi.ai/code/console?aff=magpie) |
| Kimi Code (China) | Kimi Code membership | `https://api.kimi.com/coding/v1` | `https://api.kimi.com/coding` | [kimi.com/code/console](https://www.kimi.com/code/console?aff=magpie) |

A key works only on the endpoints of the plan and region that issued it, so pick the preset that matches where you got it.

## In each agent

Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.

```
magpie claude moonshot/kimi-k2.6
magpie codex moonshot/kimi-k2.6
magpie gemini model moonshot/kimi-k2.6
magpie opencode kimi-code/kimi-for-coding
```

- **Claude Code.** speaks Anthropic Messages, and so does Kimi’s Anthropic endpoint, so its requests are passed on as they are. Every tier (opus, sonnet, haiku) runs on the model you pick unless you give one its own. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses. Kimi serves Chat Completions and Anthropic Messages but not Responses, so magpie translates each request and the reply, streaming and tool calls included. The model shows in Codex’s `/model` with its reasoning efforts. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Gemini’s API. magpie points it at its gateway and translates. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** gets the model in `opencode.json`, with its reasoning variants and cost. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

## Thinking

Some Kimi models always think: Kimi Code (China)’s K3.1 turns away a request that switches thinking off. When an agent asks for it off and the model refuses, magpie asks again with thinking left on, so the agent gets an answer rather than the error.

## Balance, windows and search

- **Kimi API..** The row shows your balance: in ¥ for Kimi (China), in $ for Kimi.
- **Kimi Code..** The row shows the membership’s windows, read from Kimi: the weekly allowance, shorter windows such as five hours, the monthly allowance and a booster pack’s balance.
- **Cost..** Kimi Code’s models are listed at $0, so magpie’s Usage tab prices their calls at the Kimi API’s price for the same model.
- **Web search..** A Kimi Code key searches the web through the membership’s own search endpoint, and magpie gives that search to Kimi Code models that can’t search by themselves.

## FAQ

### How do I use Kimi K2 in Codex?

Add your Kimi key in magpie, then pick a Kimi model such as `kimi-k2.6` on Codex’s row, or run `magpie codex moonshot/kimi-k2.6`. Kimi serves Chat Completions and Anthropic Messages but not the Responses API Codex speaks, so magpie translates each request and the reply, streaming and tool calls included.

### Can I use my Kimi Code membership in Claude Code or Codex?

Yes. Add the Kimi Code preset (or Kimi Code (China)) with a key from the Kimi Code console. magpie sends requests to the membership’s own endpoints, `https://api.kimi.ai/coding` for Anthropic Messages and `https://api.kimi.ai/coding/v1` for Chat Completions, and shows the membership’s usage windows.

### Kimi or Kimi (China): which preset do I pick?

The one that issued your key. A key from platform.kimi.ai goes with Kimi (api.moonshot.ai); one from platform.kimi.com goes with Kimi (China) (api.moonshot.cn). Kimi Code has the same two: kimi.ai and kimi.com.

### Why does Kimi Code show a cost when the membership is prepaid?

Kimi Code’s model list prices its models at $0, so magpie prices each call at the Kimi API’s price for the same model. The figure shows what the work would have cost on the API; it isn’t charged.

### Can Kimi Code search the web for my agent?

Yes. A Kimi Code key searches the web through the membership’s own search endpoint, so a Kimi Code model that can’t search by itself is given magpie’s search on your plan.

Every agent: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Models in Codex](https://usemagpie.ai/docs/codex-models), [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models), [Models in OpenCode](https://usemagpie.ai/docs/opencode-models). Ask on [Discord](https://discord.gg/vGSnD3ZKQF) if you get stuck.

---

Source: https://usemagpie.ai/docs/glm

# GLM Coding Plan in Claude Code, Codex, Gemini CLI and OpenCode

Zhipu’s GLM models come from two places, Zhipu GLM at open.bigmodel.cn and Z.ai at api.z.ai, and each has two plans: pay as you go and the GLM Coding Plan. Add a key to magpie with its plan, and Claude Code, Codex, Gemini CLI, OpenCode and your other agents can use GLM through magpie’s gateway at `127.0.0.1:3425`.

## Add GLM

1. **Get a key.** From [open.bigmodel.cn](https://open.bigmodel.cn/usercenter/proj-mgmt/apikeys) for Zhipu GLM, or [z.ai](https://z.ai/manage-apikey/apikey-list) for Z.ai.
2. **Add the provider and pick the plan.** In Providers, press ＋ Add provider, pick Zhipu GLM or Z.ai, choose the plan your key is for (Pay as you go or Coding Plan), paste the key and save.
3. **Pick it for an agent.** In the Agents tab, choose a GLM model such as `glm-5.3` on the agent’s row.

```
magpie provider add zhipu sk-… plan=coding   # GLM Coding Plan (open.bigmodel.cn)
magpie provider add zai sk-… plan=coding     # GLM Coding Plan (z.ai)
magpie provider add zhipu sk-… plan=api      # pay as you go
```

> **Pick the plan your key is for.** A Coding Plan key has its own endpoints. Sent to the pay-as-you-go one, it is told it has no balance (429, code 1113). If that happens, magpie tries the Coding Plan endpoint, and when the key is served there it moves the provider to the plan’s endpoints. When both refuse, the error says what each said and what to change.

## Plans and endpoints

| Preset | Plan | OpenAI Chat Completions | OpenAI Responses | Anthropic Messages |
| --- | --- | --- | --- | --- |
| Zhipu GLM | Pay as you go | `https://open.bigmodel.cn/api/paas/v4` | — | `https://open.bigmodel.cn/api/anthropic` |
| Zhipu GLM | Coding Plan | `https://open.bigmodel.cn/api/coding/paas/v4` | `https://open.bigmodel.cn/api/v1` | `https://open.bigmodel.cn/api/anthropic` |
| Z.ai | Pay as you go | `https://api.z.ai/api/paas/v4` | — | `https://api.z.ai/api/anthropic` |
| Z.ai | Coding Plan | `https://api.z.ai/api/coding/paas/v4` | `https://api.z.ai/api/v1` | `https://api.z.ai/api/anthropic` |

Both plans share the Anthropic endpoint, which bills the Coding Plan when the account has one. Each key on the provider says which plan it is for, so one provider can hold a pay-as-you-go key and a Coding Plan key, and each key’s requests, model list and windows are its own plan’s.

## In each agent

Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.

```
magpie claude zhipu/glm-5.3
magpie codex zhipu/glm-5.3
magpie gemini model zhipu/glm-5.3
magpie opencode zhipu/glm-5.3
```

- **Claude Code.** speaks Anthropic Messages, and so does GLM’s Anthropic endpoint, so its requests are passed on as they are. Every tier (opus, sonnet, haiku) runs on the model you pick unless you give one its own. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses. The Coding Plan serves the Responses API itself, so Codex’s requests are passed on as they are; on pay as you go, magpie translates them to Chat Completions. The model shows in Codex’s `/model` with its reasoning efforts. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Gemini’s API. magpie points it at its gateway and translates. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** gets the model in `opencode.json`, with its reasoning variants and cost. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

## Thinking and effort

- **GLM-5.3 always thinks..** It turns away a request that switches thinking off. magpie asks again with thinking left on, so the agent gets an answer rather than the error.
- **Effort..** GLM-5.2 and GLM-5.3 take their reasoning level in `output_config.effort`, and magpie puts the agent’s level there.

## Usage windows and search

- **Coding Plan windows..** The row shows the plan’s windows, read from Zhipu or Z.ai: the hourly and weekly allowances, and the month’s MCP tool calls.
- **Web search..** With a Coding Plan key and no searcher chosen in Settings, magpie searches the web for GLM models through the plan’s own search service.

## FAQ

### How do I use the GLM Coding Plan in Claude Code?

Add Zhipu GLM (open.bigmodel.cn) or Z.ai (api.z.ai) in magpie, choose Coding Plan as the key’s plan, then pick a GLM model such as `glm-5.3` on Claude Code’s row, or run `magpie claude zhipu/glm-5.3`. Claude Code’s requests go to the Anthropic endpoint, which bills the Coding Plan when the account has one.

### Can Codex use GLM?

Yes. The GLM Coding Plan serves the OpenAI Responses API Codex speaks, so magpie passes Codex’s requests on as they are. On pay as you go, magpie translates Codex’s requests to Chat Completions. Run `magpie codex zhipu/glm-5.3` or pick it on Codex’s row.

### Why does my GLM Coding Plan key say insufficient balance (1113)?

A Coding Plan key sent to the pay-as-you-go endpoint, `https://open.bigmodel.cn/api/paas/v4`, is answered with 429 code 1113. magpie tries the Coding Plan endpoint, `https://open.bigmodel.cn/api/coding/paas/v4`, and when the key is served there it moves the provider to the plan’s endpoints. Choosing Coding Plan when you add the key avoids it.

### Can I have a Coding Plan key and a pay-as-you-go key together?

Yes. Each key on a Zhipu GLM or Z.ai provider says which plan it is for. Its requests go to that plan’s endpoints, and its model list and usage windows are that plan’s.

### Zhipu GLM or Z.ai: which preset do I pick?

The one that issued your key: Zhipu GLM for a key from open.bigmodel.cn, Z.ai for a key from z.ai.

### Does GLM-5.3 work with thinking turned off?

GLM-5.3 always thinks and turns away a request that switches thinking off. magpie asks again with thinking left on, so the agent gets an answer.

Every agent: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Models in Codex](https://usemagpie.ai/docs/codex-models), [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models), [Models in OpenCode](https://usemagpie.ai/docs/opencode-models). Ask on [Discord](https://discord.gg/vGSnD3ZKQF) if you get stuck.

---

Source: https://usemagpie.ai/docs/qwen

# Qwen in Claude Code, Codex, Gemini CLI and OpenCode

Alibaba serves Qwen through DashScope, on Alibaba Cloud Model Studio, Bailian and Qwen Cloud, pay as you go or on a Token Plan. Every one of them speaks OpenAI Chat Completions and Anthropic Messages. Add your key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Qwen through magpie’s gateway at `127.0.0.1:3425`.

## Add Qwen

1. **Get a key.** Pay as you go: [Model Studio](https://modelstudio.console.alibabacloud.com/?tab=playground#/api-key) (international) or [Bailian](https://bailian.console.aliyun.com/?tab=model#/api-key) (China). A Token Plan’s key comes from its own plan page.
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick the Qwen preset your key is from (the table below), paste the key and save. magpie asks the endpoint which models it serves.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose a Qwen model such as `qwen3.8-max`.

```
magpie provider add qwen sk-…                     # Model Studio, international
magpie provider add qwen-cn sk-…                  # Bailian, China
magpie provider add bailian-token-plan sk-sp-…    # Bailian Token Plan
magpie provider add qwencloud sk-ws-… region=us-east-1
```

> **Each key works on its own host only.** A Token Plan key (`sk-sp-…`) is refused by pay-as-you-go endpoints and by the other Token Plans, and a Qwen Cloud key is refused outside its region. If a request comes back 401, check that the key sits under the preset it was made for.

## Plans and endpoints

| Preset | Plan and key | Endpoints (Chat Completions, Anthropic Messages) |
| --- | --- | --- |
| Qwen qwen | pay as you go, international (Model Studio) | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1` `https://dashscope-intl.aliyuncs.com/apps/anthropic` |
| Qwen (China) qwen-cn | pay as you go, China (Bailian) | `https://dashscope.aliyuncs.com/compatible-mode/v1` `https://dashscope.aliyuncs.com/apps/anthropic` |
| Qwen Token Plan qwen-token-plan | subscription, `sk-sp-` | `https://token-plan.maas.qianwenaiapi.com/compatible-mode/v1` `https://token-plan.maas.qianwenaiapi.com/apps/anthropic` |
| Bailian Token Plan bailian-token-plan | subscription, `sk-sp-` | `https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1` `https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic` |
| Qwen Cloud qwencloud | pay as you go, `sk-ws-`, six regions, Singapore the default | `https://{region}.maas.qwencloudapi.com/compatible-mode/v1` `https://{region}.maas.qwencloudapi.com/apps/anthropic` |
| Qwen Cloud Token Plan qwencloud-token-plan | subscription, `sk-sp-`, Singapore | `https://token-plan.maas.qwencloudapi.com/compatible-mode/v1` `https://token-plan.maas.qwencloudapi.com/apps/anthropic` |

When a Token Plan’s host gives no model list, magpie offers the plan’s text models as its overview lists them: auto, qwen3.8-max, qwen3.8-flash, qwen3.7-max, qwen3.7-plus, qwen3.6-flash, and the DeepSeek and GLM models the plan includes. The Bailian Token Plan also serves a decision model that can classify turns for [intent routing](https://usemagpie.ai/docs/intent).

## In each agent

Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.

```
magpie claude qwen/qwen3.8-max
magpie codex qwen/qwen3.8-max
magpie gemini model qwen/qwen3.7-plus
magpie opencode qwen/qwen3.8-max
```

- **Claude Code.** speaks Anthropic Messages, and so does Qwen’s Anthropic endpoint, so its requests are passed on as they are. Every tier (opus, sonnet, haiku) runs on the model you pick unless you give one its own. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses. DashScope serves Chat Completions and Anthropic Messages but not Responses, so magpie translates each request and the reply, streaming and tool calls included. The model shows in Codex’s `/model` with its reasoning efforts. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Gemini’s API. magpie points it at its gateway and translates. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** gets the model in `opencode.json`, with its reasoning variants and cost. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

Qwen Code is one of the agents magpie connects too: its row takes Qwen’s models or any other vendor’s.

## Thinking and images

- **Whole replies..** DashScope answers a thinking Qwen model only as a stream, and turns away a request for one whole reply. When an agent or a routing group’s classifier asks for one, magpie asks DashScope for a stream and gives the agent the whole reply, thinking included.
- **Models that always think..** Some models on DashScope refuse to have thinking turned off, such as its `glm-5.3`. When an agent asks for it off and the model refuses, magpie asks again with thinking left on.
- **Images..** The Qwen-Image and `wan2.7-image` models draw through DashScope’s own image API, on any of the six presets. Choose one in magpie’s Settings → Models → Images. Give a size as `WIDTHxHEIGHT`, at most 2048×2048.

## Balance and usage

magpie shows no balance or plan card for Qwen: DashScope has no API for a key’s balance, and neither Token Plan has one for its credits, which the plan’s subscription page in Alibaba’s console shows. The Usage tab counts tokens, cache hits and cost for each agent and model that went through magpie.

## FAQ

### How do I use Qwen in Claude Code?

Add your key in magpie (Providers, Add provider, then the Qwen preset your key is from), then pick a Qwen model such as `qwen3.8-max` on Claude Code’s row, or run `magpie claude qwen/qwen3.8-max`. magpie writes Claude Code’s `settings.json` and passes its requests to DashScope’s Anthropic endpoint.

### Can Codex use Qwen, Qwen3 Coder included?

Yes. magpie lists the models DashScope gives your key, coder models included, and Codex can use any of them: magpie translates Codex’s Responses requests to Chat Completions and the replies back. Pick the model on Codex’s row or run `magpie codex qwen/qwen3.8-max`; it shows in Codex’s `/model` list.

### Which preset do I pick for my key?

The one whose site the key is from. A Token Plan key (`sk-sp-…`) works only on its own plan’s host, and a Qwen Cloud pay-as-you-go key (`sk-ws-…`) only in its own region, so a key added to another preset is turned away with 401.

### Can Qwen Code use other models?

Yes. Qwen Code is one of the agents magpie connects, so its row in the Agents tab takes any model you have added, Qwen’s or another vendor’s.

### Why does a Qwen request without streaming work in magpie?

DashScope turns away a thinking Qwen model asked for one whole reply (`enable_thinking` must be false for non-streaming calls). magpie asks for it streamed and hands the agent the whole reply, thinking included.

### Does magpie show my Token Plan credits?

No. Neither Token Plan has an API for its credits; the plan’s subscription page in Alibaba’s console shows them. magpie’s Usage tab still counts the tokens each agent spent.

Every agent: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Models in Codex](https://usemagpie.ai/docs/codex-models), [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models), [Models in OpenCode](https://usemagpie.ai/docs/opencode-models). Ask on [Discord](https://discord.gg/vGSnD3ZKQF) if you get stuck.

---

Source: https://usemagpie.ai/docs/minimax

# MiniMax and the MiniMax Coding Plan in Claude Code, Codex, Gemini CLI and OpenCode

MiniMax serves an OpenAI-compatible Chat API and an Anthropic-compatible one, on a global site and a China site, for pay-as-you-go keys and Coding Plan keys alike. Add your key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use models such as `MiniMax-M3` and `MiniMax-M2.7` through magpie’s gateway at `127.0.0.1:3425`.

## Add MiniMax

1. **Get a key.** Create one at [platform.minimax.io](https://platform.minimax.io/user-center/basic-information/interface-key), or [platform.minimaxi.com](https://platform.minimaxi.com/user-center/basic-information/interface-key) for the China site. A Coding Plan key starts with `sk-cp-`.
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick MiniMax or MiniMax (China), paste the key and save. A pay-as-you-go key and a Coding Plan key go in the same way.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose a MiniMax model.

```
magpie provider add minimax sk-…        # platform.minimax.io
magpie provider add minimax-cn sk-cp-…  # Coding Plan, platform.minimaxi.com
```

## Plans and endpoints

| Preset | Site | Chat Completions | Anthropic Messages |
| --- | --- | --- | --- |
| MiniMax minimax | platform.minimax.io | `https://api.minimax.io/v1` | `https://api.minimax.io/anthropic` |
| MiniMax (China) minimax-cn | platform.minimaxi.com | `https://api.minimaxi.com/v1` | `https://api.minimaxi.com/anthropic` |

The Coding Plan uses the same endpoints as pay as you go; the key decides which one a request is billed to. A global key and a China key are different accounts, so each goes under its own site’s preset.

## In each agent

Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.

```
magpie claude minimax/MiniMax-M3
magpie codex minimax/MiniMax-M3
magpie gemini model minimax/MiniMax-M2.7
magpie opencode minimax/MiniMax-M3
```

- **Claude Code.** speaks Anthropic Messages, and so does MiniMax’s Anthropic endpoint, so its requests are passed on as they are. Every tier (opus, sonnet, haiku) runs on the model you pick unless you give one its own. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses. MiniMax serves Chat Completions and Anthropic Messages but not Responses, so magpie translates each request and the reply, streaming and tool calls included. The model shows in Codex’s `/model` with its reasoning efforts. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Gemini’s API. magpie points it at its gateway and translates. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** gets the model in `opencode.json`, with its reasoning variants and cost. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

MiniMax Code is one of the agents magpie connects too: its row takes MiniMax’s models or any other vendor’s.

## Thinking and effort

- **Interleaved thinking..** MiniMax’s Chat API gives a model’s thinking in the reply text, between `<think>` tags, and wants it back there on later turns. magpie hands it to the agent as thinking and puts it back where MiniMax expects it.
- **Effort..** `MiniMax-M3.1-Flash` and its preview think at levels from low to max. magpie sends the level an agent asks for in `output_config.effort`, as MiniMax Code does, so it isn’t lost to a token budget.
- **Models that always think..** `MiniMax-M3.1-Flash-Preview` refuses to have thinking turned off. When an agent asks for it off, magpie asks again with thinking left on, so the agent gets an answer rather than the error.

## Coding Plan windows and usage

- **Coding Plan windows..** A Coding Plan key’s row shows what is left of each window MiniMax reports, a rolling one and a weekly one, read from MiniMax. Models draw on the general bucket; a bucket metered apart, such as video, shows as a count, like 4 / 5. A pay-as-you-go key has no windows and no card.
- **Routing..** With several Coding Plan keys, magpie weighs them by their windows and rests one that has used a window up until it resets.
- **Usage..** The Usage tab counts tokens, cache hits and cost for each agent and model that went through magpie.

## FAQ

### How do I use MiniMax M2.7 or M3 in Claude Code?

Add your MiniMax key in magpie (Providers, Add provider, MiniMax or MiniMax (China)), then pick a model such as `MiniMax-M3` on Claude Code’s row, or run `magpie claude minimax/MiniMax-M3`. magpie writes Claude Code’s `settings.json` and passes its requests to MiniMax’s Anthropic endpoint, `https://api.minimax.io/anthropic`.

### How do I use the MiniMax Coding Plan?

Add the Coding Plan key (`sk-cp-…`) to the MiniMax preset of the site you bought it on, the same as a pay-as-you-go key. magpie tells the two apart by what MiniMax says about the key, and shows a Coding Plan key’s usage windows on its row.

### Can Codex use MiniMax?

Yes. MiniMax serves Chat Completions and Anthropic Messages but not Responses, so magpie translates Codex’s requests and MiniMax’s replies. Pick the model on Codex’s row or run `magpie codex minimax/MiniMax-M3`; it shows in Codex’s `/model` list.

### Can MiniMax Code use other models?

Yes. MiniMax Code is one of the agents magpie connects, so its row in the Agents tab takes any model you have added, MiniMax’s or another vendor’s.

### Why does MiniMax’s thinking show up in the text?

MiniMax’s Chat API puts a model’s thinking in the reply text between `<think>` tags. magpie takes it out and gives it to the agent as thinking, then puts it back on the next turns, where MiniMax wants it.

### Can I use several MiniMax keys?

Yes. Add them all to the MiniMax provider and tick each one. magpie spreads requests over them, and weighs and rests Coding Plan keys by their windows, so a key that has used up its window sits out until it resets.

Every agent: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Models in Codex](https://usemagpie.ai/docs/codex-models), [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models), [Models in OpenCode](https://usemagpie.ai/docs/opencode-models). Ask on [Discord](https://discord.gg/vGSnD3ZKQF) if you get stuck.

---

Source: https://usemagpie.ai/docs/intent

# Intent routing

Send a turn to a model by what the user asks for: tests to the strong model, quick questions to the fast cheap one. You describe each kind in a few words. When a turn begins, a small model you choose picks which kind the message is.

Intent is one of the conditions a [routing group’s rule](https://usemagpie.ai/docs/start#rules) can have, next to length, images, reasoning and agent. This page describes exactly what magpie does with it, as of v0.1.99, so you can predict every decision and check it in the Routing tab.

> **In one paragraph.** magpie decides once per turn: when you send a message, not while the agent works through tool calls. If a rule with an intent could be the first to match, magpie asks the group’s *classifier* model one short question through its own gateway. The question holds the intents as a numbered list plus the text of your latest message, and the classifier answers with a number. magpie reads that number and checks the rules top first with it. The first rule that matches puts its model first, and the group’s other models stay behind it for failover. The turn then stays on that model until you speak again. If the classifier fails, times out or answers something else, no intent matches and the turn is routed as if those rules weren’t there. There are no embeddings, no keyword lists and no training: the model you pick reads your message and picks a number.

## Set it up

You need a [routing group](https://usemagpie.ai/docs/start#routing) with at least two models, and one more model to classify with. The classifier can be any model magpie has, in the group or not.

1. **Open the group.** Go to Routing, find the group under *Routing groups* and click Edit.
2. **Add a rule with an intent.** Click Add a rule. The new rule reads asks for → a model, with the intent box ready: type what the message asks for, such as *writing or fixing tests*, then pick the model after →. More conditions come from the rule’s +, and must hold too.
3. **Pick the classifier.** Intent told by appears once a rule has an intent, set to Jev when you have a TypeSafe provider. Otherwise choose a small, fast model without reasoning. A group whose effort Jev already picks offers the same under its classifier: It can pick the model too. A group can’t be saved with an intent and no classifier.
4. **Save, and send a message.** Changes apply from the next turn, with no restart. The Routing tab shows what the classifier said and where the turn went.

The timeout is global: in Settings → Models → Replies → Intent classifier timeout, choose 8, 15, 30 or 60 seconds. It defaults to 8 seconds and applies to the next classifier call, including Jev, with no restart. A slow classifier may need longer, but the turn waits for it before routing. In `~/.config/magpie/settings.json`, `"classifyTimeout"` accepts whole seconds from 1 to 60; 0 or a missing field uses 8. A custom value in that range appears as its own choice in Settings.

The same from a terminal:

```
magpie group rule add coder use=deepseek/deepseek-v4-flash intent="a quick question" classifier=groq/llama-3.1-8b-instant
magpie group rule add coder use=deepseek/deepseek-v4-pro intent="writing or fixing tests"
magpie group rule add coder use=deepseek/deepseek-v4-pro use-effort=low intent="a simple edit"   # the same model, asked for low reasoning
magpie group rule coder                           # the rules, numbered, and the classifier
magpie group rule classifier coder groq/llama-3.1-8b-instant   # change the classifier
magpie group rule mv coder 3 1                    # order matters: top first
magpie group rule rm coder 2
```

`intent=` also takes the spellings `asks=` and `about=`. `classifier=` also takes `classify=` and `by=`. `classifier=` on `rule add` sets the group’s classifier and is needed only the first time. The classifier is saved in the group’s record in `~/.config/magpie/providers.json` as `"classifier"`, and each rule as `{"use": …, "intent": …}`.

A rule can also set the reasoning its model is asked for, so an intent picks the model and the effort as a pair: `use-effort=` (`low`, `medium`, `high`, `xhigh` or `max`), saved as `"useEffort"`, such as `{"use": "deepseek/deepseek-v4-pro", "intent": "a simple edit", "useEffort": "low"}`. In the editor it is set from the rule’s ⋯ menu, Set its reasoning, and shows beside the model. The rule’s model is then asked for that effort on the turn’s requests, whatever the agent asked, at the model’s nearest level. A model whose levels magpie doesn’t know is asked as the agent asked, and so are the models the group fails over to. A model fixed at an effort in the group keeps its own. Without it, the model is asked as the agent asked. The Routing tab says when a rule set the effort.

## How a turn is routed

Every request an agent sends to a group with rules goes through these steps, in this order:

1. **Is this a new turn?.** magpie looks at the request’s last user message. If it carries text or an image and no tool result, you just spoke, so a new turn begins. If it carries tool results, the agent is continuing a turn already under way (see The rest of the turn). Turns are counted per conversation. A subagent is its own conversation: it shares its agent’s session but starts with different words.
2. **Which intents could decide?.** magpie walks the rules top first and ignores intent for now: a rule is a candidate if its other conditions (tokens, images, reasoning, agents) hold for this request. Each candidate’s intent is collected, and duplicates spelled the same apart from case count once. The walk stops at the first candidate *without* an intent, because that rule matches outright and nothing below it could come first. If no intents were collected, the classifier isn’t asked and costs nothing.
3. **Ask the classifier.** magpie sends the classifier the collected intents and the text of your message. The exact prompt is shown below. The call goes through magpie’s own gateway, like a request from an agent, so it uses that model’s provider with its keys or accounts and their failover. It has the configured timeout to answer (8 seconds by default).
4. **Read the answer.** magpie takes the first whole number in the reply. `1` to `n` names that intent, and `0` means none of them. Anything else, such as no number or one out of range, counts as a failure. The answer is kept for 10 minutes for the same message and intents.
5. **Match the rules.** The rules are checked top first with the answer. A rule with an intent matches only when the classifier named its intent, compared without case, and all its other conditions hold. The first rule that matches wins. If none matches, the group routes the turn as it always does.
6. **Order the models.** The winning rule’s model goes first, and the group’s other models follow in their usual order as failover. This holds even if another model answered the conversation’s last turn: a rule outranks the Stays setting as a turn begins. If the rule’s model has nothing ready right now (every key resting, the provider off), the group’s usual order stands and the trace says so.
7. **Remember the decision.** magpie keeps the decision for this conversation (the group, the agent’s session and the conversation’s first words) with the classifier’s answer, so the rest of the turn follows it.

### An example

The Coder group above has three rules:

| # | When | Send to |
| --- | --- | --- |
| 1 | ≥ 128000 tokens | kimi/kimi-k2.5 |
| 2 | asks for “a quick question” | deepseek/deepseek-v4-flash |
| 3 | asks for “writing or fixing tests” | deepseek/deepseek-v4-pro |

- A 20k-token turn: rule 1 doesn’t hold, so both intents are candidates. The classifier is asked to choose between “a quick question” and “writing or fixing tests”.
- A 150k-token turn: rule 1 has no intent and holds, so the walk stops there. The classifier isn’t asked, and the turn goes to Kimi.
- The classifier says `0` (none): no rule matches, and the turn goes by the group’s routing (here *In order*, so deepseek-v4-pro first).

### In the app

A real request through a group with two intent rules (“a quick question or explanation, with no code to write or change” and “writing or fixing tests”), sent from Claude Code: “Add unit tests for the LRU cache in cache.go, covering eviction and concurrent reads and writes”. The Routing tab shows it as it happens.

## What the classifier sees

This is the whole request, and nothing else is sent. The system message is fixed. The user message lists your intents in rule order, as they were collected in step 2:

```
You route a user's message to a coding assistant by what it asks for. Given numbered kinds of request and the user's message, answer with the number of the kind the message is, or 0 if it is none of them. Answer with the number only.
```

```
Kinds:
1. a quick question
2. writing or fixing tests

The user's message:
<message>
Write unit tests for the parseTokens function and fix any that fail.
</message>

The number of its kind (0 for none):
```

- **Only your latest message..** magpie sends the text parts of the last user message and nothing else: no earlier turns, no system prompt, no tool definitions, no files.
- **Images aren’t sent..** A message that is only an image has no words to classify, so no intent matches. To route by images, use the rule’s has an image condition.
- **Agent reminders are removed..** `<system-reminder>…</system-reminder>` blocks, which Claude Code adds to your message, are stripped. Other text an agent puts in the same message is kept.
- **Long messages are shortened..** Over 4,000 characters, magpie keeps the first 3,000 and the last 1,000, joined by `…`. The start and the end usually say what is being asked.
- **The request settings..** An OpenAI-style chat completion, not streamed, with `temperature 0`, `max_tokens 2048` and User-Agent `magpie-router/1`. When magpie knows the classifier’s reasoning levels, it asks for the least: `none` if the model has it, else its lowest level (for example `low`). When the levels aren’t known, nothing is sent and the vendor’s default applies. magpie translates it for the classifier’s provider, like any other request, so an Anthropic, Gemini or other model works too.

## When it can’t say

A classifier is a helper, not a gate. Whatever happens to it, the turn is still answered: the intent rules just don’t match.

| What happens | What magpie does |
| --- | --- |
| It answers `0` | No intent matches. Rules without an intent and the group’s usual order decide. |
| No answer within the configured timeout | Treated as a failure: no intent matches, and the turn goes on at once. |
| An error (quota, 5xx, bad key) | Its provider’s own failover is tried first, within the configured timeout. If it still fails, no intent matches. |
| An answer that isn’t a number from 0 to n | No intent matches this turn. The classifier did answer, so it isn’t rested: the next turn asks it again. |
| An error or a timeout | That classifier model is left alone for 30 s: turns in that time don’t wait on it, and the trace says it wasn’t asked. The first good answer clears this. |
| The message has no words | Not asked. No intent matches. |

Each case is written in the turn’s trace with the reason. An intent rule can therefore make a turn go to a different model than you hoped, but it can’t make it fail.

## The rest of the turn

A turn is often dozens of requests: the agent calls a tool, sends the result back, calls another, and so on. magpie deals with them like this:

- **Held..** Every request within the turn goes to the model the turn began on, and the classifier isn’t asked again. Switching models mid-turn would throw away what the vendor cached of the conversation (prompt caching), and some vendors reject reasoning that another one wrote.
- **Failover sticks..** If the rule’s model failed and another member answered, that member keeps the rest of the turn (with Stays on *Auto*, *Session* or *Within a turn*). The rule decides again at your next message.
- **Outgrown..** The one exception: if the conversation grows within the turn to 95% of the current model’s context, magpie checks the rules again, keeping the classifier’s earlier answer. If a rule sends it to a model with *more* context, it moves. It never moves to a model with less.
- **Waits..** If magpie didn’t see the turn begin (it was started or restarted in the middle of one), or the rule that decided it was removed or now sends to another model, no rule moves the turn. The rules decide again at your next message.
- **Subagents..** A subagent’s turns are decided on their own, from the subagent’s own messages. A rule can send a subagent elsewhere while its agent stays where it is.

Decisions are kept in memory for 24 hours after a conversation’s last request. Restarting magpie clears them, and the next message decides afresh.

## Reading the trace

The Routing tab shows each group’s latest request: who answered it, and under How the last request was routed, why.

The lines you can see about intent:

| The trace says | Meaning |
| --- | --- |
| … was asked which of “A”, “B” turn 1 is, and said “B” (in 323 ms). | The classifier was asked, with these candidates, and named B. |
| … and said none (…). | It answered 0. |
| … (said before, for the same message). | The answer came from the 10-minute cache, so no call was made. |
| … was to tell which … but couldn’t — *reason* — so no rule with an intent matches it. | It failed. The reason is the error, the timeout, what it answered, or that it is resting after a failure. |
| Turn N begins and rule R matches — asks for “B” — so M goes first … | The rule that won, and the model put first. |
| Rule R matches, but M has no account or key that can take this request, so the group’s order stands. | No account or key for the rule’s model can take this request. |
| Rule R (…) sent turn N to M as it began; the turn stays there. | A tool round within the turn, held on its decision. |
| This turn began before magpie saw it, so the rules wait for the next one. | See *Waits* above. |

The classifier’s own calls appear in Usage under the agent *magpie*, with their tokens and cost, so you can see what classifying costs.

## Latency, cost, privacy

- **Latency..** Only the first request of a turn waits for the classifier, typically a few hundred milliseconds on a fast provider (323 ms in the screenshot) with a configured timeout of 8 seconds by default. Tool rounds within the turn, turns where no intent could decide, and cached answers add nothing.
- **Cost..** One short call per turn: roughly the size of your message plus the intents in, and one or two tokens out. In the example above that was 212 tokens in and 1 out. With a subscription model as the classifier, these calls count against that subscription’s limits.
- **Privacy..** The text of your message (up to about 4,000 characters) goes to the classifier’s provider. To keep it on your machine, use a local model from Ollama or LM Studio as the classifier. magpie keeps only a hash of the message and the answer, in memory, for 10 minutes. The message itself isn’t stored or logged.

## Writing good intents

- **Describe the request, not the model..** Write “writing or fixing tests”, not “hard tasks for Opus”. The classifier sees only your words and the message.
- **Keep kinds apart..** If two intents overlap (“a question”, “a question about the code”), a small model will choose between them unpredictably. Merge them, or make the difference plain.
- **Few and broad beats many and narrow..** Two to five intents are easy for an 8B model. Up to 200 characters each is allowed, but a few words are usually enough.
- **Order still matters..** Only the first matching rule counts, so put a rule that must win (such as a long-context rule) above the intent rules. The classifier is then skipped whenever that rule holds.
- **“None” is a real answer..** A turn that fits no intent goes to the group’s usual order, so let that order be your default choice.
- **Any language..** Intents and messages can be in any language the classifier understands. The fixed prompt is in English, and small models read mixed languages well.
- **Choosing a classifier..** Pick a small, fast model without reasoning: Llama 3.1 8B on Groq, a Flash-Lite, nano or mini model, Claude Haiku, DeepSeek’s non-reasoning chat model, or a local model. A reasoning model is slower; magpie asks it for its least reasoning and leaves it 2048 tokens, but a slow one can still miss the configured timeout. Check the trace for a few turns: if it guesses wrong, rewrite the intents before switching models.

## Numbers

| What | Value |
| --- | --- |
| Classifier timeout | 8 s by default; configurable from 1 to 60 s, including its provider’s failover |
| Rest after a failure | 30 s, per classifier model |
| Answer cache | 10 min, per classifier + intents + message; in memory |
| Turn decisions kept | 24 h after the conversation’s last request; in memory |
| Message sent | Up to 4,000 characters; longer is first 3,000 + last 1,000 |
| Classifier request | temperature 0, max_tokens 2048, the least reasoning the model has, not streamed |
| Intent length | Up to 200 characters; spaces collapsed, compared without case |
| Outgrown | At 95% of the current model’s context, only to a model with more |

## FAQ

### Is this embeddings or a vector search?

No. There is no embedding model, no similarity threshold, no keyword list and nothing to train. The classifier is an ordinary chat model that reads your intents and your message and answers with a number. It is only as good as that model and your wording, and the trace shows every answer.

### Does it look at the whole conversation?

No, only the message you just sent. So a follow-up like “now do the same for the other file” is judged on those words alone. Give that turn a clearer message, or add an intent that fits follow-ups.

### My agent made 40 requests for one message. Was the classifier asked 40 times?

No, once. The other 39 carried tool results, so they belong to the same turn and follow its decision. You can see this in the trace (“the turn stays there”) and in Usage (one *magpie* call).

### Can a turn switch models halfway?

Only in two cases: the model it is on fails and another member takes over, or the conversation outgrows the model’s context and a rule sends it to one with more room. Intent is never re-asked mid-turn.

### What if the classifier is down or slow?

The turn still goes through. After waiting up to the configured timeout (8 s by default), no intent matches and the group’s other rules and order decide. For the next 30 s magpie doesn’t ask that classifier again, so turns don’t each wait out the timeout. The trace gives the reason.

### Why did the turn not go to the rule’s model when the classifier named its intent?

Check the trace. The usual causes are:

- a rule above it matched first;
- another condition on the rule didn’t hold (tokens, images, reasoning or agent);
- no account or key for the rule’s model could take this request;
- it was a tool round in a turn that began elsewhere;
- magpie didn’t see the turn begin (“the rules wait”).

### Two rules have the same intent. What happens?

The intent is offered to the classifier once. If it is chosen, the first of those rules whose other conditions hold wins. Use this to send, for example, “writing or fixing tests” from Codex to one model and from Claude Code to another.

### Does changing a rule affect a turn already running?

No. Saving applies from the next turn. A turn whose rule you removed, or pointed at another model, keeps where it is until then; the trace says the rules wait.

### Can the classifier be a routing group, or one of the group’s own models?

It can’t be a group: it must be one model, `provider/model`, which magpie checks when you save. It can be any model magpie has, including one of the group’s members, a subscription model or a local model.

### Can I use a reasoning model?

Yes, if it answers within the configured timeout (8 s by default). magpie asks it for the least reasoning it has (`none`, else its lowest level) and leaves 2048 tokens, so thinking doesn’t crowd out the answer. A small, fast model is still the better choice: cheaper, and every turn waits for it.

### How well does it work with real models?

We ran 20 real coding messages (English and Chinese: quick questions, test work, and ordinary coding tasks, including “Fix the bug in parseTokens and add a test for it”) through a group with two intent rules. DeepSeek V4 Flash, GLM-5.3 Flash and MiMo v2.6 Flash each classified all 20 correctly; the median classifier time was 0.75 s, 1.3 s and 1.9 s. Gemini 3.8 Flash through one reseller took 11 s even at `low` reasoning, so with the default 8 s timeout every turn timed out and routed as if there were no intents — the trace said so each time. That is the pattern to expect: a wrong classifier costs you the routing, never the turn.

### Does retrying the same message ask again?

Not within 10 minutes: the same message with the same intents and the same classifier is answered from the cache, and the trace says “said before”. Changing an intent or the classifier makes it ask again.

### Which agents does it work with?

Any agent that sends to a routing group through magpie: Claude Code, Codex, OpenCode, Gemini CLI and the rest. Turns are detected from the request itself (a message with text and no tool results), whatever API the agent speaks.

### Is my message stored anywhere?

magpie keeps a hash of it (for the cache) and the classifier’s answer, in memory only. The text goes to the classifier’s provider, like any request, under that provider’s terms. The classifier’s usage record holds its token counts, not the text.

### How accurate is it?

That depends on the classifier and on how distinct your intents are. With a few clearly different kinds, a small model picks well; with overlapping ones it will sometimes guess. Since a wrong or missing answer only changes which model answers, start with two or three broad intents, watch the trace for a day and adjust the wording.

Questions or a setup worth sharing? Ask on [Discord](https://discord.gg/vGSnD3ZKQF). Routing groups in general are covered in [Get started](https://usemagpie.ai/docs/start#routing).

---

Source: https://usemagpie.ai/docs/masking

# Privacy masking

magpie can mask what your agents send before it leaves this computer. API keys, passwords and tokens, and when you ask, emails, phone numbers and words of your own, go to the vendor as placeholders such as `{{API_KEY_es6eu6jk}}`. In the reply each placeholder turns back into its value, so your agent and your files keep the real thing and the vendor never sees it. It runs on this computer, in magpie’s gateway, and is **off by default**.

> **It covers what goes through magpie.** An agent [connected to magpie](https://usemagpie.ai/docs/start) sends its requests through the gateway, and they are masked whichever provider or account answers. An agent that calls a vendor directly, not through magpie, is not covered.

## Turn it on

1. **Open the page.** Go to Settings → Privacy.
2. **Mask secrets.** Under What to mask, set Mask secrets to On: API keys, private keys, tokens and passwords.
3. **Personal data, if you want it.** Set Mask personal data to On for emails, phone numbers, ID and bank card numbers. Each further kind of personal data then gets its own switch below it.
4. **Your own words.** In Masked words, list names, codenames or hosts to keep from vendors, one on each row (several pasted with commas between become a row each). Masked words in any case makes *Nightjar* mask *NIGHTJAR* too. A secret magpie doesn’t know, such as your gateway’s own keys, goes under Masking rules: what it starts with, or a regular expression.
5. **Try it.** Paste a text into Try it to see exactly what the vendor would get. What you paste there isn’t kept.

It applies from the next request, with no restart and nothing to change in your agent. The work is done by the built-in plugin Privacy masking (`redact`, in Settings → Plugins), which is on whenever any masking is asked for.

There is no CLI command for it. Without the window (`magpie serve`, [Docker](https://usemagpie.ai/docs/docker)), open the same page with `magpie web`, or set it in `~/.config/magpie/settings.json` (`/config/magpie/settings.json` in Docker). The masker reads the file on every request:

```
{
  "redact": true,
  "redactPersonal": true,
  "redactWords": ["Nightjar", "db.acme-corp.cn"]
}
```

## What is masked

| Switch | What it finds |
| --- | --- |
| Mask secrets | Private key blocks (`-----BEGIN … PRIVATE KEY-----`). API keys by their shape: `sk-…` (OpenAI, Anthropic, OpenRouter), `ghp_`/`github_pat_`, `glpat-`, `AIza…`, `xox…-`, `sk_live_`, `AKIA`/`ASIA`, `hf_`, `gsk_`, `xai-`, `npm_`, `pypi-`, `dop_v1_`, `SG.`, and relay keys like `oc_sk_…`. JWTs. The password in `user:password@host`. The value of a field named for a secret, as `.env` files and configs have them: `DB_PASSWORD=…`, `api_key: …`, `client_secret`, `token`, `credential`. Your own Masking rules. |
| Mask personal data | Emails, mainland China mobile numbers (not an 11-digit id: one under `order_id` or after 订单号 goes as written), Chinese ID numbers and bank card numbers whose checksum adds up. Also on by default: US Social Security numbers, passport numbers (after *passport*, 护照 or パスポート), IBANs, birthdays (next to *birthday*, *DOB* or 生日, and over a year ago, so today&rsquo;s date stays), MAC addresses and serial numbers (after *S/N*). Off until you turn them on, since agents send them in nearly every request: the user name in home folders (sent as a made-up name, the same every turn, so the model reads a real folder rather than a placeholder), user and computer names (`user@host`), public IP addresses (sent as a name such as `public-ip-kvxqmrtz`, so the model still knows the address is public and connects with it, and the real address goes back into its commands) and cloud storage buckets. A wallet or contract address (`0x` and 40 hex digits) is public and goes as written; a private key is still masked. |
| Masked words | Each word you listed, exactly, as `{{TERM_…}}`. A date, such as *1990-05-12*, matches that day however it is written: *1990/5/12*, *1990.05.12*, *1990年5月12日*, *19900512*, *May 12, 1990*, and *13/05/1990* style only where the day can’t be read as a month. Never another date or a version like *1990.5.12.1*. |
| Find with a local model | Under How it’s found. A model on this computer finds what no rule can: a name or an address in free text. It is on unless you turned it off, and AstrLink Guard downloads with the first masked request; until it is on disk, the rules mask alone. It needs Mask secrets or Mask personal data on, and finds under the same switches. The menu beside it picks the model: AstrLink Guard (Chinese and English, a 39 MB download, few false alarms in code, on a Mac it runs on the Neural Engine; the default) or OpenAI’s Privacy Filter (1.6 GB, uses the GPU, masks more ordinary values in code). Confidence threshold under it is how sure the model must be before a value is masked: Privacy Filter’s default is 0.5, AstrLink Guard’s 0.8, its publisher’s. Higher masks fewer ordinary values, and lets more real names and addresses through: the rules after the model drop most false alarms already, so the default is where we measured the fewest real values lost. |

A placeholder is the kind plus eight characters of a keyed hash. The same value gets the same placeholder every time, so the conversation reads the same turn after turn and the vendor’s prompt cache stays valid. The values are held in memory only.

## An example

With Mask secrets and Mask personal data on and *Nightjar* in Masked words, your agent sends:

```
Deploy Nightjar with OPENAI_API_KEY=sk-proj-8fK2mQx7Lp4Rt9Vw3Yz6Ab1Cd, then mail li.wei@acme-corp.cn or call 13800138000.
```

```
Deploy {{TERM_5hmsrhdc}} with OPENAI_API_KEY={{API_KEY_srhjgvja}}, then mail {{EMAIL_eh5um6mb}} or call {{PHONE_uf7iy2qq}}.
```

When the model answers *“I set OPENAI_API_KEY to {{API_KEY_srhjgvja}} in .env”*, your agent reads the real key there, in streamed text and tool-call arguments alike, so the file it writes has the real key. A placeholder the model rewrote a little (spaces inside the braces, another case) is still turned back.

## Check that it works

- **Before:.** Try it on Settings → Privacy shows the text as the vendor would get it, with each value’s kind.
- **Each request:.** a shield badge with a count appears on the request in the Gateway page’s recent calls and in the Routing log. Point at it for the kinds; click it to open the request’s record.
- **Over time:.** Insights → Masking (also What was masked on the Privacy page) shows the values masked over 7 or 30 days by kind, agent and provider, and each request’s text as the vendor saw it, placeholders marked.

The records are kept in `~/.config/magpie/masking` for 30 days: the agent, provider, model, and each placeholder’s kind, length and first characters, never the value.

## When a value is found

Under When a value is found, choose per kind:

- Mask (the default): sent as a placeholder.
- Warn: sent as written, and the badge counts it in amber.
- Block: the request is held back with a 400, *“magpie held this request back: Settings › Privacy blocks API_KEY, and it has one (sk-…, 33 characters). Nothing was sent.”* The message never has the value.

A value the task needs as it is, such as a team address or a test key, goes in Never mask: it is sent as written wherever it is found whole.

## What it leaves alone, and limits

- **Thinking stays as the vendor wrote it..** A thinking block with its signature, Gemini’s thoughts and Responses’ encrypted reasoning are sealed by the vendor and go back unchanged, so the signature still matches. Only values already masked elsewhere in the request are swapped in them.
- **Ids and tool definitions go as written:.** model ids, message and call ids, UUIDs, tool names, MCP server names, and tool schemas (their descriptions are masked), so a vendor or a tool can still check them.
- **Images and file data are sent as they are..** Text inside a screenshot is not masked.
- **It fails closed..** If masking is on and can’t run (the Privacy masking plugin turned off by hand, or the local model you turned on can’t answer), the request gets a 503 that says nothing was sent. It is never sent unmasked instead. The model on by default that can’t answer leaves the rules to mask alone.
- **A provider can skip it..** Send requests unmasked on a provider sends its requests as written: a model on this computer or your local network (Ollama, LM Studio), and, if you choose, any other provider, a subscription or a plugin’s provider too. Turned on for one that isn’t local, the editor says its vendor gets your requests unmasked. A request that can fall back to a provider still masked is masked. `magpie provider set ollama unmasked=yes` does the same.
- **Or send what masking would change to one of them..** In Settings › Privacy, Instead of masking, send to picks such a model. An agent’s request that masking would change then goes to it as written, so it can answer about the real names, and a request with nothing to mask goes where it was going. If that model fails, the request fails: it is never masked and sent to a vendor instead. Off by default.
- **The model sees placeholders..** It can’t read or reason about a masked value; it can only pass it on. Put a value it must read under Never mask.
- **Rules find shapes..** A phone number in another country’s format or a name in free text needs Find with a local model, or your own Masked words and Masking rules. Try your own text in Try it first.

See also [Privacy](https://usemagpie.ai/docs/privacy) for everything magpie sends by itself. The code is [internal/redact](https://github.com/yetone/magpie/tree/main/internal/redact) and [internal/masking](https://github.com/yetone/magpie/blob/main/internal/masking/masking.go).

---

Source: https://usemagpie.ai/docs/library

# Library

magpie’s Library keeps instructions, MCP servers, skills, hooks and subagents in one place, and writes each of them into every agent you tick for it, in that agent’s own files and format. The agents read those files as they always do. magpie adds no layer between an agent and what it is given: the agent itself decides when to use a skill, an MCP tool or a subagent.

The page has six tabs: Instructions, MCP servers, Skills, Hooks, Subagents and RTK. Each item has a row of agents; tick an agent to give it the item, untick it to take it away. An agent reads the change when it starts again.

## Where it is kept

- **The library.** is `library.json` in magpie’s config folder (`~/.config/magpie`, or `$XDG_CONFIG_HOME/magpie` when that is set). Instruction texts and skill folders are in `library/` next to it.
- **Every change.** saves the library and writes it into every agent at once. magpie records what it wrote, so it only ever takes away its own entries and leaves yours alone.
- **Backups..** Before a change, the files it replaces are copied to `backups/` in the same folder. The last 30 are kept. The Backups button at the top of each tab opens them.
- **Write it again..** After you install an agent, or edit its files by hand, `magpie library sync` writes the library into every agent again.

```
magpie library          # what the library gives each agent
magpie library sync     # write it into the agents again
```

## Instructions

Instructions are text every session of an agent starts with, such as house rules or a coding style. magpie writes its part between two marker lines in the agent’s instructions file:

```
<!-- magpie:begin · written by magpie from its Library -->
…the Library's instructions…
<!-- magpie:end -->
```

Everything outside the markers is yours and is never changed. You can keep several named sets and give each set to different agents, and a set can live in a file of your own.

| Agent | File |
| --- | --- |
| Claude Code | `~/.claude/CLAUDE.md` |
| Codex | `~/.codex/AGENTS.md` (or `AGENTS.override.md` when you use one) |
| Gemini CLI | `~/.gemini/GEMINI.md` |
| Antigravity | `~/.gemini/config/GEMINI.md` |
| OpenCode | `AGENTS.md` in its config folder |
| Copilot CLI | `~/.copilot/copilot-instructions.md` |
| Goose, Crush, Qwen Code, CodeBuddy | `.goosehints`, `CRUSH.md`, `QWEN.md`, `CODEBUDDY.md` |
| Droid, Grok, dsh, omp | `AGENTS.md` in the agent’s own folder |
| Pi, OmO | the first one there of `AGENTS.md` and `CLAUDE.md` |

Folders follow the agent’s own setting: a custom `CLAUDE_CONFIG_DIR` or `CODEX_HOME` is used in place of the default.

## MCP servers

An MCP server is either a command (a program the agent starts, such as `npx …`) or a URL (HTTP or SSE). magpie writes one entry per server into each ticked agent’s MCP config, in that agent’s format, and keeps any fields you added to the entry yourself.

| Agent | File |
| --- | --- |
| Claude Code | `~/.claude.json` |
| Codex | `~/.codex/config.toml` |
| Gemini CLI | `~/.gemini/settings.json` |
| Antigravity | `~/.gemini/config/mcp_config.json` |
| OpenCode | `opencode.json` |
| Cursor | `~/.cursor/mcp.json` |
| Copilot CLI | `~/.copilot/mcp-config.json` |
| Zed | `context_servers` in its `settings.json` |

- **Variables..** `${NAME}` in a header or an env value is written in each agent’s own syntax. An agent that has no such syntax is not given that server, and the page says why.
- **SSE..** Codex, Goose, dsh, Grok, Command Code and Zed can’t use an SSE server. Claude Desktop takes no remote servers at all.
- **Single tools off..** You can turn off tools one by one for Codex, Gemini CLI, Crush, Hermes Agent, Claude Code and OpenCode, each in its own setting. Every other agent gets the whole server.
- **Sign-in..** A server that needs OAuth is signed in to once, in magpie. Agents then reach it through magpie’s gateway at `/mcp/<name>`.
- **This computer only..** Turn off Sync to your other computers for a server that should stay here (`magpie library mcp local <name> on`).

With the [MCP router](https://usemagpie.ai/docs/mcp-router) on, each agent gets one server named `magpie` in place of these entries, and magpie runs each command server once for all of them. It is off by default.

## Skills

A skill is a folder with a `SKILL.md` in it. The agent reads each skill’s name and description and loads the rest when a task needs it. Add one from GitHub, any git repository, a folder on this computer, or the market on the Skills tab.

| Agent | Folder |
| --- | --- |
| Claude Code | `~/.claude/skills` |
| Codex | `~/.codex/skills` |
| Gemini CLI | `~/.gemini/skills` |
| OpenCode | `skills` in its config folder |
| Cursor | `~/.cursor/skills` |
| Copilot CLI | `~/.copilot/skills` |
| Goose | `~/.agents/skills` |

### Links or copies

Give skills as sets how a skill reaches an agent, for every agent or, under By agent, for one:

- **Links.** (the default). The agent’s folder links to the library’s copy, so an update reaches every agent at once. On Windows without the right to make links, a junction is used.
- **Copies..** Each agent gets a folder of its own, for tools that don’t follow links. A copy is made again when the library’s skill changes. If the agent, or you, edit a copy, the next sync takes the newest edit into the library and gives it to the other agents. An edit that loses to a newer one is kept with the backups.

A skill folder of your own with the same name is never written over: the page asks whether to use the library’s or keep yours.

### Editing and updates

- **Edit.** opens a skill’s files on the page; Save (or ⌘S) writes them. The command line has no editor.
- **Updates..** When you open the Skills tab, skills from GitHub are checked for updates if 12 hours have passed since the last check (`magpie library skill update` checks now). A skill you changed is never replaced without asking.
- **Put skills in..** Skills go to each ticked agent’s own folder (the default), or also into `~/.agents/skills`, which Codex, Gemini CLI, OpenCode, Crush, Droid, Kimi Code and other tools read.
- **Off here..** A skill can be turned off on this computer only; a sync from another computer doesn’t turn it back on.

## Subagents

A subagent is a helper the main agent can hand a task to. It has a name, a description and a prompt. magpie writes it as a file in each ticked agent’s subagent folder. The main agent reads every subagent’s **description** and decides itself when to call one, so the description should say plainly what it is for and when to use it.

- **Name:.** 2 to 50 lowercase letters, digits and `-`. A few names are reserved, such as `default` and `main`.
- **Description:.** required, up to 1,000 characters.
- **Prompt:.** required. It becomes the subagent’s instructions.
- **Model:.** optional. See Subagent models.

| Agent | File | Skills, MCP servers |
| --- | --- | --- |
| Claude Code | `~/.claude/agents/<name>.md` | the ones you pick |
| Codex | `~/.codex/agents/<name>.toml` | all the agent has |
| OpenCode | `agents/<name>.md` in its config folder | all the agent has |
| Gemini CLI | `~/.gemini/agents/<name>.md` | all the agent has |
| Qwen Code | `agents/<name>.md` in its folder | all the agent has |
| Droid | `~/.factory/droids/<name>.md` | MCP servers you pick; all skills |
| Grok | `agents/<name>.md` in its folder | all the agent has |
| Cursor | `~/.cursor/agents/<name>.md` | all the agent has |
| Copilot CLI | `~/.copilot/agents/<name>.agent.md` | all the agent has |

- Only Claude Code limits a subagent to the skills you pick, and only Claude Code and Droid to the MCP servers you pick. Elsewhere a subagent has everything its agent has.
- Cursor: only the Cursor app reads `~/.cursor/agents`. `cursor-agent` reads only a project’s `.cursor/agents`.
- Kimi Code, Goose, Crush, Qoder, CodeBuddy, iFlow and Kiro have no user-wide subagent folder, so they get none. Agents in WSL get none either.
- If you edit a file magpie wrote, it becomes yours and magpie stops changing it. A file of your own with the same name is never written over; the page shows a problem instead.

## Subagent models

A subagent’s Model field is written only for **Codex**. Every other agent runs its subagents on the model it picks itself, and the page says so. Left empty, the field reads Picked by the agent.

For Codex, the model goes into the subagent’s `.toml` file. Codex lays that file over the spawn, so requests carry that model and magpie’s gateway routes them like any other request. You can pick any model in Codex’s list, a magpie `provider/model`, or a routing group (`group/<id>`).

### Codex’s subagent model on the Agents page

Codex’s row on the Agents page has a subagent model of its own, for every subagent Codex starts:

- **Lead’s pick.** (the default). The main agent picks each subagent’s model, one of Codex’s own too. A subagent it names no model for runs on the main agent’s model. A resumed subagent stays on the model it started on.
- **Same as the lead..** Every subagent runs on the main agent’s model.
- **A model or a group..** Every subagent runs on it, even when the main agent names another.

> **The Agents page wins.** When that setting is anything but Lead’s pick, the gateway sends every Codex subagent request to it, over a Library subagent’s own model too. The Library editor then says so. Picking a model there also removes `default_subagent_model` from Codex’s config.

Codex’s own `[agents] default_subagent_model` in `config.toml` is a different thing: only the model a subagent starts on when the main agent names none. One exception to all of the above: a task the ChatGPT backend has sealed stays on the model it asked for, unless the setting is a ChatGPT account’s model.

Claude Code has its own order: the model the main agent names in its call, then the subagent file’s `model:`, then `CLAUDE_CODE_SUBAGENT_MODEL` (which Claude Code’s row on the Agents page can set), then the session’s model.

## Hooks

A hook is a command an agent runs at a point in its turn: a notification when it finishes, a formatter after it edits a file. Pick a portable event (turn end, after a tool, before a tool, on a prompt, at session start) and magpie writes it under each agent’s own name for that event. Only Claude Code, Codex, Gemini CLI, Cursor, Grok Build and Grok App take hooks. A hook entry you change becomes yours.

## RTK

The RTK tab turns on [RTK](https://www.rtk-ai.app/) per agent: the agent’s shell commands run through RTK, which shortens their output to save tokens. magpie can install RTK for you; turning it off works with RTK gone.

## What magpie touches

- Only what it wrote: the text between its markers, entries it recorded, files it marked as its own.
- Never a file, entry or skill of yours with the same name. The page shows the clash and lets you choose.
- Anything it replaces goes to the backups first.

Projects can get skills and MCP servers too, in the project’s own folders (such as `.claude/skills`, `.agents/skills`, `.mcp.json` or `.codex/config.toml`).

---

Source: https://usemagpie.ai/docs/mcp-router

# MCP router

The MCP servers you add in magpie’s Library are normally written into each agent’s own config, one entry per server. With the **MCP router** on, each agent is given a single server named `magpie` instead, and magpie passes each call on to the Library server behind it. It is **off by default**.

- **Set up once..** A server written once in the Library reaches every agent and app through one entry.
- **Run once..** A command server (one started as a program, such as `npx …`) runs once in magpie, not once in each agent. A server with no calls for 10 minutes is stopped and starts again on the next call.
- **One address for other apps..** Cursor, VS Code, Windsurf or an app on another computer can connect to magpie and use every Library server.

Tools appear in the agent as `server__tool`. Only tools are served (no resources or prompts), and a tool you turned off in the Library is neither listed nor run.

## Turn it on

1. **Open the page.** Go to Library → MCP.
2. **Switch it on.** Below the server list, turn on MCP router. Each agent that has Library servers ticked and can reach a server over HTTP (Streamable HTTP) gets one `magpie` entry at `/mcp/magpie/hub/<agent>` on magpie’s gateway, and those servers’ own entries are taken out of its config.
3. **Restart your agents.** An agent reads the change when it starts again.

Turning it off writes each server’s own entry back, removes only the `magpie` entry magpie wrote, and stops every server the router started. From the command line:

```
magpie library mcp router on
magpie library mcp router off
```

`magpie library` lists which agents are given the router and which keep their own entries, with why.

## Other apps

With the router on, the Other apps row shows an address ending in `/mcp/magpie/hub`, which serves every server in the Library. Connect… opens a sheet with a ready entry to copy for Cursor, VS Code, Windsurf or any app that takes a JSON MCP config; in the app window, Cursor and VS Code also have Add, which opens the app to confirm. An app on another computer needs a gateway key, as every request from your network does (see [Remote magpie](https://usemagpie.ai/docs/remote)).

> **Command servers run on this computer.** Anyone holding a gateway key on your network can call them through the router, with your rights here. Only share keys with people you trust.

## Agents that keep their own entries

These agents keep each server’s own entry, and the Library page says which and why:

- **No remote servers..** The agent can’t reach an MCP server over HTTP, such as Claude Desktop.
- **A server named magpie..** One of your Library servers is itself called `magpie`, so the names would clash.
- **Its own magpie entry..** The agent already has an entry called `magpie` that magpie didn’t write; it is left as it is.

## When to use it

- **Turn it on.** when you use several agents with the same servers, when command servers start many copies of themselves, or when you want editors and other computers to use your Library.
- **Leave it off.** if you use one agent, if you want each agent to talk to its servers directly, or if you’d rather nothing else on your network can reach your command servers. Every call goes through magpie, so magpie needs to be running.

---

Source: https://usemagpie.ai/docs/remote

# Remote magpie

One magpie can serve several computers. Sign in and set up providers and routing groups once, on the computer that keeps them (your desktop, a server, a [NAS in Docker](https://usemagpie.ai/docs/docker)), and on every other computer add that magpie as a provider of its own: a **Remote magpie**.

|  | The shared magpie | Each other computer’s magpie |
| --- | --- | --- |
| Providers, subscriptions, keys | kept and signed in here | uses them through the Remote magpie |
| Routing groups | made here | picked as `office/group/…` |
| Agents | its own | still wired by this computer’s magpie |
| Usage and quotas | counted and read here | shown here, named with the remote |

The computer you sit at still runs magpie: it wires that computer’s agents, picks their models and keeps their sessions. Only the models come from the other one.

## 1. Share the main magpie

1. **Turn on sharing.** On the computer that keeps your providers: Settings → Network and sharing → Share on local network → On. magpie then listens on the local network and makes a gateway key named Magpie. The Address row below the switch shows where other computers reach it, such as `http://192.168.1.20:3425`.
2. **Make a key for each computer.** Gateway → Gateway keys, or `magpie gateway-key add "Laptop"`, which prints its `sk-magpie-key-…`. Each key can have its own daily, weekly or monthly limit and its own models, and its calls are counted under its name.

While sharing is off, a desktop magpie listens on its own computer only, and other computers can’t reach it. A magpie in Docker is reached through its published port instead, and asks every caller outside its container for a gateway key, shared or not; see [Docker](https://usemagpie.ai/docs/docker#share).

## 2. Add it on the other computer

You need the address and a key from step 1. Any of these does it:

- **The app:.** on the Providers tab press ＋ Add provider, pick Remote magpie under Another computer’s magpie (the last heading), then give its address and the key.
- **The TUI.** (`magpie tui`): on the Providers page press `a`, pick Remote magpie, then type its address and key. On its row, `w` changes the address and `m` fetches its list again.
- **The CLI:.**

```
magpie provider add remote-magpie sk-magpie-key-… url=http://192.168.1.20:3425 id=office
magpie models            # office/… are the shared magpie's
magpie provider refresh office   # fetch its list again
```

`id=` names the provider here, and so begins its models’ ids (`office/…`). The address can be typed as `192.168.1.20:3425` (plain `http://` is assumed), with `/v1` after it, or as the root: magpie puts every API on it either way. Add one Remote magpie for each computer you share from, with a different id.

## What you get

- **Its models.** , as its own agents are shown them: `office/relay-a/claude-sonnet-5`, labelled `Claude Sonnet 5 · Relay A · office`. The ids stay ids; only the labels carry the names. Pick them for an agent here like any other model.
- **Its routing groups.** , as `office/group/…`. The group decides on the shared magpie, with its accounts.
- **Every API..** A request goes on in the API the agent spoke (Anthropic Messages and token counting, Responses, Chat Completions). A model that the shared magpie’s provider serves on another API only is turned into that API once, never on both computers. Responses go over HTTP, SSE included, not WebSocket.
- **Images and video..** Its image and video models are found by themselves and served through its image generation and edit, and video, APIs.
- **System One..** Its decision models (Jev, Clef, and models with names of your own) are set up at its `/v1/systemone` and appear as decision models, not chat models. Refresh the provider’s list to find new ones. A bare `office` asks the first decision model listed.
- **Embeddings, rerank, speech to text and text to speech.** go to its matching APIs. They stay in agents’ lists as they are on the remote; being listed doesn’t make them able to hold a conversation.
- **Prices..** Each model costs here what the shared magpie counts it at (a price set there by hand, else its provider’s list price), so the two computers count the same. A price you set here comes first.

## Quotas and usage

The Usage page, the menu bar and `magpie quota` show the shared magpie’s subscription cards, named with it (`Codex · office`, id `office/codex`), as that magpie last read them: only the computer with the sign-ins asks the vendors. A card’s refresh here has it read that card once more, at most once every 30 seconds. A Codex reset or a WorkBuddy check-in is pressed on that computer, from its own app, TUI or CLI. A key that magpie holds to a budget, some models or some accounts is told none of its cards: only that key’s own card shows here, with its limit.

The shared magpie counts this computer’s requests under the name of the gateway key it sends, with the account that answered.

## Short-lived keys

A program that starts agents in sandboxes can give each one a gateway key of its own that stops working by itself. The key lives 1 minute to 30 days, and may be held to some models, some accounts, a number of tokens or a cost over its whole life, or to read-only use. Its secret is told once, in the answer.

```
curl -s -X POST http://127.0.0.1:3425/v1/magpie/keys \
  -d '{"name":"sandbox-1","ttl":"1h","models":["office/codex/gpt-5"],"tokens":200000}'
# {"id":"k…","name":"sandbox-1","key":"sk-magpie-…","expires":"…","models":[…],"limit":{…}}
curl -s http://127.0.0.1:3425/v1/magpie/keys              # the keys you issued, masked
curl -s -X DELETE http://127.0.0.1:3425/v1/magpie/keys/k…  # revoke one early
```

A program on this computer may call it with no key; a page in a browser may not. Another computer, a container or CI calls it with a gateway key you let issue keys, and every key it issues is held to that key: never a model or account it may not use, never past its own expiry, and what they spend counts against its limit. Turning it off or removing it stops its keys at once. The same from the command line, which prints the key alone:

```
magpie gateway-key issue --ttl 1h --name sandbox-1 --models office/codex/gpt-5 --tokens 200000
magpie gateway-key issuer <id> on    # let a key issue keys
magpie gateway-key issue --ttl 30m --from <id> --read-only --json
magpie gateway-key list               # until 10-31 14:00, expired, issued by …
```

An expired key is refused with `401` and why (“the gateway key "sandbox-1" expired at …: ask for a new one”) on every API, from this computer too. It is removed an hour later.

## Keys for GitHub Actions

A GitHub Actions job can get a short-lived key without a gateway key in the repository’s secrets: it trades the OIDC token GitHub gives it. Write a rule naming the repository (and, if you like, the branch, environment or any other claim, exact or with `*`), the gateway key its keys are issued under, and how long they live:

```
magpie gateway-key issuer <id> on
magpie gateway-key oidc add --key <id> --repo owner/app --ref refs/heads/main --ttl 1h
# prints the rule id and its audience, magpie-<rule id>
magpie gateway-key oidc list
magpie gateway-key oidc remove <rule id>
```

In the workflow, ask GitHub for a token with the rule’s audience and POST it to `/v1/magpie/keys/oidc`:

```
permissions:
  id-token: write
steps:
  - name: Get a magpie key
    run: |
      TOKEN=$(curl -s -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
        "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=magpie-<rule id>" | jq -r .value)
      KEY=$(curl -s -X POST https://<your magpie>/v1/magpie/keys/oidc \
        -H "Authorization: Bearer $TOKEN" -d '{"ttl":"30m"}' | jq -r .key)
      echo "::add-mask::$KEY"
      echo "MAGPIE_KEY=$KEY" >> "$GITHUB_ENV"
```

The key is issued under the rule’s gateway key and held to it like any other issued key, lives no longer than the rule says, and is named after the repository, branch and run. A token from another repository or branch, an expired one, or one already traded gets `401` and why. The route answers another computer only while magpie is shared, and refused tokens count against the failed sign-ins it allows. Without a rule nothing is traded.

## Stats API

What the Usage page shows is also served as JSON, to this computer and, while magpie is shared, to a request with a gateway key. A key held to a budget, models or accounts is told only its own calls and limit, and the quotas of what it may use once its owner turns on Quotas for it (`magpie gateway-key quotas <id> on`).

- `/v1/magpie/usage?period=today|7d|30d|all`: totals, by model, agent, provider, account and gateway key.
- `/v1/magpie/usage/requests`: the request log, with `period`, `day`, `offset`, `limit`, and filters `model`, `agent`, `provider`, `account`, `callerKey`, `failed=1`, `retried=1` and `q`.
- `/v1/magpie/quotas`: each subscription’s windows (`?kept=1` without asking the vendors); `/v1/magpie/quotas/history?days=`: what was left over time, 45 days at most.
- `/v1/magpie/limit`: the key’s own limits, its expiry, and its issuer’s limits; for a held key, what holds it (`heldTo`), its `models`, and whether it is told quotas (`quotas`, `quotaProviders`).
- `/v1/magpie/concurrency`: requests in flight, per account.

```
curl -s 'http://127.0.0.1:3425/v1/magpie/usage?period=7d'
curl -s 'http://127.0.0.1:3425/v1/magpie/usage/requests?period=today&callerKey=k…&failed=1&limit=50'
curl -s 'http://127.0.0.1:3425/v1/magpie/quotas?kept=1'
curl -s 'http://127.0.0.1:3425/v1/magpie/quotas/history?days=14'
curl -s http://127.0.0.1:3425/v1/magpie/limit -H 'Authorization: Bearer sk-magpie-…'
curl -s http://127.0.0.1:3425/v1/magpie/concurrency
```

## When it doesn’t work

| You see | What to do |
| --- | --- |
| “magpie isn’t shared on the local network”, or “remote magpie isn’t shared” | turn on Share on local network on that computer |
| “remote magpie didn’t take this key” (401) | use one of its enabled gateway keys: Gateway → Gateway keys there |
| 403 for a model | that key may use only some models: `magpie gateway-key models <id>` on that computer shows or changes them. A bare `office` asks System One’s first decision model, whatever the key allows; use the full `office/provider/model` id |
| “couldn’t reach the remote magpie” | check the address, that magpie is running there with sharing on, and that its firewall lets the port in |
| no System One models, or “doesn’t share its quotas” | update magpie on that computer, then refresh the list here |

> **Away from home**, reach the shared magpie over a VPN such as Tailscale or WireGuard, with its address there. Don’t open its port to the internet.

Questions or a setup worth sharing? Ask on [Discord](https://discord.gg/vGSnD3ZKQF). The [reference](https://github.com/yetone/magpie/blob/main/docs/reference.md) has the details.

---

Source: https://usemagpie.ai/docs/docker

# magpie in Docker

Run magpie on a server or a NAS that has no desktop: its gateway serves your models to agents on other computers, and you add providers and sign in to subscriptions from a page in your browser.

| **Image** | `ghcr.io/yetone/magpie`, for `linux/amd64` and `linux/arm64` |
| --- | --- |
| **Tags** | `latest` (the newest release), `daily` (the newest release as of 20:00 UTC, moved once a day), `stable` (the desktop app's Stable channel: a release a week, out three days first, or an urgent one at once), `0.1.1150` (one release), `0.1`, `edge` (every change on `main`) |
| **Ports** | `3425` the gateway agents call; `3430` the browser UI, when the container runs `magpie web`; it answers the gateway’s `/v1` routes too, so a reverse proxy needs only this port |
| **Volume** | `/config`: providers, keys, sign-ins, plugins and usage |
| **User** | nonroot (uid 65532) |

The image holds magpie’s terminal-only build on Debian 12 slim, with bash for a terminal in the container and curl for the installers of the CLIs some subscriptions sign in with (Cursor, Devin, Grok Build). It runs `magpie serve` (the gateway alone) unless given another command. The container finds no agents to wire, so magpie in it is a gateway: the agents that use it run elsewhere.

## Run it

Run it with the browser UI, a key for that page you keep across restarts, and both ports on the host’s loopback only:

```
docker run -d --name magpie --restart unless-stopped \
  -p 127.0.0.1:3425:3425 -p 127.0.0.1:3430:3430 \
  -e MAGPIE_WEB_KEY=$(openssl rand -hex 16) \
  -v magpie-config:/config \
  ghcr.io/yetone/magpie:latest web --addr 0.0.0.0:3430 --no-open

docker logs magpie
```

The log names the page with its key:

```
● magpie web on http://127.0.0.1:3430/?k=0f3c9a1e…
  on the network http://172.17.0.2:3430/?k=0f3c9a1e…
  these are the container's own addresses: other machines use the host's, and MAGPIE_PUBLIC_URL=http://<host>:<port> puts it here
  other containers on this host http://172.17.0.1:3425
! anyone with the link can change magpie and see its keys, and the network carries it unencrypted
  the link carries MAGPIE_WEB_KEY · gateway http://127.0.0.1:3425 · Ctrl-C to stop
```

> **Agents outside the container need a gateway key.** In the container any key works. A request from the host or another machine is answered only with an enabled gateway key, and gets 401 without one: make one as in Gateway keys. `127.0.0.1:` in `-p` keeps a port on the host; leave it out, or name the host’s LAN or VPN address, for other machines to reach it.

Without `web --addr 0.0.0.0:3430 --no-open` the container runs the gateway alone, which you then set up from a terminal in it (`docker exec -it magpie magpie provider add …`). A folder bind-mounted at `/config` works in place of the named volume, if uid 65532 can write it: `sudo chown -R 65532:65532 /volume1/docker/magpie/config`.

## The browser UI

Open the link from the log. The key in it is traded for a cookie and taken out of the address; a page opened without it is turned away (401). With `MAGPIE_WEB_KEY` set (16 or more letters, digits or `- . _ ~`; `openssl rand -hex 16` makes one) the key stays the same across restarts and the browser stays signed in for 400 days. Without it, every start makes a new key and the cookie lasts the browser session.

The page is in **gateway mode**: Providers, Gateway, Routing, Usage, Sessions, Plugins and Settings, with no Agents, since there are no agents in the container. Library has its MCP servers alone, with the MCP router: other computers’ apps connect at the router’s address with a gateway key. Sessions lists only the sessions of agents on other computers that came through this gateway, never this machine’s agents’ files. Settings → General → Gateway mode turns it off.

On a NAS or a server you reach over SSH, open the page through a tunnel rather than publishing 3430: `ssh -L 3430:127.0.0.1:3430 you@nas`, then the log’s link on your own computer.

> **Anyone with the link can change magpie and see its keys.** Keep 3430 on loopback or a VPN. Across the network, serve it over HTTPS: give magpie a certificate with `MAGPIE_TLS_CERT` and `MAGPIE_TLS_KEY`, or put it behind a reverse proxy with TLS, such as Caddy.

## Sign in to subscriptions

Add API keys on Providers as on the desktop. A subscription’s sign-in (ChatGPT, Claude…) opens the vendor’s page in your browser, and when you are done the vendor sends that browser back to `localhost`, for ChatGPT `http://localhost:1455/auth/callback?code=…`. That is your own computer, not the container, so the page doesn’t load. Copy its whole address from the address bar and paste it into the sign-in’s Callback URL field.

The same from a terminal:

```
docker exec -it magpie magpie accounts add codex
```

Open the link it prints, sign in, then paste the address the browser ended on. The browser UI can also import sign-ins from a file.

A Claude subscription is signed in to and answered through Claude Code, which the image doesn’t have. Have magpie download Anthropic’s own build first: it says the version, where it comes from and where it goes, asks, and checks the download’s SHA-256 against Anthropic’s manifest. It is kept in `/config/cache`, on the volume, so a new image keeps it, and magpie keeps it at Claude Code’s newest release by itself: it looks a minute after it starts and every six hours, and downloads a newer one the same way. Nothing needs installing again after an update. To hold a version, set `-e DISABLE_AUTOUPDATER=1`. `magpie accounts add claude` offers it too when Claude Code is missing.

```
docker exec -it magpie magpie claude-code install
```

A Grok (SuperGrok) subscription signs in through xAI’s Grok Build CLI, which the image doesn’t have either. Its sign-in, in the browser UI or with `magpie plugin login grok`, installs it first, as xAI’s installer does: the stable version from `x.ai/cli`, kept in `/config/home/.grok`. To use a Grok Build binary you put on the volume yourself, set `GROK_BIN_DIR` to the folder holding it.

## Your own browser

Magpie Browser lets agents act in your own browser, through its extension. The extension can’t be loaded from the container’s folders, so in the browser UI open Library → Magpie Browser and click Download the extension. The zip is pointed at the page’s own address, with a gateway key named **Magpie Browser** of its own. Unzip it, open `chrome://extensions`, turn on Developer mode and click Load unpacked on the unzipped folder. An extension already loaded takes the address (`http://localhost:3430`, or the gateway’s published port) and a gateway key in its popup.

The Magpie Browser key connects the extension and nothing else: it can’t use models, MCP servers or stats, so a copy of the zip left in Downloads spends nothing. The host’s browser reaches the container from Docker’s bridge, not from the container’s own computer, so it is that key’s alone and the container’s agents don’t use it yet ([#5529](https://github.com/yetone/magpie/issues/5529)). To use it from an agent on the host, give that agent a gateway key of its own with full access, connect the extension with the same key in its popup, and call `/mcp/magpie/browser` with it. A browser given another key is that key’s alone, and it is let go once its key is turned off, removed or rotated.

## What is kept

Everything magpie writes is under `/config`, so a restart, or a new container on the same volume, keeps your providers, keys, sign-ins and plugins.

| Path | Holds |
| --- | --- |
| `/config/magpie` | magpie’s own files: `settings.json`, providers, gateway keys, routing groups |
| `/config/home` | the container’s `HOME`: sign-ins kept where their agent keeps them (`~/.codex`, `~/.claude`…) |
| `/config/cache` | the model catalog, Bun, which plugins run on (downloaded the first time one is used), and the Claude Code `magpie claude-code install` downloaded |
| `/config/data`, `/config/state` | the rest of what magpie keeps |

A volume made by an older image keeps working: magpie adds the folders it lacks when it starts. Only sign-ins made with that older image, which lived outside the volume, have to be made again.

## Environment

| Variable | What it does |
| --- | --- |
| `MAGPIE_ADDR` | where the gateway listens. The image sets `0.0.0.0:3425`, so the published port reaches it. |
| `MAGPIE_PUBLIC_URL` | the address other machines reach the gateway at, such as `http://192.168.1.20:3425` (the host’s or the NAS’s, on the published port), or a reverse proxy’s base URL. In the container magpie sees only Docker’s own `172.17.x` address; with this set, the address it shows and prints is the one to use. |
| `MAGPIE_WEB_KEY` | the browser UI’s key, kept across restarts (16+ characters) |
| `MAGPIE_TLS_CERT`, `MAGPIE_TLS_KEY` | a PEM certificate (its chain after it) and its key, mounted into the container: other machines then reach the gateway and the browser UI over `https://` only, and plain HTTP from them gets 400. The files are read again when they change, so a renewal needs no restart. One without the other, or files that don’t load, stop magpie from starting. Use `https://` in `MAGPIE_PUBLIC_URL` too. |
| `MAGPIE_ALLOW_IPS` | the only addresses other machines may reach the gateway and the browser UI from, as IPs and CIDR ranges: `203.0.113.7,10.0.0.0/8,2001:db8::/32`. Any other address gets 403, even with a gateway key. Unset lets every address in, each with a key. See Allowed addresses. |
| `HOME`, `XDG_CONFIG_HOME`, `XDG_CACHE_HOME`, `XDG_DATA_HOME`, `XDG_STATE_HOME` | set by the image to the folders under `/config` above; leave them |

## Gateway keys and other machines

1. **Make a key for each client.** Gateway → Gateway keys, or in a terminal `docker exec magpie magpie gateway-key add "Laptop"`, which prints the new `sk-magpie-key-…`. Every request from outside the container, the host’s own included, must carry an enabled gateway key, and one without gets 401. A key can have its own daily, weekly, monthly, every-N-days or every-N-hours limit and its own list of models (`magpie gateway-key limit`, `magpie gateway-key models`).
2. **Publish the port.** Recreate the container with `-p 3425:3425`, or bound to the NAS’s LAN or VPN address (`-p 192.168.1.20:3425:3425`), and with `-e MAGPIE_PUBLIC_URL=http://192.168.1.20:3425`.

On each other computer, point the agent at the gateway with one of those keys as its API key: `http://192.168.1.20:3425/v1` for an OpenAI client, `http://192.168.1.20:3425` for an Anthropic or Gemini one. Model ids are `provider/model`, or a routing group’s; `GET /v1/models` lists them. If that computer runs magpie itself, add the container as a [Remote magpie](https://usemagpie.ai/docs/remote) instead, and magpie wires its agents for you.

**Other containers on the same host.** Another container on the NAS reaches magpie at the host, through the Docker bridge’s gateway and the published port: `http://172.17.0.1:3425` on Docker’s default bridge. The container’s own `172.17.x` address is no use to it, and the host’s LAN address may not be either, as a NAS’s firewall can keep containers from it. `host.docker.internal` is the same address on Docker Desktop, and on Linux only in a container given `extra_hosts: ["host.docker.internal:host-gateway"]`. A container on magpie’s own compose network, or one you made, can use its name, `http://magpie:3425`. Either way it sends a gateway key. The log and the browser UI list this address as Other containers on this host, after the host’s address the page was opened at.

Settings → Network and sharing → Share on local network isn’t needed in the container: turning it on also makes a gateway key named Magpie, and the gateway asks for a key from outside the container either way.

**Upgrading from an earlier image.** An agent outside the container that sends `magpie`, or any other key that isn’t an enabled gateway key, now gets 401 (“the API key sent is not an enabled magpie gateway key”). Make it a key as above and put that in the agent’s settings. Agents that already send a gateway key, and a Remote magpie set up with one, keep working.

**Allowed addresses.** On a public host, set `-e MAGPIE_ALLOW_IPS=203.0.113.7,10.0.0.0/8` to the addresses your clients come from. A request from any other address is refused 403 before its key is looked at, so a key that leaks is no use from elsewhere; the refusal names the address it came from, as does the container’s log. magpie judges the address of the connection itself, never an `X-Forwarded-For` header, and a mistyped entry lets nothing in rather than everything. Docker’s default bridge network passes a client’s own address into the container, but a request from the host itself arrives from the bridge’s gateway (`172.17.0.1`), and Docker Desktop and rootless Docker show every client as one address of their own: add that, or check what the 403 says. Behind a reverse proxy or tunnel, every request comes from the proxy’s address, so limit who reaches magpie at the proxy. On the desktop app the same list is Settings → Network and sharing → Allowed addresses.

> **Over the internet, prefer a VPN** such as Tailscale or WireGuard to opening 3425. A reverse proxy or tunnel in front of the container is the network too: its clients need a gateway key like any other machine’s.

**Claude Code’s status line, with Claude Code outside the container.** The status line square can’t reach another machine’s `~/.claude/settings.json`, and the command it writes names a binary in the container. The gateway answers the same line itself: on the machine Claude Code runs on, set `statusLine` in `~/.claude/settings.json` to `{"type": "command", "command": "curl -fsS -m 1 -H 'Authorization: Bearer sk-magpie-key-…' --data-binary @- http://<host>:3425/v1/magpie/statusline || true"}`, with the host or address that reaches the container and a gateway key (a read-only key is enough). A key held to a budget, models or accounts gets the line once its owner turns on Quotas for it, with only the accounts it may use. Add `?format=json` for the same as JSON (the line, the model, and each account’s windows with `used` and `resetsAt`), for a status line that draws its own. Claude Code runs it on every message and passes its session on stdin, which adds the model the session went to. The same command is shown in the browser UI under Settings → About.

## Docker Compose on a NAS

```
services:
  magpie:
    image: ghcr.io/yetone/magpie:latest
    restart: unless-stopped
    ports:
      # 127.0.0.1: the host alone; every caller outside the container needs a gateway key
      - "127.0.0.1:3425:3425"
      - "127.0.0.1:3430:3430"
    environment:
      MAGPIE_PUBLIC_URL: http://<nas-address>:3425
      MAGPIE_WEB_KEY: <random-key>
    volumes:
      - ./config:/config
    command: [web, --addr, 0.0.0.0:3430, --no-open]
```

Then: `sudo chown -R 65532:65532 ./config`, `docker compose up -d`, open `http://127.0.0.1:3430/?k=<random-key>` through an SSH tunnel, add your providers and make a gateway key for each machine. For other machines to reach the gateway, change its line to `"3425:3425"` (or the NAS’s LAN or VPN address) and run `docker compose up -d` again.

## Health, terminal, updates

- **Health..** The image has a `HEALTHCHECK`: `magpie healthcheck` exits 0 while the gateway answers, under `serve` and `web` alike, so `docker ps` shows the container as healthy and Compose can wait for it with `depends_on: condition: service_healthy`.
- **Terminal..** `docker exec -it magpie bash`, or a NAS panel’s terminal, opens a shell with `magpie` on its PATH: `magpie providers`, `magpie models`, `magpie usage`, `magpie quota` and the rest of the [CLI](https://github.com/yetone/magpie/blob/main/docs/reference.md).
- **Updates..** Pull the new image and recreate the container on the same volume: `docker pull ghcr.io/yetone/magpie:latest`, then `docker rm -f magpie` and the same `docker run`, or `docker compose pull && docker compose up -d`. magpie releases several times a day; for one update a day with Renovate or Watchtower, follow `daily` (with Renovate, pin its digest), or `stable` for one a week.
- **Build it yourself..** `docker build -t magpie .` in a checkout of [the repository](https://github.com/yetone/magpie) makes the same image.

Questions or a setup worth sharing? Ask on [Discord](https://discord.gg/vGSnD3ZKQF). The [reference](https://github.com/yetone/magpie/blob/main/docs/reference.md#docker) has the details.

---

Source: https://usemagpie.ai/docs/import

# Add to magpie

Hand your users one link, and your models show up in every agent they run: Claude Code, Codex, OpenCode, Gemini CLI, Pi, Crush. No config files, no environment variables, no copy-pasting base URLs.

## Quick start

1. **Build a link.** Describe your endpoint as URL parameters: a name, a base URL per API you speak, and optionally the user’s key and the models to offer.
2. **Put it behind a button.** On your dashboard, next to the key you just minted: *Add to magpie*.
3. **The user confirms.** magpie opens, shows exactly where prompts and the key will go, and adds the provider when the user says yes. Every agent can use it right away.

```
https://usemagpie.ai/import#name=Acme%20Relay&chat=https://api.acme.example/v1&anthropic=https://api.acme.example&key=sk-…&models=gpt-5.5,claude-sonnet-5
```

## The link

magpie registers the `magpie://` scheme with the system. An import link is that scheme, the word `import`, and a query string:

On the web, link to the same parameters on `usemagpie.ai/import` instead, after a `#`:

### Why the https link

It works everywhere a link does: GitHub READMEs, chat apps and email clients drop or block custom schemes. It opens magpie, and offers the download when magpie isn’t installed yet.

### Why after the `#`

Browsers never send the fragment to a server. The key goes from your page to the user’s machine without passing through usemagpie.ai, not even its logs.

Every value is URL-encoded, as `URLSearchParams` or `urlencode` produce. Both `%20` and `+` work for spaces.

## Parameters

A link either names one of magpie’s presets, which already knows the vendor’s endpoints, or describes a provider from scratch with a name and at least one base URL.

| Parameter | Meaning |
| --- | --- |
| `name`or preset | What the provider is called in magpie, at most 80 characters. |
| `chat` | OpenAI Chat Completions base URL, ending in `/v1` (magpie appends `/chat/completions`). |
| `responses` | OpenAI Responses base URL, ending in `/v1`. Codex speaks only this API; magpie translates for it when you don’t. |
| `anthropic` | Anthropic Messages base URL: the root, without `/v1`. |
| `gemini` | Google Gemini API base URL, ending in `/v1beta`, as the app’s editor and the TUI take one. |
| `key` | The user’s API key. Leave it out and the user pastes one in the dialog. |
| `models` | Model ids to offer the agents, comma separated. Without it, magpie lists the models your `/v1/models` returns. |
| `id` | The id agents use in `id/model`. Defaults to the name, lowercased with dashes (`Acme Relay` → `acme-relay`). |
| `catalog` | A [models.dev](https://models.dev) provider id whose metadata applies, e.g. `openai` for a relay of OpenAI models: display names, context sizes (written into the agents that take them), reasoning levels and image input; the model list when the provider’s own `/models` can’t be read; and per-token prices, which the Usage page turns into a cost estimate in USD. Several ids may be given, comma-separated: their models are combined, and where two know the same model the first one’s entry is used. |
| `website` | Your site (https). Shown on the provider’s page. |
| `keys` | The page where users make keys (https). The dialog links to it when the link has no key. |
| `icon` | A picture of your own (https): PNG, JPEG, GIF, WebP, ICO or SVG, at most 1 MB. magpie downloads it once, after the user confirms the import, and keeps it beside the provider. Without one, magpie shows the `catalog` vendor’s logo or a plain mark. |
| `balance` | Where the key’s balance is read (https), on the host of one of your base URLs: magpie asks it with the key, as a chat request sends it. `{key}` in it stands for the key. Without it, magpie reads the vendors it knows, and asks a relay where new-api and sub2api tell a key its balance (`/api/usage/token`, `/v1/usage`); give one when yours answers elsewhere. |
| `balance_path` | Where the amount is in the JSON reply: a dotted path, list items by index (`data.balance`, `balance_infos.0.total_balance`), or a sum of them in your own units (`$ data.quota / 500000`). `$` or `¥` before it is the currency, `%` after it a percent of 1; several amounts go apart by `;`, each with a `label:` if wanted. Needs `balance`. |
| `balance_method` | `GET`, the default, or `POST` with no body. Needs `balance`. |
| `preset`or name | A preset id; its endpoints, catalog and pages are used, and `name` may rename it. |
| `region` | With a preset that has regions, which one. |

At least one of `chat`, `responses`, `anthropic` and `gemini` is required without a preset; give every API you speak, and each agent uses the one it speaks natively. Base URLs must be **https**, except plain http to `localhost`, loopback, private addresses and `*.local`, where model servers usually run without TLS. They can’t carry a query, a fragment or credentials.

A link sets no other header or token for the balance: an account-wide access token is worth more than one key, and a URL stays in browser history. A balance that needs one is set up in the provider’s editor.

### Presets

Vendors magpie already knows. `magpie presets` prints the current list.

A vendor with a preset only needs to add the key: `magpie://import?preset=deepseek&key=sk-…`. Want yours on the list? [Open an issue](https://github.com/yetone/magpie/issues).

## Link builder

Fill in your endpoint; the link, the button and the Markdown follow as you type. Everything stays in this page.

## The button

Two ready-made badges, one for light pages and one for dark. Link them to your import link, or draw your own button: the words *Add to magpie* and the bird are yours to use.

```
<a href="https://usemagpie.ai/import#preset=deepseek&key=sk-…">
  <img src="https://usemagpie.ai/img/add-to-magpie.svg" alt="Add to magpie" width="176" height="40">
</a>
```

```
[![Add to magpie](https://usemagpie.ai/img/add-to-magpie.svg)](https://usemagpie.ai/import#preset=deepseek)
```

For dark pages, use `add-to-magpie-light.svg`. A public page like a README should never carry a key; leave `key` out and the user pastes their own.

## From your backend

The natural place for the button is the page that shows a freshly minted key. Build the link where you have it:

```
const params = new URLSearchParams({
  name: "Acme Relay",
  chat: "https://api.acme.example/v1",
  anthropic: "https://api.acme.example",
  key: apiKey,
  models: ["gpt-5.5", "claude-sonnet-5"].join(","),
  icon: "https://acme.example/logo.svg",
});
const href = "https://usemagpie.ai/import#" + params;
```

```
from urllib.parse import urlencode

href = "https://usemagpie.ai/import#" + urlencode({
    "name": "Acme Relay",
    "chat": "https://api.acme.example/v1",
    "anthropic": "https://api.acme.example",
    "key": api_key,
    "models": "gpt-5.5,claude-sonnet-5",
    "icon": "https://acme.example/logo.svg",
})
```

```
magpie import 'magpie://import?preset=deepseek&key=sk-…'   # asks first; -y to skip
```

## Security

An import link is a suggestion. The user decides.

- **Always confirmed..** magpie shows the name, every host that prompts and the key will go to, and the models, and saves nothing until the user presses Add. The user can rename it, or replace the key, first.
- **No silent overwrites..** When the id is already taken, the dialog says so and the button reads *Replace*.
- **https only..** Plain http is refused except to this machine or the local network; `file:`, credentials in URLs and other schemes are refused outright.
- **Read once..** Inside the app, the link’s contents are handed to the window a single time; a reload doesn’t bring the dialog back.
- **Icons are fetched, not embedded..** An `icon=` URL is downloaded by magpie, only after the user confirms the import, only over https, and only into its own icons folder — at most 1 MB, and the type is checked. magpie asks for it through usemagpie.ai’s icon proxy, so your host sees Cloudflare’s address and never the user’s, and the fetch is made from Cloudflare, where nothing on the user’s own machine or network can be reached. A loopback or local-network name is refused before anything is asked. The page and the dialog never load a remote picture directly.
- **The balance stays on your hosts..** A `balance=` URL on any host but one of the link’s base URLs is refused, so the key goes nowhere its requests don’t already go. It is asked only after the user adds the provider.
- **Keys stay out of servers..** The web link keeps parameters in the fragment. The key ends up only in `~/.config/magpie/providers.json`, readable by the user alone.

## Platforms

| System | How `magpie://` gets registered |
| --- | --- |
| macOS | By the app itself, as soon as magpie.app is in Applications. |
| Windows | For the current user, the first time magpie runs. |
| Linux | By a desktop entry (`x-scheme-handler/magpie`), written by the installer and again on first run. |
| Terminal | `magpie import <link>` shows the same summary and asks before adding. |

Import links need magpie 0.1.8 or later. When magpie is already running, the link goes to that instance and its window comes forward.

---

Source: https://usemagpie.ai/docs/integrate

# Integrate your app

For developers of an AI app, agent or client who want it to work well with magpie. There are three levels, from no work on magpie’s side to a row of your own on the Agents page.

| You want | Route | Change to magpie |
| --- | --- | --- |
| Your app’s requests served by magpie, counted under its own name in Usage | Talk to the gateway | none |
| A row on the Agents page: detected, its model picked there, put back on disconnect | An agent adapter | a pull request |
| A new model source (a subscription, a vendor), or rewriting requests | A plugin | none |

## 1. Talk to the gateway

magpie runs a local LLM gateway. Every model the user has in magpie (subscriptions, API keys, local models, routing groups) is served there under one id each, so your app needs one provider entry, not one per vendor.

### Find it

The gateway listens on `127.0.0.1:3425`, or on the port in `port` of magpie’s `settings.json` (`~/.config/magpie/settings.json`, the same path under the user’s folder on Windows; `$XDG_CONFIG_HOME/magpie` when that is set). `GET /api/hello` answers `{"name":"magpie","version":"…"}` when it is magpie. Read that file, never write it. magpie must be running (the app or `magpie serve`); an app that finds nothing there offers its own providers as usual.

```
curl -s http://127.0.0.1:3425/api/hello
curl -s http://127.0.0.1:3425/v1/models -H "Authorization: Bearer magpie-acme"
```

### Endpoints

Requests go straight through when the vendor speaks your API, and are translated otherwise, streaming, tool calls, images and reasoning included. The base URL is `http://127.0.0.1:<port>/v1` for an OpenAI client and `http://127.0.0.1:<port>` for an Anthropic or Gemini one.

| Path | API |
| --- | --- |
| `/v1/chat/completions` | OpenAI Chat Completions |
| `/v1/responses` | OpenAI Responses |
| `/v1/messages`, `/v1/messages/count_tokens` | Anthropic Messages |
| `/v1beta/models/{model}:generateContent` (and `:streamGenerateContent`) | Google Gemini |
| `/v1/models` | the catalog |
| `/api/version`, `/api/tags`, `/api/show` | the catalog as an Ollama server lists it, for a client that takes only an Ollama endpoint (Copilot in Visual Studio and VS Code: enter `http://127.0.0.1:<port>` as the Ollama URL; it chats on `/v1/chat/completions`, and `/api/chat` isn’t served) |

### The key names your app

On this machine the gateway takes any key. Send `magpie-<your-app-id>` (`Authorization: Bearer magpie-acme`, or `x-api-key`) and every call is counted as `acme` in Usage, the Requests log and the routing rules that match on agents. Without it, magpie counts the call by the first word of your `User-Agent` (`Acme/1.4 (darwin)` is `Acme`); an SDK’s own User-Agent (`OpenAI/JS …`, `ai-sdk/…`) would count it as that SDK. From another computer (Settings → Share on local network) the key must be one of the user’s gateway keys, and the User-Agent names your app.

### Models

`GET /v1/models` lists what the user has turned on: `id` (`provider/model`, or a routing group’s name, sent as it is), `display_name`, `owned_by` (the provider), `reasoning` and `supported_reasoning_levels` (`[{"effort":"low"},…]`, and the same as plain names in `reasoning_levels`), `context_window` and `max_output_tokens` when known, and `modalities` when magpie knows whether it takes images. List them from there rather than shipping a list: the user adds and removes providers in magpie. Reasoning is asked in your API’s own field (`reasoning_effort`, `reasoning.effort`, Anthropic’s `thinking` or `output_config.effort`). `?format=text` gives the ids one a line. The list holds chat models alone: ask for image and video models with `?kind=image,video` (or `?kind=all`). Each is marked `"kind": "image"` or `"video"` and is made on `/v1/images/generations` or `/v1/videos`, not a chat route.

A vendor’s own fields: `/v1/images/generations` and `/v1/videos` take OpenAI’s fields and pass the others on to a vendor that takes them, such as Volcengine Ark’s `content` (reference video and audio, `draft_task`), `ratio`, `resolution`, `duration: -1`, `tools`, `watermark` and `sequential_image_generation`, and a video’s answer carries Ark’s own fields (`content.last_frame_url`, `usage`). For the rest of a vendor’s API use `/v1/magpie/native/<provider>/<path>`: `GET`, `POST`, `PUT`, `PATCH` or `DELETE`, with `<path>` joined to the provider’s host (not its base URL), in the vendor’s own shape on the user’s key for that provider, a stream as it comes; Ark’s task list is `GET /v1/magpie/native/ark/api/v3/contents/generations/tasks`. It serves a provider added with an API key, not a subscription or sign-in, and Ark’s short paths (`images/generations`, `contents/generations/tasks`) still work under the key’s base. It takes the same gateway key as every route, and a key held to models, accounts or a budget is refused it.

### Optional

Send `X-Magpie-Session: <id>` with a conversation’s requests and `GET /v1/magpie/route?session=<id>` says which model a routing group picked for the turn and the fallbacks it tried, before the first token (long-poll with `after=<seq>&wait=<s>`). `GET /v1/magpie/quotas` lists the user’s subscription allowances, and `GET /v1/magpie/usage` and `/v1/magpie/usage/requests` the Usage page’s numbers and its requests (with `session`, and `subagent`/`parent_agent` for a Claude Code subagent’s call). They answer only this machine, or another with a gateway key; a key held to a budget, models or accounts sees its own calls and routes alone, and is refused the quotas unless its owner lets it see those of what it may use (`magpie gateway-key quotas <id> on`; its own limit is `GET /v1/magpie/limit`). Calls your app makes to its vendor itself can be reported with `POST /v1/magpie/usage/requests` (one record or up to 5000 a post, in `usage.jsonl`’s shape, each with a `rid`; past times are kept, so a history can be backfilled). They show on the Usage page as reported, and never count against a key’s limit. The [reference](https://github.com/yetone/magpie/blob/main/docs/reference.md#connecting-anything-else) has the details.

> **Keep the user’s providers.** Add magpie as one more provider (named Magpie) beside the ones the user set up in your app, rather than replacing them, so turning magpie off is picking another provider.

## 2. A row on the Agents page

The agents magpie lists (Claude Code, Codex, OpenCode, dsh, Alma, Cindy…) are adapters in [`internal/agent`](https://github.com/yetone/magpie/tree/main/internal/agent), one file each. A row gets your app’s name and icon, shows when your app is installed, lets the user pick its model (and reasoning) from magpie’s catalog, follows the catalog as providers change, and on disconnect puts back what your app had before. There is no runtime registration: a row is added by a pull request to magpie, and ships in the next release.

An adapter is an [`Agent`](https://github.com/yetone/magpie/blob/main/internal/agent/agent.go) value. What your app offers decides its shape:

- **magpie edits your config file.** (most adapters; [`fx.go`](https://github.com/yetone/magpie/blob/main/internal/agent/fx.go), [`empryo.go`](https://github.com/yetone/magpie/blob/main/internal/agent/empryo.go)). `Dir`, `Path` and `Bin` find the app; each `Field` (`model`, `effort`…) has `Get`, `Set` and `Options`. Connecting adds a `magpie` provider at the gateway, keyed `magpie-<id>`, and sets your model to one of magpie’s; the agent’s default or `Unwire` takes magpie’s entries out and restores what was there. Only the keys magpie sets are touched. `Notice` says when your app must be restarted; `Sync` rewrites a model list your app keeps in a file.
- **Your app takes a provider only through its own import link, confirmed in your app.** ([`cindy.go`](https://github.com/yetone/magpie/blob/main/internal/agent/cindy.go)). `Import` returns the link (`yourapp://provider/import?…` with the gateway’s URL, the key `magpie-<id>` and the endpoints), the row’s button opens it, and the user says yes once, in your app. `Added` reads, read-only, whether your app has magpie already. magpie writes nothing of yours. This suits an app that keeps its providers in a database or encrypted.
- **Your app has a local API while it runs.** (Alma): magpie adds itself as a provider and sets the default model through it.

A pull request needs the adapter and its entry in `agents.go`, `UA` (what your User-Agent begins with, lower-case) so Usage knows your calls, an icon in `internal/gui/assets/icons`, tests that run under a temporary `HOME` (connect, switch, disconnect restoring the original file), and a row in the reference’s Agents table. What helps most is a stable, documented config format or import link, and where your app keeps it on each system.

## 3. Plugins

A plugin is an npm package magpie runs; the user installs it from Settings → Plugins or with `magpie plugin add <package>`. **Provider plugins** (OpenCode’s `auth` hook, or a pi package) add a source of models, such as a subscription magpie doesn’t sign in to itself. **Gateway middleware** rewrites requests and replies as they pass. See the [plugin guide](https://usemagpie.ai/docs/plugins). A plugin can’t add a row to the Agents page or write another app’s config, so it is not how an app registers itself.

## What isn’t there

- No API or link lets another app register itself as an agent, or install a plugin, without the user: plugins are installed in magpie by the user, and agent rows come from adapters in magpie’s source.
- `magpie://import` links add a *provider* (a source of models, with its key), not an agent or an app: see [Add to magpie](https://usemagpie.ai/docs/import).

Questions, or an adapter you’d like to discuss first: open an [issue](https://github.com/yetone/magpie/issues) or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/plugins

# Writing a plugin

A plugin signs in to a service and makes its requests. magpie turns it into a provider that every agent can use, with several accounts, failover, usage and the rest. magpie runs [OpenCode’s provider plugins](https://opencode.ai/docs/plugins/), so a plugin written for OpenCode works here unchanged, and it runs [pi](https://github.com/earendil-works/pi)’s packages that register a provider too (see pi packages). This page covers what a plugin author needs: the hooks magpie calls, what it does with their answers, and how to test, publish and list a plugin.

> **In one paragraph.** A plugin is an npm package, a git repository or a folder. Its module exports an async function in OpenCode’s v1 plugin shape. magpie loads every plugin into one [Bun](https://bun.sh) process, the *plugin host*. The function returns hooks: `config` declares the provider and its default models. `auth` gives the sign-in methods, plus a `loader` whose `fetch` makes each request. `provider.models` lists the models one account has. `auth.usage` says how much of the plan is used. It is magpie’s own hook, and OpenCode ignores it. `auth.refresh` renews an account’s token before it runs out, once at a time. It is magpie’s own hook too. `auth.checkin` presses the vendor’s daily check-in for an account. It is magpie’s own hook too. An agent can send in any API. The gateway translates the request into the API the model speaks (chat completions, Responses, Anthropic Messages or Gemini), hands it to the plugin’s `fetch`, and streams the answer back.

## A plugin in five minutes

This example signs in to Acme, a made-up coding plan. Acme takes an API key, has an OpenAI-compatible endpoint, and reports each account’s models and usage. A real plugin differs mainly in how it signs in and signs its requests. This whole example was run against magpie v0.1.676 and a local stand-in for Acme’s API.

```
{
  "name": "opencode-acme-auth",
  "version": "0.1.0",
  "description": "OpenCode provider plugin: Acme Coding Plan",
  "type": "module",
  "main": "./index.mjs",
  "files": ["index.mjs", "README.md"],
  "keywords": ["opencode", "opencode-plugin", "acme"],
  "license": "MIT",
  "magpie": { "maxConcurrency": 4 }
}
```

```
const PROVIDER = "acme"
const BASE = "https://api.acme.example/v1"

export const AcmeAuthPlugin = async ({ client }) => ({
  // the provider and the models it has before anyone signs in
  config: async (cfg) => {
    cfg.provider ??= {}
    cfg.provider[PROVIDER] ??= {
      name: "Acme",
      npm: "@ai-sdk/openai-compatible", // chat completions
      api: BASE,
      models: {
        "acme-coder": { name: "Acme Coder", limit: { context: 200000, output: 32000 }, tool_call: true },
      },
    }
  },

  auth: {
    provider: PROVIDER,
    methods: [{ type: "api", label: "Acme API key", placeholder: "acme-…" }],
    // what every request of this account is sent with
    async loader(getAuth) {
      const auth = await getAuth()
      if (auth?.type !== "api") return {}
      return {
        baseURL: BASE,
        async fetch(input, init) {
          const headers = new Headers(init?.headers)
          headers.set("authorization", `Bearer ${auth.key}`)
          headers.set("x-acme-client", "opencode-acme-auth/0.1.0")
          return fetch(input, { ...init, headers })
        },
      }
    },
    // magpie's own hook: how much of the plan is used
    async usage(getAuth) {
      const auth = await getAuth()
      const res = await fetch(`${BASE}/usage`, { headers: { authorization: `Bearer ${auth.key}` } })
      if (!res.ok) return { error: `Acme answered ${res.status}`, windows: [] }
      const u = await res.json()
      return {
        plan: u.plan,
        windows: [{ name: "5 hours", used: u.percent, resetsAt: u.resets_at, span: 5 * 3600 }],
      }
    },
  },

  // the models this account has, asked of Acme
  provider: {
    id: PROVIDER,
    async models(provider, { auth } = {}) {
      if (auth?.type !== "api") return provider.models
      const res = await fetch(`${BASE}/models`, { headers: { authorization: `Bearer ${auth.key}` } })
      if (!res.ok) return provider.models // magpie keeps the list it had
      const { data } = await res.json()
      const base = provider.models["acme-coder"]
      return Object.fromEntries(data.map((m) => [m.id, { ...base, id: m.id, name: m.name ?? m.id }]))
    },
  },
})
```

Add the folder to magpie, sign in, and try it:

```
magpie plugin add ./opencode-acme-auth   # a folder is loaded where it is; nothing is installed
magpie plugin login acme                 # asks for the key
magpie plugin                            # acme (Acme, 2 models)  signed in
magpie provider test acme                # ✓ chat  7 ms · acme-coder
magpie quota                             # acme · Pro · 5h 37% ↻59m
```

Agents now reach its models as `acme/acme-coder`, the same way as any other provider’s. In the app, open Plugins, click Add a plugin and give it the folder. Then sign in from the provider’s row.

> **Try it in a sandbox.** A plugin you are writing should never touch your real magpie. Run magpie with a `HOME` of its own, as Testing shows.

## How magpie runs plugins

- **Bun..** magpie downloads Bun the first time a plugin is added, and runs every plugin on it. Bun runs TypeScript as is, so an entry can be `index.ts`.
- **One host process..** Every plugin that is on loads into one Bun process, started the first time one is needed. magpie and the host talk over stdin and stdout, one JSON message a line. Anything a plugin prints, `console.log` and `process.stdout` included, is sent to stderr. magpie logs it as `plugin: …`.
- **Installing..** An npm package is installed with `bun add`, with its install scripts left unrun, as OpenCode installs plugins. A dependency that needs a `postinstall` build won’t work.
- Packages come from the npm registry you already use: the `registry=` in your `~/.npmrc`, `install.registry` in `~/.bunfig.toml`, or `NPM_CONFIG_REGISTRY` / `BUN_CONFIG_REGISTRY` in your shell, before the Mirrors in China switch. A token your `.npmrc` keeps for that registry is sent to it alone. To use another, change npm registry on Plugins → Discover, or run `magpie plugin registry <url>` (`default` goes back).
- A git repository is fetched by Bun: `github:owner/repo[#ref]`, `git+https://…` or `owner/repo`.
- A path to a folder or file is loaded where it is.

- The community’s packages (`@magpie-community/*`) update by themselves a little after magpie starts, then every hour.
- Any other package with a newer version shows a dot on Plugins, and in the sidebar Installed reads “1 update”. Plugins then opens on Installed, which names the plugins with a newer version at the top beside Update all; the user updates them with a click or `magpie plugin update`.
- A spec pinned to a version (`name@1.2.3`) stays on it until the user updates it: Update to …, Update all and `magpie plugin update` install the newest version and unpin it.
- A git repository has no version to compare. It shows an update when its branch or tag (the default branch without `#ref`) is at another commit than the one Bun installed: GitHub is asked through its API, any other host with `git ls-remote`, at most every ten minutes, and the hourly check asks again. A spec pinned to a commit never has one. The row shows the commit installed.

What magpie keeps, in its config folder (`~/.config/magpie`, or `$XDG_CONFIG_HOME/magpie`):

| File | What it holds |
| --- | --- |
| `plugins.json` | The plugins added: `{"plugins": [{"spec", "off"?, "options"?}], "config"?}`. `options` is the plugin’s second argument, as OpenCode’s `["name", {…}]` gives it. `config` is the OpenCode config the plugins are handed. |
| `plugins/` | The installed npm and git packages, a Bun project of their own. |
| `plugin-auth.json` | The sign-ins (mode 600), in the same shape as OpenCode’s `auth.json`, so a sign-in can be moved between the two. |
| `plugin-providers.json` | The providers and models the plugins listed last, so magpie can start without asking them. |

## The package

### Where magpie loads it from

magpie looks for the server side of a plugin in the same places OpenCode does, and loads the first file that exports a plugin:

1. `exports["./server"]`, then `main`, then `exports["."]` (or `exports` when it is a string), in `package.json`.
2. Otherwise `index.ts`, `index.tsx`, `index.js`, `index.mjs` or `index.cjs`.

A path to a single file loads that file.

### What the module exports

- `export default { id, server }` (OpenCode v1): `server` is the plugin.
- Otherwise, **every function the module exports** is called as a plugin, as is every exported `{ server }` object.

So don’t export helper functions from the entry file. Put what your tests need on an object instead, as the community plugins do with `export const _internal = { … }`.

### The function

```
async (input, options) => hooks
// input:   { client, project, directory, worktree, serverUrl, $, experimental_workspace }
// options: the entry's "options" in plugins.json, else undefined
// hooks:   { config?, auth?, provider?, "chat.headers"? }
```

A plugin may return more than one provider by exporting more than one function. Each one’s hooks are separate. When two plugins have an `auth` hook for the same provider, the one loaded last wins, as in OpenCode.

### magpie’s fields in package.json

OpenCode ignores the `magpie` object, so these are safe to add to an OpenCode plugin.

| Field | Meaning |
| --- | --- |
| `magpie.icon` | The plugin’s picture, on its card in Discover (read from npm, or from the repository for one on GitHub) and its row in Installed, and the picture of each of its providers that doesn’t give its own: an `https://` URL or a `data:image/…` URI, at most 1 MB. SVG, PNG and the like. |
| `magpie.name` | The plugin’s name on its row in Installed, and on its sidebar tab when its page gives no title, for a plugin the community’s list doesn’t name (the list’s name wins). The package’s npm name has to be ASCII, so a name like 华为云 HUAWEI goes here. One line, at most 80 bytes; anything else is ignored. It is never shown as reviewed, and never used to find a plugin by name. A repository tagged `magpie-plugin` shows it on its card under Discover → Unofficial, on GitHub too, in place of the repository’s name. |
| `magpie.summary` | Its card’s line under Discover → Unofficial, on GitHub, by language: `{ "en": "…", "zh": "…" }`, in the window’s language (zh-TW reads `zh`), else English, else GitHub’s description. One line of at most 300 bytes a language; anything else is ignored. A card showing a name or summary of the package’s own says “Its own words”: nobody reviewed them. |
| `magpie.maxConcurrency` | How many requests each account takes at once, a whole number from 1 to 1000. A limit the user sets on the provider wins over it. |

The same fields can be set on the `auth` hook (`auth.icon`, `auth.maxConcurrency`), where they win over `package.json`. A plugin that signs in to several providers can give each its own `auth.icon` and keep `magpie.icon` for the plugin itself.

## Provider and models

### Declaring the provider

The provider’s id is `auth.provider`. If [models.dev](https://models.dev) lists that id, magpie starts from its entry, as OpenCode does. Otherwise, declare the provider in a `config` hook. Use `??=`, so a provider the user configured in `plugins.json` isn’t written over:

```
config: async (cfg) => {
  cfg.provider ??= {}
  cfg.provider["acme"] ??= {
    name: "Acme",
    npm: "@ai-sdk/anthropic",          // the API its models speak (table below)
    api: "https://api.acme.example/v1", // where requests go, unless the loader says otherwise
    models: {
      "acme-large": {
        name: "Acme Large",
        id: "acme-large-2026-09",          // the id the API takes, when it isn't the key
        limit: { context: 400000, output: 64000 },
        reasoning: true,
        tool_call: true,
        modalities: { input: ["text", "image"] },
        cost: { input: 3, output: 15, cache_read: 0.3 }, // US$ per million tokens; leave out for a plan
        variants: { low: {}, medium: {}, high: {} },        // reasoning levels
      },
    },
  }
}
```

A model can also say `provider: { npm, api }` to use another API or address than the provider’s, `headers`, `options`, and `disabled: true` to hide it.

### An upstream that searches the web

When your plugin sits in front of Anthropic’s or OpenAI’s own API, which runs the hosted web search tool itself, set `searches: true` on the provider in the `config` hook. A client’s web search (Claude Code’s WebSearch, Codex’s `web_search`) then reaches your `fetch` as it was sent, on the provider’s Anthropic or Responses models, rather than going through magpie’s own search. Its Chat models are unaffected. magpie doesn’t search with it for other models by itself, but it can be named as the searcher in Settings.

### A decision API (System One)

A plugin can serve TypeSafe’s System One API for its provider, so its models can be a [routing group’s classifier](https://usemagpie.ai/docs/intent). Set `decide: true` on the provider in the `config` hook, and `decides: true` on each model that answers questions rather than a conversation, in the `config` hook or on the `models` hook’s list. magpie then posts each question as `POST {baseURL}/systemone` through your loader’s `fetch`, with the account’s sign-in, as it sends any other request. The body is `{"model", "questions", "state"}`; answer `{"model", "answers": {"<question>": {"choice", "score", "confidence"}}}`.

A marked model, and one named `jev-*`, is offered as a classifier and kept from agents: a chat request to it is refused. Without `decide: true` on the provider, `decides` is ignored and every model stays one to chat with.

### The API a model speaks

The AI SDK package named by `npm`, on the model or on the provider, decides the API. That decides the shape of the request your `fetch` receives. Whatever the agent sent, magpie’s gateway has already translated it:

| npm | API | Path after the base |
| --- | --- | --- |
| `@ai-sdk/anthropic`, `@ai-sdk/google-vertex/anthropic` | Anthropic Messages | `/messages` |
| `@ai-sdk/openai`, `@ai-sdk/azure` | OpenAI Responses | `/responses` |
| `@ai-sdk/google` | Gemini | `/models/<id>:streamGenerateContent?alt=sse` |
| `@ai-sdk/github-copilot` | Responses for GPT-5 and later (not gpt-5-mini), chat completions for the rest | `/responses` or `/chat/completions` |
| anything else (`@ai-sdk/openai-compatible`, `xai`, `groq`, `deepseek`, …) | Chat completions | `/chat/completions` |

The base is chosen in this order:

1. the loader’s `baseURL`;
2. the model’s `provider.api`;
3. the provider’s `api`;
4. the AI SDK package’s own default (`https://api.anthropic.com/v1`, `https://api.openai.com/v1`, …).

The body’s `model` is the model’s API id: its `id`, else its key.

### Each account’s models

When the models depend on the account, add a `provider` hook:

```
provider: {
  id: "acme",
  async models(provider, { auth }) {
    // provider.models: what models.dev and the config hook give, keyed by id
    // auth: this account's sign-in, as plugin-auth.json keeps it
    return { "acme-large": { ...provider.models["acme-large"], name: "Acme Large" } }
  },
}
```

- magpie calls it once for each account, in that account’s scope and through its proxy. Each account serves only the models listed for it, so an account on a smaller plan isn’t sent a model it doesn’t have.
- A model is OpenCode’s `Model`: `id`, `name`;
- `api: {id, url, npm}`;
- `limit: {context, input?, output}`;
- `capabilities: {reasoning, toolcall, attachment, input: {text, image, …}}`;
- `cost: {input, output, cache: {read, write}}`;
- `variants`, `release_date`, `status`.

- `free: true`: the plan serves it at no cost to its allowance. Only this flag makes a model free, and magpie never reads it from `rate`: set it from the vendor’s own word (its list marks the model free, or prices it at $0), not from a rate you worked out.
- `rate`: the credits a request costs, as a multiple, given as a number (`0.5`) or as the vendor writes it (`"x0.5"`). `0` reads as no rate given, not as free.
- `rateWas`: the rate before a discount that is running now.

### When the vendor can’t be reached

magpie keeps the list it already had, as it does for a built-in subscription whose list couldn’t be fetched, when the hook does any of these:

- returns `provider.models` unchanged after a fetch that failed;
- throws;
- returns a list of its own with `list[Symbol.for("magpie.fellBack")] = true`.

If what failed was the sign-in, throw an error with `signIn: "expired"` on it. The account is then marked as needing a new sign-in (see Sign-in state).

## Signing in

The `auth` hook is `{ provider, methods, loader, usage?, refresh?, refreshLead?, checkin?, icon?, maxConcurrency? }`. Each method is a way to sign in that the user can pick. In the app the methods are buttons; in a terminal, `magpie plugin login <id> [<method>]` asks which one.

### An API key

```
{ type: "api", label: "Acme API key", placeholder: "acme-…" }
```

- `label` titles the key’s field. A label that only says “API key” is shown as “Acme API key”.
- `placeholder` is magpie’s own field, a hint inside the field.
- Without an `authorize` function, the key is saved as is: `{type: "api", key, metadata?}`. Answers to `prompts` go in `metadata`.
- With `authorize(inputs)`, the plugin checks or exchanges the key itself. It returns `{type: "success", key, metadata?}` or `{type: "failed", error?}`.

### A browser or device sign-in

```
{
  type: "oauth",
  label: "Sign in with Acme",
  async authorize(inputs) {
    const d = await startDeviceCode()
    return {
      url: d.verification_uri,                    // magpie opens it
      instructions: `Enter the code ${d.user_code}`, // and shows this
      method: "auto",                              // "auto": callback() resolves on its own
      async callback() {                           // "code": callback(code), the code the user pastes
        const t = await pollForToken(d)
        if (!t) return { type: "failed", error: "The code expired" }
        return { type: "success", refresh: t.refresh_token, access: t.access_token,
                 expires: Date.now() + t.expires_in * 1000, accountId: t.email }
      },
    }
  },
}
```

- A success with `refresh` is saved as `{type: "oauth", refresh, access, expires, …}`, with every other field you return kept beside them (`accountId`, `enterpriseUrl`, your own).
- A success with `key` is saved as an API key.
- `provider: "other-id"` on the result saves the sign-in to another provider the plugin signs in to.
- `error` on a failure is magpie’s own field: the user sees why (up to 500 characters). Without it, they see only that the sign-in failed.
- When `authorize` can’t start the sign-in, throw, or return `{type: "failed", error}` with no `callback`: the user sees that reason.
- A sign-in the user cancels, or that times out, is over: whatever `callback` returns after it is dropped, and the fetches it makes for it fail. magpie also passes the sign-in’s `AbortSignal` as `callback(code, { signal })` (and `authorize(inputs, { signal })`), so a callback that waits a long time can stop when it aborts.
- `inputs` is passed only to a method with `prompts`. A method without prompts gets `undefined`, as OpenCode’s TUI calls it. An empty object is how OpenCode’s CLI calls, and some plugins then ask on the terminal.

### Questions before signing in

A method’s `prompts` are asked in order before `authorize`, each only when its condition holds:

```
prompts: [
  { type: "select", key: "region", message: "Region",
    options: [{ label: "Global", value: "global" }, { label: "China", value: "cn", hint: "acme.cn" }] },
  { type: "text", key: "team", message: "Team id", placeholder: "t-…",
    when: { key: "region", op: "eq", value: "global" },        // or condition: (inputs) => boolean
    validate: (v) => (/^t-/.test(v) ? undefined : "Starts with t-") },
]
```

A `type: "password"` question is a `text` one typed unseen: a masked field in the app, and no echo in `magpie plugin login` on a terminal. Use it for a token or a personal access token. It is magpie’s own type: OpenCode’s are `text` and `select`.

### Accounts

- **Where they are kept..** A provider can be signed in to more than once. The first account is kept under the provider’s id, as OpenCode keeps it. Others are kept under `id#xxxxxx`.
- **How the user tells them apart..** magpie names an account by `accountId`, else `metadata.email`, else `email`. Save one of them, an email where you have one.
- **Signing in again..** A new sign-in replaces an existing account when both have the same `accountId`. Where both also have a `uid` (the vendor’s own id, for vendors whose names can repeat), it must match too. Without an id, the same secret matches. Otherwise the sign-in becomes a new account.
- **Scope..** Every call magpie makes for an account runs in that account’s scope: `getAuth()` returns that account.
- `client.auth.set({ path: { id: "acme" }, body })` saves to that account.

### Renewing a sign-in

From magpie 0.1.684, a plugin can leave renewing its tokens to magpie with `auth.refresh`, magpie’s own hook (OpenCode ignores it):

```
auth: {
  provider: "acme",
  methods: [ … ],
  // optional: how long before expires to renew (ms), 5 minutes by default
  refreshLead: 5 * 60 * 1000,
  async refresh(auth, provider) {  // auth is the account's saved sign-in
    const t = await exchange(auth.refresh)
    if (t.error === "invalid_grant")
      throw Object.assign(new Error("Acme refused the sign-in"), { signIn: "expired" })
    return { access: t.access_token, refresh: t.refresh_token ?? auth.refresh,
             expires: Date.now() + t.expires_in * 1000 }
  },
  loader: async (getAuth) => ({ … }),  // getAuth() already gives the renewed token
}
```

- **When it runs..** For an OAuth account whose `expires` is less than `refreshLead` away, before the account’s loader, `provider.models`, `auth.usage` or a request. An account with `expires` 0 or none is never renewed.
- **Once at a time..** Requests that find the token due wait for one renewal, so a vendor that spends a refresh token once never sees it twice. They wait up to 15 seconds; a renewal that takes longer is still saved when it ends.
- **What is saved..** The fields you return are kept over the account’s old ones (merged, unlike `client.auth.set`), and the account’s mark is cleared. Return nothing when there is nothing to renew.
- **When it fails..** The account is left as it was and the request goes on with the old token, for the vendor’s answer to tell. An error with `signIn: "expired"` marks the account (see Sign-in state), and magpie doesn’t try again until it is signed in again. Any other error is tried again after 30 seconds.
- **OpenCode and older magpie..** They ignore the hook. Keep the check in your `fetch` too if the plugin runs there: under magpie it finds the token fresh and does nothing.

## Requests

`loader(getAuth, provider)` runs once per account and is run again after its sign-in changes. It returns what OpenCode would give the AI SDK:

| Field | What magpie does with it |
| --- | --- |
| `baseURL` | Where requests go, ahead of the model’s and provider’s `api`. |
| `apiKey` | Sent as the AI SDK package sends it: `x-api-key` for Anthropic, `x-goog-api-key` for Google, `Authorization: Bearer` otherwise. For an API-key sign-in, it defaults to the saved key. |
| `headers` | Added to every request. |
| `fetch` | Makes the request. Without it, magpie’s host uses the standard `fetch`. |

The request your `fetch(input, init)` receives:

- `input` is the full URL: the base plus the path for the model’s API.
- `init.method` is usually `POST`.
- `init.headers` are set in this order, each overriding the one before: the key header from `apiKey`;
- the loader’s `headers`;
- the gateway’s request headers;
- what `chat.headers` hooks add.
- `init.body` is the JSON string in that API’s shape (bytes when it isn’t UTF-8 text). `model` in it is the API id, and `stream` is whatever the agent asked for.
- `init.signal` aborts when the agent gives up on the request.

Return a `Response`. Its status, headers and body go back as they come, streamed chunk by chunk. If you rewrite a streaming body, drop `content-length` and `content-encoding` from the headers.

### Failures and failover

- A non-2xx response is the vendor’s answer. The gateway handles it as it would any provider’s: a rate limit or a server error moves the request to the next account or model, and a 401 marks the account (see Sign-in state). Answer a model the account may not use with 403 or 404 and the vendor’s words, not 401: the gateway reads that as the model refused, not the sign-in.
- A thrown error fails the request, and failover moves on.
- Answer in the API’s own error shape where you can, so the agent shows the vendor’s message.

### chat.headers

OpenCode’s `chat.headers` hook runs for every request. Its `input.sessionID` is magpie’s conversation id, which stays the same across a conversation’s turns. Use it for a vendor’s session or cache header:

```
"chat.headers": async (input, output) => {
  if (input.model.providerID === "acme") output.headers["x-acme-session"] = input.sessionID
}
```

## Sign-in state

magpie marks an account whose sign-in the vendor refused. It shows the mark to the user and stops sending to the account until it works again. By default a 401 marks the account and a success clears the mark. A plugin can say more precisely what an answer means with the `X-Magpie-Sign-In` response header, which magpie removes before the answer goes on:

| Value | Meaning |
| --- | --- |
| `expired` | The sign-in was refused, whatever the status (a vendor that answers 403 or 502 for it). |
| `kept` | Leave the account as it is (a 401 that is about something else). |
| `renewed` | The sign-in renewed: clear the mark, whatever the request then met. |

A 401 without the header whose body says only that the model isn’t served (“model … not available”, `model_not_found`, “模型不支持”) and nothing of a token, key, session or sign-in is read as `kept`. Before, it marked every account the request failed over to as needing a new sign-in. A 401 that names the model and also says the token is invalid still marks the account.

From `fetch` or `provider.models`, throw an error with `signIn: "expired"` on it for the same effect:

```
throw Object.assign(new Error("Acme refused the sign-in; sign in again"), { signIn: "expired" })
```

## Usage

`auth.usage(getAuth, provider)` is magpie’s own hook. It says how much of an account’s allowance is used. It runs in the account’s scope, so a token it refreshes is saved to that account. magpie shows its answer on the account in Providers, in `magpie quota` and at `GET /v1/magpie/quotas` on the gateway. Every field is optional:

```
{
  plan: "Pro",
  user: "ada@example.com",     // the account as the vendor names it
  until: "2026-11-01T00:00:00Z", // the plan's end
  renew: "auto",                // or "off"
  balance: "$12.40",
  error: "",                    // shown in place of the windows
  windows: [{
    name: "5 hours",
    used: 37,                   // percent; past 100 when overspent
    resetsAt: "2026-10-03T18:00:00Z", // or resetSecs: 3600
    span: 18000,                // seconds the window runs
    display: "370 / 1000 credits",
    amount: 370, limit: 1000, unit: "credits", // its own count, when it counts amounts
    model: "opus",              // counts only models whose ids hold this word
    models: [], notModels: [],  // or exactly these ids, or all but these
    aside: false,               // true: using it up doesn't stop the account
    runsOutAt: "2026-10-05T00:00:00Z", runsOut: 120, // when the soonest credits left are lost, and how many
    balance: 6291,              // a prepaid wallet: what is left, in unit; no used or limit
  }],
  resets: { count: 2, until: "…", byWindow: false, fiveHour: 1, weekly: 1 }, // resets the account may spend
  signIn: "kept",               // as X-Magpie-Sign-In
}
```

Times are ISO strings or epoch numbers, in seconds or in milliseconds. Without `signIn`, an `error` that says to sign in again marks the account, and a clean read clears the mark.

Leave `used` out when the vendor doesn’t tell it, never send 0 for “not known”. Left out with `amount` and `limit`, the share is theirs (370 of 1000 is 37 used). Left out with no count, the window is its `display` alone: routing doesn’t read it, and an account whose windows all say nothing is weighed as one never read, not as the one with the most left. A window with `aside: true` is shown on the account’s card, with its share and count, and in `GET /v1/magpie/quotas`, but routing never reads it: using it up doesn’t stop the account or weigh it against the others, whatever `amount` and `limit` say. Leave `aside` off a window the account really stops at.

## Check-in

A vendor that gives credits for a daily check-in can have the plugin press it with `auth.checkin`, magpie’s own hook (OpenCode ignores it). magpie runs it for each signed-in account once a Beijing day while the user has check-in on for the provider, and shows what came of it on the account’s Usage card and in Settings.

```
auth: {
  provider: "acme",
  async checkin(getAuth, provider) {
    const auth = await getAuth()
    const r = await claim(auth.access)
    if (r.already) return { outcome: "done" }
    return { outcome: "claimed", credit: r.points, streak: r.days, message: r.text }
  },
}
```

It answers `{ outcome, credit?, streak?, message? }`:

| `outcome` | Meaning |
| --- | --- |
| `claimed` | Checked in now. `credit` is what it gave. |
| `done` | Checked in already today. A vendor that answers 2xx with nothing left to claim is `done`, not `failed`. |
| `ineligible` | The account can’t take part. |
| `inactive` | No check-in is running. |
| `captcha` | The vendor asks for a captcha. Never solve it: the user checks in in the vendor’s own app. |
| `failed` | It didn’t work. magpie asks again later that day. |

`streak` is the days in a row, and `message` is shown as it is. A hook that throws, or answers no outcome above, is `failed`. It runs in the account’s scope, so a token it renews with `client.auth.set` is saved to that account.

## Model load

A vendor that queues requests to a busy model can have the plugin say how busy each model is, with `input.magpie.load(provider, loads)`, magpie’s own (OpenCode has none). `loads` maps a model id to a percent from 0 up, or to `null` to say it isn’t known any more. The plugin calls it whenever it likes, from its own timer: magpie doesn’t ask for it.

```
export default async (input) => {
  const report = async () => {
    const r = await fetch(`${BASE}/load`).then((r) => r.json()).catch(() => null)
    if (r) input.magpie?.load?.("acme", { "acme-large": r.large, "acme-small": r.small })
  }
  report()
  setInterval(report, 60_000)  // within five minutes, or the load is unknown again
  return { auth: { /* … */ } }
}
```

- **Values..** 100 is as busy as the vendor serves at once; a vendor that queues reports past it (200 is twice that). A number below 0 counts as 0, and one past 10000 as 10000, a sanity cap. Anything else (a string, `NaN`) is dropped. Model ids match whatever their case, and `model@256k` has its model’s load unless reported itself. One call takes up to 1000 models and returns how many it took. A provider that isn’t a string, or a `loads` that isn’t an object, throws a `TypeError`.
- **Freshness..** Each model’s load counts for five minutes from the call that reported it. After that it is unknown, never 0: a plugin that stops calling leaves its models where they were. A model a call doesn’t name keeps its last load until its own five minutes run out.
- **Where it shows..** The provider editor shows it by the model, a small grey number.
- **Routing..** With Settings › Network and sharing › Busy models last set (Off by default; over 50, 70, 80 or 90%, or Custom… for any number from 1 to 9999, such as 150 for a vendor that queues), a model reported busier than that goes behind every other candidate a request could go to, ahead of those resting after a failure. A conversation it answered moves to the one that leads at its next turn; within a turn it stays. A model with no load known keeps its place. The Routing trace says `busy` with the load.

A plugin written for older hosts checks `input.magpie?.load` first, as above.

## What a plugin is given

magpie hands a plugin what OpenCode’s `PluginInput` has, as far as it has meaning without an OpenCode server:

| Field | In magpie |
| --- | --- |
| `client.auth.set` / `.remove` | Saves or forgets the sign-in of the account in scope. |
| `client.app.log` | Writes to magpie’s log as `plugin [level]: [service] message`. |
| `client.tui.showToast` | Written to magpie’s log. |
| `client.config.get` | The config after every plugin’s `config` hook. |
| any other `client.*` | Answers `{ data: undefined }`. |
| `directory`, `worktree` | magpie’s config folder, a place to keep files. |
| `project` | `{ id: "magpie", worktree }`. |
| `$` | Bun’s shell. |
| `serverUrl` | A placeholder; no OpenCode server is behind it. |
| `magpie.option`, `.options`, `.load` | magpie’s own: the plugin’s options as the user set them, and its models’ load. |

The hooks magpie calls are `config`, `auth` (its methods, `loader`, `usage`, `refresh` and `checkin`), `provider.models` and `chat.headers`. A plugin’s other hooks (`tool`, `event`, `chat.params`, …) are not called. The agent runs its own tools.

## Provider ids

- Agents name a plugin’s model as `<id>/<model>`, where the id is the plugin’s `auth.provider`.
- When the id is taken in magpie, by a built-in subscription, a preset (`google`, `openai`, `anthropic`, …) or `magpie` itself, the plugin’s provider is named `<id>-plugin`. Pick an id that is only yours.
- The community’s plugins for magpie’s deprecated built-in subscriptions are the exception. They use the built-in’s id (`cursor`, `zed`, …) and take it over once the user moves onto the plugin, so agents keep working unchanged.
- When two installed plugins sign in to the same id, such as a published plugin and your own copy of it, one of them serves it: the one picked for it, otherwise the one added last. Both stay in Plugins → Installed, and each row says which one serves the provider. Use for … on the other row, or `magpie plugin use <name> <id>`, makes the pick.

## Testing

Run magpie in a sandbox, so your own magpie, its agents and sign-ins are never touched:

```
sb=$(mktemp -d)
m() { env HOME=$sb XDG_CONFIG_HOME=$sb/.config XDG_CACHE_HOME=$sb/.cache MAGPIE_ADDR=127.0.0.1:3499 magpie "$@"; }
m plugin add ./opencode-acme-auth </dev/null
m plugin --json                     # what the plugin lists: methods, accounts, models, load errors
m plugin login acme                 # each method, each prompt
m provider test acme                # one tiny request per API
m provider test acme acme-coder     # or to the models named
m quota                             # the usage hook
m plugin logout acme
```

- A plugin that fails to load says why in `magpie plugin`.
- Hook errors and everything a plugin prints are in the output, as `plugin: …` lines.
- For unit tests, run `bun test` against the functions you put on `_internal`.
- The [community repository](https://github.com/magpie-community/plugins) has a few scripts: `bun scripts/check.mjs` loads each package as magpie does and checks its hooks.
- `scripts/try.sh <name>` runs it in a sandbox like the one above.

## Publishing and listing

- **npm..** Publish the package as usual. Users add it by name (`magpie plugin add opencode-acme-auth`), by a version (`…@0.2.0`), from git, or from a folder.
- **Search..** The search on Plugins asks npm for `<query> opencode`. It shows a package whose name or keywords hold `opencode` and one of `auth`, `plugin` or `provider`. Keywords like `["opencode", "opencode-plugin", "<vendor>"]` do it. It also asks for `keywords:pi-package <query>` and shows a pi package whose name or keywords mention `auth` or `provider`.
- **README..** A plugin’s page in magpie shows its npm README. Say what it signs in to, how, where the sign-in is kept, and which models it has.
- **The list..** Plugins suggests the plugins in [`registry.json`](https://github.com/magpie-community/plugins/blob/main/registry.json) of the community repository. magpie fetches it at most every six hours and builds in a copy for when it can’t. To be listed, open a pull request adding an entry: { "package": "opencode-acme-auth", "name": "Acme", "icon": "https://acme.example/icon.svg", "providers": ["acme"], "summary": { "en": "Your Acme Coding Plan.", "zh": "使用你的 Acme Coding Plan。" } } A middleware’s entry has `"kind": "middleware"` and no `providers`; it is listed under Gateway middleware. The other kinds are listed the same way: `"kind": "tools"` under Tools for agents, `"kind": "page"` under Pages and `"kind": "agent"` under Agents. Those sections hold the community’s own packages, whose entries have `"community": true`. A package published from your own repository leaves that out: it isn’t in the sections, the search on Plugins finds it by its name, summary or publisher, and its card shows its npm publisher, not the magpie community badge. `MAGPIE_PLUGIN_MARKET=<url>` points magpie at another list, which is useful to check yours, and `off` keeps to the built-in copy.
- **A GitHub topic..** A repository tagged `magpie-plugin` on GitHub is shown under Plugins → Discover → Unofficial, on GitHub, the most starred first, marked as reviewed by no one. Keep `package.json` at the repository’s root. Published to npm with `repository` naming the repository, it is installed from npm; otherwise from the repository as it stands, so the file it loads must be committed: one whose `dist` is built only to publish is left out. Forks, archived repositories and magpie-community’s own are left out too. magpie asks GitHub at most every ten minutes, so a repository shows within minutes of being tagged. Its card shows the icon `"magpie": { "icon": "…" }` in its `package.json` gives, else a puzzle piece. Its licence is the one GitHub reads from the repository’s `LICENSE` file; when GitHub can’t match the file to a licence (it says `NOASSERTION`, as for MIT’s text with a line added) or there is none, the card shows `package.json`’s `license`. A plugin installed from npm shows `package.json`’s.
- **The community packages..** To contribute one to [magpie-community/plugins](https://github.com/magpie-community/plugins): Put it under `packages/<name>`, named `@magpie-community/opencode-<name>-auth` (a provider) , `@magpie-community/middleware-<name>` (middleware or a routing strategy), `@magpie-community/tools-<name>` (tools), `@magpie-community/page-<name>` (a page) or `@magpie-community/agent-<name>` (an agent), with no runtime dependencies unless one is really needed.
- Pushing a version bump to `main` publishes it.
- These packages update by themselves in every magpie.

## Async gateway request hooks

A plugin can await I/O before an agent request is routed, for example to recall project context. Declare `"magpie": { "hooks": "./hooks.js" }` in package.json, or add a `*.hooks.js` / `.mjs` / `.ts` / `.mts` file (Bun runs TypeScript without a build step). Export a named async `onRequest(body, ctx)`. A gateway-only package needs no OpenCode main/exports.

Optional async `onResponse(reply, ctx)` receives a best-effort completion notification after output finishes. It cannot change the reply and never holds the live stream. Client tool declarations and tool loops stay with the client.

It runs in Bun once per agent request, before the JS gateway middleware, for every provider, Codex's own ChatGPT sign-in included. body is the agent API object. ctx contains `protocol`, `model`, `stream`, `path`, `agent`, `session`, `cwd`, `query`, `options` and `signal`. The query is the latest user text, excluding tool results and images. Missing identity fields are empty; authorization headers are never included.

Return an object to replace the request, or undefined to keep it. A hook that changes the model, streaming, the client's tools or its tool choice is rolled back, as a failure, and gets no `onResponse` for that request. Each hook receives a clone; mutations from failed or undefined hooks are discarded. Successful changes follow enabled plugin order. Each hook defaults to one second; `gatewayTimeoutMs` accepts integers from 100 to 10000 milliseconds. The chain sums budgets, clamped to 2–10 seconds; startup plus RPC is bounded to 11 seconds. Settings → Plugins offers JSON options and call, latency, failure and outcome diagnostics. `ctx.report(code, bytes)` accepts ready/empty/unbound/unauthorized/unavailable/invalid/skipped and byte counts only. Statistics reset on reload and retain no private text. Use `ctx.signal` with fetch. Errors, invalid returns, timeouts and a host busy starting keep the request. Bun plugins have host privileges; install trusted code.

Install with `magpie plugin add ./my-plugin`; save options with `magpie plugin options my-plugin '&lbrace;"serverUrl":"http://127.0.0.1:8000"&rbrace;'`. On/off and options changes reload the host; source-only edits need a configuration reload. Internal title/classifier requests skip the hook.

## Gateway middleware

A plugin can also be *gateway middleware*: code that magpie’s gateway runs on every request an agent sends it, before the request is routed, and on the reply on its way back. It can give a model another name, add to the system prompt, turn a request away, change or hide what the model says, or keep its own count of what goes through. It works with every provider, a plugin’s or not.

```
// alias.middleware.js
export const events = ["message_start"]

export function onRequest(body, ctx) {
  ctx.state.asked = body.model
  if (body.model === "fast") body.model = "deepseek/deepseek-chat"
  if ((ctx.options.blocked ?? []).includes(body.model)) return ctx.reject(403, "not this model")
  return body
}

export function onEvent(ev, ctx) {
  ev.message.model = ctx.state.asked  // the agent sees the name it asked for
  return ev
}
```

```
magpie plugin add ./alias.middleware.js   # or a package whose package.json has "magpie": { "middleware": "./mw.js" }
```

### Ready-made middleware

The community repository has middleware ready to add, most of it what [New API](https://github.com/QuantumNous/new-api) does for its channels, taking the same JSON. They are under Plugins → Discover → Gateway middleware, and every card there says whether it is a provider or middleware.

| Package | What it does |
| --- | --- |
| [`param-override`](https://github.com/magpie-community/plugins/tree/main/packages/param-override) | New API’s `param_override`: set, delete, move, copy or rewrite fields of the request, for some models or under conditions, or turn a request away. A `param_override` copied from New API works unchanged. |
| [`model-map`](https://github.com/magpie-community/plugins/tree/main/packages/model-map) | New API’s `model_mapping`: send a model under another name, by name or `/pattern/`. Replies name the model the agent asked for. |
| [`system-prompt`](https://github.com/magpie-community/plugins/tree/main/packages/system-prompt) | A system prompt of yours on every request, or only some agents’ or models’, in each API’s own place. A request with its own keeps it unless `override` is on. |
| [`word-guard`](https://github.com/magpie-community/plugins/tree/main/packages/word-guard) | New API’s sensitive-word filter: turn away or mask words and patterns in what users send, and in replies if you like. |
| [`think-tags`](https://github.com/magpie-community/plugins/tree/main/packages/think-tags) | Take a `<think>…</think>` block out of the start of a reply’s text, or put a Chat reply’s `reasoning_content` into it (New API’s `thinking_to_content`). |
| [`antigravity-cloak`](https://github.com/magpie-community/plugins/tree/main/packages/antigravity-cloak) | Breaks up the words Antigravity turns Claude Code’s and the Agent SDK’s system prompts away for, in what it sends Antigravity only. Other providers are sent the prompt as it was. |

```
magpie plugin add @magpie-community/middleware-model-map
magpie plugin options model-map '{"mapping": {"fast": "deepseek/deepseek-chat"}}'
```

### Options

A middleware reads its settings from `ctx.options`, which are its entry’s `options` in `plugins.json`. Set them in Plugins → Installed with the middleware’s Options button, which edits them as JSON in its row, or with `magpie plugin options <name> '<json>'` (`off` clears them). The name can be the package’s, its spec, or its short name: `model-map` for `@magpie-community/middleware-model-map`. They apply from the next request on. A package can suggest options with `"magpie": { "options": { … } }` in its `package.json`: the editor starts from those when none are set, but a middleware runs with no options until you save some. A key that a provider plugin declares as a switch (its editor’s Plugin options, such as Cursor’s `wire_trace`) is saved as that switch: `magpie plugin options cursor '&lbrace;"wire_trace": true&rbrace;'` turns it on, and `off` puts every switch back to the plugin’s default.

### How it runs

Middleware isn’t run on Bun. It runs inside the gateway’s own process, in [moejs](https://github.com/MoeForge/moejs), a JavaScript engine written in Go, because a reply streams thousands of events and each one waits for it. A hook on one event costs about a microsecond; a round trip to Bun would cost tens. Each middleware is compiled once, and each request gets a runtime of its own, so requests run in parallel and a request’s hooks share `ctx.state`.

- **Declaring it..** `"magpie": { "middleware": "./mw.js" }` in `package.json`, or a single file named `*.middleware.js` (or `.mjs`). A package with no `main` and no `exports` is only middleware, and the plugin host leaves it alone; one with both is a provider plugin and middleware at once.
- **Imports..** Only files inside the plugin, by relative path. There is no `node_modules` here: bundle what you import into the file.
- **What it has..** Standard JavaScript and `console.log` (into magpie’s log, at most 60 lines a minute). There are no timers, no `fetch` and no Node APIs. A hook may be `async`, but there is nothing for it to wait on.
- **Changes..** magpie looks at the files and `plugins.json` once a second, and loads a middleware again when they changed.

### The hooks

Each is a named export or a member of `export default { … }`. Bodies and events are in the agent’s own API (`ctx.protocol`), not the provider’s. Return the object to send on, or nothing to send it on as it was.

| Hook | Is given | Returns |
| --- | --- | --- |
| `onRequest(body, ctx)` | The request body, before routing: a new `model` routes it elsewhere. | The body, or nothing. `ctx.reject(status, message)` turns the request away with that error, in the agent’s API (403 when no status is given). |
| `onAccount(account, ctx)` | The subscription account a try is about to go to, before anything is sent: `account` has `ref`, `provider`, `name`, `kind` (such as `codex` or `claude`) and `model`. `ref` stands for the account without naming it: 32 hex characters, the same on every request and after magpie restarts, and different for each middleware, so a middleware can remember an account without ever being told its email or id. A new plan gives the account a new `ref`. Not called for an API key. `ctx.account` is the same object in the hooks after it for that try. | `{skip: true}` passes the account over for this request: the next account or key is tried, and the account isn’t rested or held against. When every one is passed over, the agent gets the usual error that none is ready, and nothing is sent. Anything else, or nothing, uses the account. |
| `onProvider(body, ctx)` | The request body as it is about to go to one provider; `ctx.provider` has its `id`, `name`, `account` (the subscription’s kind, such as `claude` or `antigravity`; absent for an API key) and `model`. It is called again for each provider a request is tried on, each time with the body `onRequest` left, so a change for one provider reaches no other. | The body, or nothing. The request is routed by now: it can’t be turned away or sent elsewhere. |
| `onEvent(event, ctx)` | Each event of a streamed reply: its `data:` JSON. | The event, nothing, or `null` to leave the event out. |
| `onResponse(body, ctx)` | A reply that isn’t streamed, whole; `ctx.status` is its status. | The body, or nothing. |

`export const events = ["content_block_delta"]` calls `onEvent` only for events of those names (Anthropic Messages and Responses name theirs). Chat Completions and Gemini events have no name, so leave `events` out for them. An event holds a piece of the reply, so a word can be split over two events. A `data: [DONE]` line and comments pass by unseen. A compressed reply passes as it is.

`ctx` has `protocol` (`anthropic`, `chat`, `responses` or `gemini`), `model` and `stream` as the agent asked, `path`, `agent` when magpie knows it, `options` (the plugin’s options) and `state`, an object of the request’s own.

### When a hook fails

A hook has 250 ms for a request, a provider’s try or a whole reply and 50 ms for an event; loading has a second. A hook that throws, runs out of time or returns something else goes on as if it weren’t there: the request or the event is sent as it was. Settings → Plugins shows each middleware’s hooks, how many calls it had, the average time each took and how many failed, with the last error. The hooks see what the agent sent and gets back, before magpie’s redaction on the way out and after it on the way back. magpie’s own requests (thread titles, the router’s classifier, the web searches and image descriptions it makes for an agent’s request) don’t go through middleware.

### Routings and usage rows

The same module can also export `strategies` and `onUsage`. Such a file can be named `*.gateway.js`, and a package can say `"magpie": { "gateway": "./gw.js" }`.

- **Routings..** Each `strategies[name]` is a routing named `<plugin>/<name>` (the package’s short name, or the file’s name without `.gateway.js`), offered in every routing picker of a provider, a pool and a group while the plugin is on. It is a function `(pool, seats, options)`, or an object with `order`, and returns the order to try the seats in, as indexes. Each seat has `key`, `account`, `known`, `learns`, `used`, `soon` (when its windows renew, in ms), `pace`, `weight`, `resting` and `tokens` (what it was sent lately). It has 20 ms; if it throws, takes longer or returns something else, the seats are tried in their listed order. Off, a provider or group routed by it is too.
- **Usage..** `onUsage(row, options)` gets each request’s usage row after it ends: provider, account and key, model, tokens, `ms`, `ttftMs`, status, error type and cost, never a body, prompt or error text. It runs on its own, so a request never waits for it; rows that come while it is busy past a queue are dropped and counted. It has 250 ms.

```
// spread.gateway.js
export const strategies = {
  "fewest-tokens": (pool, seats) =>
    seats.map((_, i) => i).sort((a, b) =>
      (seats[a].resting - seats[b].resting) || (seats[a].tokens - seats[b].tokens)),
}

let slow = 0

export function onUsage(row, options) {
  if (row.ms > (options.slowMs ?? 30000)) {
    slow++
    console.log(`slow: ${row.provider} ${row.model} ${row.ms} ms (${slow} so far)`)
  }
}
```

```
magpie plugin add ./spread.gateway.js
magpie group set fast routing=spread/fewest-tokens
```

## Tools for every agent

A plugin can give tools, with OpenCode’s `tool` hook, and magpie offers them to every agent, not only OpenCode: they are an MCP server of magpie’s own at `/mcp/magpie/tools` (Streamable HTTP). Add that address to any agent that takes an MCP server, and its model can call every tool your plugins that are on give. Each is named `<plugin>_<tool>`, the plugin’s short name first: `weather-tools_now` below.

```
import { tool } from "@opencode-ai/plugin"

export const WeatherTools = async () => ({
  tool: {
    now: tool({
      description: "The weather now in a city.",
      args: { city: tool.schema.string().describe("A city, e.g. Berlin") },
      async execute({ city }, ctx) {
        const r = await fetch(`https://wttr.in/${encodeURIComponent(city)}?format=3`, { signal: ctx.abort })
        return await r.text()  // text; an object is sent as its JSON
      },
    }),
  },
})
```

```
magpie plugin add ./weather-tools
claude mcp add --transport http magpie-tools http://127.0.0.1:3425/mcp/magpie/tools   # Claude Code; other agents take the same address
```

Settings → Plugins lists each plugin’s tools by these names and copies the server’s address. `args` is a zod shape (`tool.schema` is zod), a zod object or a JSON Schema object. The agent is shown it, and magpie checks a call’s arguments against it before `execute` runs; a wrong argument is answered as an error naming it. `ctx` is OpenCode’s, with `agent` the agent that called. A tool has 55 seconds, and `ctx.abort` fires when they are up.

The built-in plugin Plugin tools serves the server. It stays on while a plugin that is on gives a tool; off, no tool is listed and a call says so. A call made with a gateway key counts against that key’s limits. A tool runs in the plugin host with your rights, as a provider plugin does, and its answer goes only to the agent that called it.

Each plugin that gives tools is also a server of its own in the Library’s MCP tab, named by the plugin’s short name (`search1api`), so you don’t have to add the address by hand. With the [MCP router](mcp-router.html) on, its tools are in the router of every agent the router is given, as `search1api__search`; switch it on or off per agent, or turn single tools off, as with any Library server. Removed, it comes back only when you remove the plugin and add it again.

To keep a plugin for its providers but give its tools to no agent, press Hide from agents on its tools line under Plugins › Installed. Its server is then given to no agent, nor to an app at the router’s address, through updates, the plugin off and on, and restarts. Give to agents gives it back to the agents it had.

## Agent plugins

A plugin can also add an *agent*: one magpie has no setup of its own for. It says where the agent keeps its model and what else to write there for the agent to use magpie’s gateway. The agent is then on the Agents page like magpie’s own: pick one of magpie’s models in its row and magpie writes it into the agent’s config, with the gateway’s address and a key of the agent’s own; switch it off and everything goes back to how the user had it. The example below adds [Aider](https://aider.chat).

```
// agent.js, named by "magpie": { "agent": "./agent.js" } in package.json
export const agent = {
  id: "aider", name: "Aider", bin: "aider",
  config: "~/.aider.conf.yml",  // the file magpie edits
  model: "model",                 // the key of the model in it
  prefix: "openai/",              // written before magpie's model id
  ua: ["aider", "litellm"],
  notice: "Aider reads its settings when it starts: restart it to use the new model.",
}

export function connect({ gateway, model }) {
  return {
    "openai-api-base": gateway.v1,
    "openai-api-key": gateway.key,
    "show-model-warnings": false,
  }
}
```

```
magpie plugin add ./agent-aider   # or a single *.agent.js file
```

### The agent export

| Field | What it says |
| --- | --- |
| `id` | Its id, as the Agents page, usage and the CLI name it: lower-case letters, digits, `.`, `_` and `-`. One of magpie’s own agents’ ids (`codex`, `claude`, …) is refused: a plugin adds an agent, it doesn’t replace one. |
| `name` | What the page calls it. The id when left out. |
| `config` | The file magpie edits. `~` and `$VAR` are expanded. It is made when it isn’t there. |
| `format` | `json`, `yaml` or `env`, when the file’s name doesn’t say it (`.json`/`.jsonc`, `.yaml`/`.yml`, `.env`). TOML isn’t supported yet. |
| `model` | The key of the model in the file, as a dotted path for JSON and YAML (`llm.model`). Leave it out for an agent whose model is picked in the agent itself, among the models `connect` writes (Raycast): the row is then a switch with no model picker, and `connect`, which such a plugin must have, is called without `model`. |
| `startup` | For an agent that keeps the model a session starts on in another file than the one `connect` writes, in place of `model`: `config` and `format` of that file, `model` the key of the model in it, and `keys` written beside the model as they are. PiG keeps its providers in `models.json` and its default in `settings.json`: `startup: { config: "~/.pig/agent/settings.json", model: "defaultModel", keys: { defaultProvider: "magpie" } }`. The row then picks the model, and each file is put back as it was. A magpie older than v0.1.3008 reads such a plugin as one with no `model`. |
| `prefix` | Written before magpie’s model id: `openai/` for an agent that reaches OpenAI-compatible endpoints through LiteLLM. The id itself is `<provider>/<model>`, as the gateway takes it. |
| `bin`, `dir` | The command on `PATH` and the folder that say the agent is installed. |
| `ua` | Words of the agent’s User-Agent, to name its requests in Usage when they come without its key. |
| `icon` | A picture for its row: an icon name, an `https://` or `data:` URL. The plugin’s own icon, else a generic one, when left out. |
| `notice` | Said after its model is changed, as for magpie’s own agents. |
| `library` | Where the agent reads what the Library gives: `instructions` (a Markdown file it reads before every conversation), `mcp` (its MCP servers file) with `mcpFormat`, the agent whose file it is shaped like (`alma`, `antigravity`, `claude`, `cline`, `codex`, `commandcode`, `copilot`, `crush`, `cursor`, `devin`, `gemini`, `goose`, `grok`, `hermes`, `kimi`, `omp`, `opencode`, `zed`; `claude` is `{"mcpServers": {…}}`), and `skills` (a folder of `SKILL.md` folders). Each is optional, with `~` and `$VAR` expanded: `library: { instructions: "~/.toy/AGENTS.md", mcp: "~/.toy/mcp.json", mcpFormat: "claude", skills: "~/.toy/skills" }`. Without it the agent is given nothing from the Library, and giving it an item is refused, naming the key its plugin would set. |

### connect

`connect(input)` returns the other keys to write beside the model, by key path, each with its value; it may be `async`. It is given `gateway` (`url`, `v1` — the URL ending in `/v1` — and `key`, the agent’s own key, which counts its requests under its id), `model` (`id`, `name`, `context`, `output`, `images`, `efforts`, and as `/v1/models` names them `native_endpoints`, the gateway paths a request for it goes on untranslated such as `["/v1/chat/completions"]`, and `pricing`, USD a token as decimal strings: `prompt`, `completion`, `input_cache_read`, `input_cache_write`; each left out when not known, never empty or 0), `models` (every model magpie offers the agent, the same way) and `agent` (`id`, `config`). A plugin without `connect` writes only the model. It is called again when magpie’s models change, so a list it writes stays current.

### What magpie does with it

- **Writing..** Each key is set in place, the user’s comments and other keys kept. Before the first write, what each key held is kept aside, typed (a number stays a number).
- **The way back..** Picking the agent’s own model again, or switching it off, puts every key back as it was and takes out the keys that weren’t there. The file is never written over whole.
- **Connected or not..** The row says connected while the key that holds magpie’s key still holds it. A key changed by hand afterwards is said in the row, as for magpie’s own agents.
- **How it runs..** As middleware does: in moejs, in magpie’s own process, with imports inside the plugin only, no Node APIs and `console.log` into magpie’s log. Loading and `connect` each have a second. A plugin whose module doesn’t load, or whose `connect` throws, says why in its row on the Plugins page and writes nothing.
- **The Library..** With `library`, the agent is one of the Library’s agents: its instructions go between magpie’s marker lines in the file, its MCP servers into the file beside the user’s own (whose other fields are kept), and its skills linked or copied into the folder. Taking one off takes away only what magpie wrote there, and what a file held before is kept in magpie’s backups. An `mcpFormat` that isn’t one of the list, or an `mcp` without one, keeps the plugin from loading.
- **Declaring it..** `"magpie": { "agent": "./agent.js" }` in `package.json`, or a single file named `*.agent.js` (or `.mjs`). A package can be a provider, middleware and an agent at once. In the plugin market an agent’s entry has `"kind": "agent"` and is listed under Agents; a community one is named `@magpie-community/agent-<name>`.
- **An agent that needs a runtime..** The agent file stays a moejs module, with no timers and nothing imported from outside the plugin. When the agent needs more (a timer, a file watched, a value carried over into the app’s own config), the package can also have a Bun module as its `main`, run as a provider plugin’s is. It is still an agent plugin: a package that declares `magpie.agent` is listed under Agents, on GitHub too, with a `main` or without, and its row in Installed wears the Agent chip, and the Provider chip only when its module serves a provider.

## Pages in the window

A plugin can add a page of its own to magpie’s window. Once it is on, the page has a tab in the sidebar’s Plugins group, after magpie’s own pages. The page is plain HTML, CSS and JavaScript in the plugin’s folder, and needs no Bun and no build step. The example below shows today’s usage.

```
{
  "name": "magpie-usage-glance",
  "version": "0.1.0",
  "magpie": {
    "page": {
      "title": "Usage glance", "file": "page/index.html", "icon": "page/icon.svg",
      "titles": { "zh": "用量速览", "ja": "使用量の概要" }
    },
    "permissions": ["usage:summary"]
  }
}
```

```
<!doctype html>
<link rel="stylesheet" href="style.css">
<script src="_magpie/bridge.js"></script>   <!-- served beside every page -->
<script src="app.js" defer></script>
<p id="calls">…</p>
```

```
await magpie.ready                                  // the window's theme, painted
const s = await magpie.read("usage:summary", { period: "today" })
document.getElementById("calls").textContent = `${s.calls} calls`
const opts = await magpie.options.get()            // this plugin's own options
await magpie.options.set({ ...opts, hideCost: true })
```

The Plugins page shows the page, and what it may read, on the plugin’s row before it is turned on. `page.file` and `page.icon` are paths inside the plugin. The page’s files are what sits in `file`’s folder; a path out of it, or a link that leads out, isn’t served. A package can be a page and a provider, middleware or an agent too. A plugin that is only a page doesn’t start the plugin host. `page.titles` (and a panel’s `titles`) names the tab in other languages, by language code (`zh`, `zh-TW`, `ja`, `de`); `title` is used for any other.

What the page leaves unstyled already looks like magpie: the bridge adds a stylesheet for the font, colours, headings, buttons, fields and tables, with no weight (`:where()`), so any rule of the page’s own wins. Use the `--magpie-*` variables to match the window in your own styles.

### What the page can ask

| Field / call | What it gives |
| --- | --- |
| `magpie.ready` | A promise of the window’s theme. It resolves once the window has answered. Until then the page has said nothing to magpie, and a page that doesn’t say it in 10 seconds is shown as not answering. |
| `magpie.theme, magpie.onTheme(fn)` | `{ dark, lang, tokens }`. The bridge also sets `data-theme`, `lang`, `color-scheme` and `--magpie-bg`, `--magpie-fg`, `--magpie-accent` and so on on `<html>`, and again on each change. |
| `magpie.options.get(), .set(o)` | The plugin’s own options in plugins.json, never another plugin’s. `set` takes an object and answers with the options saved. It can be called at most once a second. |
| `magpie.read(name, params)` | A read that `magpie.permissions` declares. Anything else is refused, by the window and again by magpie. `usage:summary` (`period`: `today`, `7d` or `30d`) gives calls, errors, tokens and cost, with the top 20 models. `providers:list` gives each provider’s id and name. No read gives keys, accounts, sign-ins or request bodies. |

### What the page can’t do

- The page runs in a frame sandboxed to scripts alone (`sandbox="allow-scripts"`, and the same in its `Content-Security-Policy`), in an origin of its own. It can’t reach the window, magpie’s cookie or the window’s storage.
- Its policy allows its own files and nothing else: `connect-src 'none'`, so no `fetch`, WebSocket or beacon, and no forms or frames. Scripts must be files (`<script src>`), not inline. Inline styles and `data:` pictures are fine.
- In a sandboxed frame, WebKit (Safari on iPhone and Mac, the Mac and Linux window) may match `'self'`, or a source without a scheme, to nothing: a `fetch` under `connect-src 'self'` is refused. A page your plugin’s service serves, which runs sandboxed too, should name whole sources (`https://…`) in its own policy. magpie adds the service’s address next to each `'self'` in a `Content-Security-Policy` header the service sends through `magpie web`, but not in a `<meta>` tag.
- magpie’s API refuses any request a frame like this one can make (`Origin: null`, a frame or another site’s request), so it is closed to the page even without the policy. Its files are served at `/_magpie/plugin/<token>/`, a token that changes each time magpie starts.
- A page can still send itself to another site, which then holds its frame. That is why reads give nothing secret. Treat what a page can read as public.
- An error the page doesn’t catch shows This page stopped working in its place, with Try again. Its own scripts’ errors reach it as “Script error.”, so look in the window’s console for the rest.

### Panels in magpie’s own pages

A plugin can also put panels into the pages magpie draws itself. Each one is a small page of its own in the plugin’s folder, with the same bridge, reads, options and sandbox as a page. It sits in a card under a heading with its title, as tall as it draws.

```
{
  "name": "magpie-provider-notes",
  "version": "0.1.0",
  "magpie": {
    "panels": [
      { "slot": "provider", "file": "ui/notes.html", "title": "Notes" },
      { "slot": "usage", "file": "ui/spend.html", "title": "Top models today" }
    ],
    "permissions": ["usage:summary"]
  }
}
```

| `slot` | Where the panel goes | `magpie.context` |
| --- | --- | --- |
| `agents` | The end of the Agents page | `{}` |
| `usage` | The end of Usage’s Overview | `{}` |
| `settings` | A Plugins tab in Settings, there only while a plugin has a panel in it | `{}` |
| `provider` | Each saved provider’s editor | `{ provider: { id, name } }` |

A plugin has at most 8 panels. A panel’s height follows its `<html>` (up to 2400px), so let the page size itself and don’t give `html` or `body` a fixed height. A panel that throws, or doesn’t answer in 10 seconds, shows {name} stopped working with Try again in its own place; the page around it and the panels beside it go on.

### Taking a built-in page’s place

A page can take the place of one of magpie’s own: add `"replaces"` to `magpie.page`, one of `sessions`, `library`, `routing` or `usage`. Its tab then stands where the built-in’s was, and links to that page open the plugin’s. When two plugins ask for the same page, the first in the Plugins list takes it and the other is a page of its own. Turn the plugin off and the built-in page is back as it was.

```
"page": { "title": "My library", "file": "page/index.html", "replaces": "library" }
```

### Items in magpie’s menus

A plugin with a page can add items to the menus of magpie’s rows: a provider’s (right-click it) and an agent’s (its handle, or right-click). They come after magpie’s own, named in the window’s language like a page’s title. Picking one opens the plugin’s page and tells it which item, and the row’s id and name, nothing else of it. The page handles it with `magpie.onAction`; an item picked before the page gave its handler waits for it.

```
"page": { "title": "Balance", "file": "page/index.html" },
"actions": [
  { "id": "check", "menu": "provider", "title": "Check balance", "titles": { "zh": "查余额" } }
]
```

```
magpie.onAction(({ id, provider }) => {
  // id: "check"; provider: { id, name }
});
```

`menu` is `provider` or `agent`. An `id` is lower-case letters, digits and dashes, up to 40. A plugin has at most 8 items, and an item with no `title` takes its page’s. A plugin without a page adds no items. The Plugins page says which menus a plugin adds to.

## pi packages

magpie also runs [pi](https://github.com/earendil-works/pi)’s packages. A pi extension that registers a provider with `pi.registerProvider` works in magpie as it does in pi, with nothing to change, and is added like any plugin (`magpie plugin add pi-antigravity`).

- **What makes a package pi’s..** Its `package.json` has a `pi` manifest (`"pi": { "extensions": [...] }`), the `pi-package` keyword, or `@earendil-works/pi-coding-agent` (or the older `@mariozechner/pi-coding-agent`) among its `dependencies` or `peerDependencies`. A single file counts when it imports pi.
- **Loading..** magpie installs pi beside the package and loads it with pi’s own loader, in the same plugin host. The providers it registers become magpie providers, with the models pi lists for them (an account’s own list when pi can fetch one). Its commands, tools, renderers and event handlers are left alone.
- **Signing in..** An OAuth login runs as pi runs it: its questions (`onPrompt`) are asked in magpie’s sign-in, its page (`onAuth`) opens in the browser, and `refreshToken` renews it. The dialogs a package shows with `ctx.ui` (`select`, `confirm`, `input`, `editor`) and the terminal components it gives `ctx.ui.custom` are asked as magpie’s questions too. A provider that takes an API key gets a key field. Each sign-in is an account, so a pi provider can have several.
- **pi’s files..** pi’s settings, its `auth.json` (each provider’s first account, as pi keeps it) and the files a package writes are in `pi/` under magpie’s config directory, not the user’s `~/.pi`, unless `PI_CODING_AGENT_DIR` is set. magpie keeps the accounts in `plugin-auth.json`, like any plugin’s.
- **Requests..** A pi provider’s models take Anthropic Messages: the gateway translates what the agent sends, magpie streams it through pi, and the answer keeps its thinking, signatures and tool calls. A vendor error is passed on with its status, so failover works as with any plugin.
- **Ids..** A pi provider’s id follows the same rule as any plugin’s; see Provider ids.

## The host protocol

Writing a plugin doesn’t need this section. It is for people working on magpie itself, or debugging the host. magpie writes `{id, method, params}` to the host’s stdin, one per line. The host answers `{id, result}` or `{id, error: {message}}`.

| Method | Does |
| --- | --- |
| `init` | Loads the plugins; runs their `config` hooks. Every other call waits for it. |
| `providers` | Each provider, its methods, accounts and each account’s models. |
| `prompt`, `validate` | A method’s next question; an answer checked. |
| `authorize`, `callback`, `apiKey` | Signing in. |
| `load` | The loader’s options for an account. |
| `fetch` | One request. It streams `{id, event: "head", status, headers}`, then `{id, event: "chunk", data}` (base64), then `{id, result: null}`. `{method: "abort", params: {id}}` cancels it. |
| `usage`, `check` | An account’s usage; an account tried as a request would. |
| `import`, `take`, `signOut`, `reload` | Accounts moved in and out, forgotten, their loaders run again. |

The host also sends events of its own: `log`, `toast`, `auth` (a sign-in saved or refreshed) and `signIn` (an account’s sign-in state, as above). The source is [`internal/plugin/host.js`](https://github.com/yetone/magpie/blob/main/internal/plugin/host.js).

## FAQ

### Does my OpenCode plugin work in magpie unchanged?

Yes, as long as it signs in and makes requests through `auth`, `config`, `provider` and `chat.headers`. What magpie adds (`auth.usage`, `auth.refresh`, `magpie.icon`, `maxConcurrency`, `free`, `rate`, `X-Magpie-Sign-In`) is ignored by OpenCode, so one package serves both.

### Does my pi package work in magpie?

Yes, if it signs in and serves models through `pi.registerProvider`. magpie uses only the providers it registers; see pi packages. Give it the `pi-package` keyword so the search finds it.

### Why is my provider called `…-plugin`?

Its id is one magpie already has. See Provider ids.

### Some of my helper functions run as plugins.

Every function the entry module exports is called as a plugin. Export only the plugin function, or `export default { id, server }`.

### Can I use npm dependencies?

Yes. They are installed with the plugin, but their install scripts aren’t run. Bun’s `fetch`, `crypto`, `fs` and `$` cover most needs.

### Can my plugin run the vendor’s CLI?

Yes, with Bun’s `$` or `child_process`. Several community plugins sign in through the vendor’s own CLI. Expect it to be missing on some machines, and say how to install it in the error.

### What does a plugin see of the user’s work?

Everything in the requests it makes: the conversation, the tools and their results. Send it only where the user asked it to go, and don’t log it.

### How do I make magpie see my edits?

A `magpie` command in a terminal loads the folder as it is now. In the app, turn the plugin off and on in Plugins.

Questions, or a plugin to share? Ask on [Discord](https://discord.gg/vGSnD3ZKQF), or open an issue in [magpie-community/plugins](https://github.com/magpie-community/plugins).

---

Source: https://usemagpie.ai/docs/privacy

# Privacy

Your prompts, replies, keys and accounts go only to the providers you use; magpie has no server of its own in that path. This page lists everything magpie sends by itself, beside those requests, and every switch that stops it. It is written from the code, which is linked in each section.

| What | Where to | Off by default? | How to stop it |
| --- | --- | --- | --- |
| The daily count | PostHog (`us.i.posthog.com`) | On in releases; never in builds from source | Settings → Privacy, `DO_NOT_TRACK=1` |
| Update checks, release notes, the partner list, icons | `usemagpie.ai` | On | `noAutoUpdate` for update checks; the rest are needed by the app |
| Model catalog and exchange rate | `models.dev`, `open.er-api.com` | On | Not switchable; nothing of yours is sent |
| OTLP export | A collector you name | Off | Leave it off |

## The daily count

Once a day (UTC), a running release of magpie (the app, or `magpie serve`) sends one batch to PostHog, so we know how many people use it and which agents, providers and models to look after first. It is sent at start and then looked at every hour; a day already sent is skipped. Builds from source never send it.

The batch has one `magpie active` event with:

- a random id made up on your computer (32 hex characters, tied to nothing about you or the machine), sent as `distinct_id`;
- magpie’s version, `kind` (`app` or `serve`), your system (`$os`) and architecture;
- how many agents, providers and models it is used with, and how many routing groups (left out when you turn off sharing what you use).

Unless you turn that part off, one `magpie uses` event follows for each agent, provider and model, by magpie’s own ids only (at most 50 of each):

- **agents.** connected to magpie: `claude`, `codex`. A WSL distro or an omp profile name is cut off (`omp`).
- **providers.** that are on: a preset’s id (`deepseek`), a subscription’s (`codex`, `copilot`), a known community plugin’s (`plugin:kiro`). A provider you added yourself is only `custom`; any other plugin only `plugin`.
- **models.** the connected agents are set to, as provider id and vendor model id (`deepseek/deepseek-v4`). On a key’s provider, a model id that [models.dev](https://models.dev) doesn’t list (a local model, a fine-tune) is only `<provider>/other`; a model on your own provider is `custom`; a routing group is `group`.

With them go `magpie partner` events: for each partner listed first in the add sheet, by its id, how many times on a day that has ended the sheet showed it, its row was opened, its key page was opened, and a provider was added from it (`what`: `shown`, `opened`, `keys`, `added`; at most 20 a day each, 5 adds). Counts only, never a provider of your own.

Every event carries `$process_person_profile: false`, so PostHog keeps no person profile for the id. No names, base URLs, accounts, keys, prompts, replies or usage are sent. A whole batch looks like this:

```
{
  "api_key": "phc_nyDyYyrUTRGvNq5U7FBesCyM2j4GdKeqGp8ko7DBerTC",
  "batch": [
    {
      "event": "magpie active",
      "distinct_id": "3f9c…(32 hex)",
      "timestamp": "2026-10-13T08:00:00Z",
      "properties": {
        "version": "0.1.1190", "kind": "app", "$os": "Mac OS X", "arch": "arm64",
        "agents": 2, "providers": 3, "models": 2, "groups": 1,
        "$process_person_profile": false, "distinct_id": "3f9c…"
      }
    },
    { "event": "magpie uses", "distinct_id": "3f9c…", "timestamp": "2026-10-13T08:00:00Z",
      "properties": { "kind": "agent", "id": "claude", "$process_person_profile": false, "distinct_id": "3f9c…" } },
    { "event": "magpie uses", "properties": { "kind": "provider", "id": "custom", … } },
    { "event": "magpie uses", "properties": { "kind": "model", "id": "deepseek/deepseek-v4", … } },
    { "event": "magpie partner", "timestamp": "2026-10-12T12:00:00Z",
      "properties": { "id": "<partner id>", "what": "shown", "count": 3, "day": "2026-10-12", … } }
  ]
}
```

The `api_key` is the project’s PostHog key; it can only send events, not read them. The code is [internal/stats](https://github.com/yetone/magpie/blob/main/internal/stats/stats.go) and [partner_events.go](https://github.com/yetone/magpie/blob/main/internal/provider/partner_events.go).

## Turning it off

Each of these switches stops part or all of it:

- Settings → Privacy → Count me as a user off, or `"noStats": true` in `settings.json` stops the whole daily count.
- `DO_NOT_TRACK=1` or `MAGPIE_NO_STATS=1` in magpie’s environment (any value but empty, `0` or `false`) stops the whole daily count, whatever the settings say.
- Settings → Privacy → Share the agents, providers and models I use off, or `"noUsageStats": true` leaves out the `magpie uses` and `magpie partner` events and the counts in `magpie active`; the id, version and system are still sent. Partner counts stop being kept too.
- Settings → About → Automatic updates off, or `"noAutoUpdate": true` stops magpie asking `usemagpie.ai` for a newer version by itself (it asks every 6 hours otherwise). This is not part of the count.

A change in Settings takes effect at the next hourly look; no restart is needed. `settings.json` sits in magpie’s folder (see below):

```
{
  "noStats": true,
  "noUsageStats": true,
  "noAutoUpdate": true
}
```

`MAGPIE_STATS_HOST` sends the count to another host instead (it is for testing, and also makes a build from source send).

## Files on your computer

| File | What it is |
| --- | --- |
| `install-id` | The random id, made the first time the count is sent |
| `stats-sent` | The last day (UTC) the count went, so a day is sent once |
| `partner-counts.json` (in the cache folder) | Partner counts not yet sent, at most 14 days |

`install-id` and `stats-sent` are in magpie’s folder: `~/.config/magpie` on macOS and Linux, `%USERPROFILE%\.config\magpie` on Windows, `$XDG_CONFIG_HOME/magpie` when that is set, and the data folder of a portable magpie. `partner-counts.json` is in `~/.cache/magpie` (`$XDG_CACHE_HOME/magpie`, or `cache` in a portable magpie’s data folder). You can delete any of them: a deleted `install-id` is replaced by a new random one at the next send, so you are counted as a new user; with the count off, none of them is written again.

The request archive (the Request archive switch on the Usage page, above the list of requests) is **off by default**. Turned on while sync has no S3 bucket, it keeps each gateway call’s headers and bodies, secrets masked as for the S3 archive, in `request-archive` in magpie’s folder, one file per call, readable by your user only. It grows to 1 GiB (`requestArchiveLocalMB` in settings.json) and the oldest calls are removed past that. The switch is this computer’s own: sync never turns it on at another computer. With an S3 bucket the calls go to the bucket instead, and nothing is written here. Delete the folder whenever you like.

The app writes a log of what it did, `app.log`, in `~/Library/Logs/magpie` on macOS, `%LOCALAPPDATA%\magpie\logs` on Windows and `~/.local/state/magpie` on Linux (see [Where is magpie’s log?](https://usemagpie.ai/docs/start#log)), readable by your user only. It names what magpie did and the errors it met, never keys, prompts or replies, and stays on your computer unless you send it. It is kept to 5 MiB, with one older file, `app.old.log`. Delete them whenever you like.

## What usemagpie.ai sees

magpie asks its own site for a few things, whatever the privacy settings say, as any app asks its update server. None of these requests carries the install id or an account.

- `/api/latest`: the update feed, every 6 hours unless `noAutoUpdate` is on, with `?lang=` for the notes in your language, and `?channel=stable` when Settings → About → Update channel is Stable. Neither says who you are. `/api/notes` gives What’s new after an update.
- `/files/<version>/<file>`: the release files an update and the installer download, served from Cloudflare R2. A file the site doesn’t hold is sent on to github.com. Nothing is counted.
- `/api/partners`: the add sheet’s partner list, every 6 hours. One fetch in ten is counted as a `magpie partners fetch` event, with the country Cloudflare gives, while a partner is listed.
- `/go/<partner>/site` and `/go/<partner>/keys`: a partner’s website and key-page links, opened in your browser, are counted (the partner, which link, a region, a country) as `magpie partner go` before you are sent on.
- `/api/icon?url=…`: icons named by a plugin, an import link or the library are fetched through it, so their hosts see Cloudflare’s address, not yours. The worker passes the picture on and counts and keeps nothing.

The site’s own pages (these docs, the home page) carry Cloudflare Web Analytics and PostHog Web Analytics (`us.i.posthog.com`), without cookies. PostHog keeps a random visitor id in your browser’s local storage for this site, so a return visit counts as the same visitor. It gets each page’s address, the page that sent you, what you click on the page (not what you type), how fast the page and its requests loaded, errors the page hit, your browser, system and screen size, the country and city your address is in, and a recording of the visit (what the page showed, mouse moves, clicks and scrolls, its console messages) with every input box masked; nothing at all when your browser sends Do Not Track or Global Privacy Control. PostHog’s requests go through this site, under `usemagpie.ai/r/`, which passes them and your address on to PostHog and keeps the site’s cookies. Following a `/download` link, or fetching `install.sh`, sends PostHog a count of its own: which file, your country, and whether a browser or a command asked; no id and no address. The app doesn’t load either. The code is [site/worker.js](https://github.com/yetone/magpie/blob/main/site/worker.js).

## Public lists magpie fetches

To price and name models magpie fetches the [models.dev](https://models.dev) catalog (`models.dev/api.json`), and for prices in your currency the USD exchange rate from `open.er-api.com` (kept 12 hours). Plugins and their updates come from the npm registry, and the library’s items from GitHub. These are plain downloads of public data: nothing about you, your providers or your usage is sent, though, as with any request, those hosts see your IP address (or your proxy’s). magpie also asks each of your providers for your allowance and model list, with your own key or sign-in; Settings → Allowances → Allowance reads → When I ask limits those to when you ask.

## OTLP export

magpie can export each gateway request to an OpenTelemetry collector of yours (Langfuse, for example). It is **off by default**, and goes only to the endpoint you set, never to us. When on, it sends per-request spans: agent, provider, model, the name you gave the gateway key it came with (never the key itself), token counts, status, timing and estimated cost. Optional switches add metrics, local agent conversations, and the request and reply bodies (secrets masked). Turn it on in Settings → Observability, or for `magpie serve` with `MAGPIE_OTEL_ENABLED`, `MAGPIE_OTEL_ENDPOINT`, `MAGPIE_OTEL_HEADERS`, `MAGPIE_OTEL_METRICS`, `MAGPIE_OTEL_SESSIONS`, `MAGPIE_OTEL_BODIES` and `MAGPIE_OTEL_BODIES_WHOLE`. An endpoint alone doesn’t turn it on. For Langfuse, pick Langfuse there and give its host and your project’s two keys; magpie makes the endpoint and sign-in from them. Each export’s resource is `service.name=magpie`, plus only what you set yourself in `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` (a server name, for example); nothing about your machine is looked up. The [reference](https://github.com/yetone/magpie/blob/main/docs/reference.md#otlp-export) has the details.

## Masking what goes to providers

The sections above are what magpie sends by itself. What your agents send goes to the providers you chose, and **privacy masking** keeps the secrets in it on this computer. It is **off by default**; turn it on in Settings → Privacy.

- Before a request leaves this computer, API keys, private keys, tokens, emails, and card and ID numbers whose checksum adds up become placeholders such as `{{API_KEY_k3v9x2mq}}`. Find with a local model adds the names, addresses and passwords no rule can find, with a model that runs on this computer (a 1.6 GB download, on the CPU).
- Every placeholder in the reply, streamed text and tool-call arguments included, turns back into its value, so your agent and your files keep the real values.
- A value gets the same placeholder every time, so the conversation and the prompt cache stay valid.
- Values are held in memory only; the record on disk keeps each value’s kind, length and first characters. If masking is on and can’t run, the request gets a 503 and nothing is sent.
- The model sees the placeholder, not the value. A value a task needs as it is (a team address, a test key) goes under Never mask.

How to turn it on, what each switch masks, an example and how to check it: [Privacy masking](https://usemagpie.ai/docs/masking).

## Why the count is on

magpie works with dozens of agents and providers, and is maintained by a small team. The daily count is how we know which of them people actually use, so they are kept working first. It is on in releases because counts from those who turn it on would be too few to tell that. In exchange it is kept small: a random id, built-in ids, numbers; one switch or `DO_NOT_TRACK=1` turns it off, builds from source never send it, and this page lists everything that goes.
