# 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 rule add opus-anywhere use=deepseek/deepseek-v4-flash when="effort is off" when="not subagent"  # reasoning off, not a subagent
magpie group rule add opus-anywhere use=deepseek/deepseek-v4-flash when="system matches ^你是对话标题命名"  # a harness's title call, told by its system prompt
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 magpie’s own files on that disk (an external SSD, say), click Move… beside Data folder in the same place and pick a folder there. magpie restarts, moves its files and cache into a folder named `magpie` inside it, and leaves a link where they were, so nothing else changes. Keep the disk connected: without it magpie won’t open until it is back. Move back brings them home. `magpie data move <folder>` does the same from a terminal.

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, models and plugins I use leaves out the agents, providers and models, the partner counts and which of Discover’s plugins are installed (for its counts of who uses and likes each); 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).

An error from the gateway? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting). Stuck, or have a setup worth sharing? Ask on [Discord](https://discord.gg/vGSnD3ZKQF). Chatting in Cherry Studio? See [Every model in Cherry Studio](https://usemagpie.ai/docs/cherry-studio). 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/…`. For a ChatGPT plan in full, tiers, effort and limits included, see [ChatGPT in Claude Code](https://usemagpie.ai/docs/claude-code-chatgpt).

## 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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

## 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). On Claude Desktop? See [Claude Desktop on any model](https://usemagpie.ai/docs/claude-desktop). 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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

## 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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

## 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. The whole setup, tiers and effort included, is in [ChatGPT in Claude Code](https://usemagpie.ai/docs/claude-code-chatgpt).

### 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/claude-code-chatgpt

# Use your ChatGPT Plus or Pro subscription in Claude Code

Claude Code can run on the GPT models of your ChatGPT Plus or Pro plan. Sign in to ChatGPT in magpie, pick a `codex/…` model for Claude Code, and keep working as before. No OpenAI API key.

Claude Code speaks Anthropic’s Messages API. magpie runs a gateway on your computer, at `127.0.0.1:3425`, that translates each of Claude Code’s requests for the GPT model and each reply back, streaming and tool calls included. magpie writes the gateway’s address and key into Claude Code’s `settings.json`, and your ChatGPT sign-in stays in magpie.

## Sign in to ChatGPT

1. **Open Add provider.** In magpie’s Providers tab, press ＋ Add provider.
2. **Click the ChatGPT tile.** magpie opens OpenAI’s own sign-in page in your browser. The account shows up as soon as you finish.

Or from a terminal:

```
magpie accounts add codex      # sign in to a ChatGPT account
```

The account’s models are `codex/…`.

## Pick a GPT model for Claude Code

In the Agents tab, click the model on Claude Code’s row and choose a `codex/…` model. From a terminal:

```
magpie models                  # every model, as provider/model
magpie claude codex/gpt-5.5
```

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

> **Only some sessions on GPT?** Leave Claude Code unconnected in magpie and run `claude-magpie` when you want it on a GPT model. It starts the same `claude` with magpie’s settings for that session only, and `settings.json` is not rewritten.

## 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. With a GPT model as the main model:

| Tier | Variable in `env` | By default |
| --- | --- | --- |
| opus | `ANTHROPIC_DEFAULT_OPUS_MODEL` | The GPT model you picked |
| sonnet | `ANTHROPIC_DEFAULT_SONNET_MODEL` | The GPT model you picked |
| haiku | `ANTHROPIC_DEFAULT_HAIKU_MODEL`, `ANTHROPIC_SMALL_FAST_MODEL` | The GPT model you picked |
| fable | `ANTHROPIC_DEFAULT_FABLE_MODEL` | Left unset |

To give a tier a model of its own, say a smaller one for haiku, set it on Claude Code’s row in magpie, or from a terminal:

```
magpie claude haiku codex/…    # one tier on its own model
magpie claude haiku ""         # back to the main model
```

## Reasoning effort

The effort Claude Code asks for goes to the GPT model as its reasoning effort, on requests where Claude Code has thinking on. magpie also tells Claude Code which effort levels each model has.

To hold one effort whatever Claude Code asks, set effort on Claude Code’s row. opus effort, sonnet effort, haiku effort, fable effort and subagent effort set it per tier. Each starts at the effort Claude Code asks for. An open Claude Code session keeps the effort it started with, so restart it to use a new one.

## Limits and usage

Requests are served on your ChatGPT account, so they count toward your plan’s usage limits, as Codex’s own requests do.

- **See what’s used..** Turn on status line on Claude Code’s row: it shows the 5h and 7d use of the accounts magpie serves, under Claude Code’s prompt. `magpie accounts` lists each account and how much of its allowance is used. The Usage tab has the history.
- **When an account runs out..** magpie sets it aside until the reset OpenAI’s refusal names, else until its full window renews, else for 5 hours, and sends requests to your next account or the provider’s Fallback. The account comes back on its own once its window renews.

## Several accounts and failover

- **Add another account..** Click the ChatGPT tile again, or run `magpie accounts add codex` again. Each account is listed under the provider.
- **Spread requests over them..** Open the provider’s row and tick every account to use. Smart routing, the default, sends requests to the account with quota to spare whose allowance renews soonest.
- **Fall back to another model..** The provider’s Fallback lists models to use when every account is out, rate limited or down, a model from another subscription or an API key included.

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

## Switch back

Pick one of Claude Code’s own models on its row, or run:

```
magpie claude default
```

That takes magpie’s wiring out of Claude Code and puts back what it had. Disconnect on Claude Code’s row does the same.

> **Your claude.ai sign-in.** On a magpie model, Claude Code’s sign-in setting is magpie’s key by default: claude.ai is signed out for it, so `/usage` plan limits, connectors, voice and `/teleport` are off. Set it to claude.ai to keep them.

## The other way round: Claude in Codex

A Claude Pro or Max subscription works in Codex the same way. Sign in to Claude in magpie and pick a `claude/…` model for Codex. Requests on a Claude subscription run through the Claude Code installed on your computer, so keep it installed.

```
magpie accounts add claude
magpie codex claude/claude-opus-5-5
```

See [Models in Codex](https://usemagpie.ai/docs/codex-models) and [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions).

## 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 requests for the GPT model and the replies back, tool calls included.

### Do I need an OpenAI API key?

No. magpie signs in on OpenAI’s own page, and Claude Code gets the gateway’s key. Your sign-in stays in magpie.

### Does it use my ChatGPT plan’s limits?

Yes. Requests are served on your ChatGPT account and count toward its usage limits. magpie’s status line shows each account’s 5h and 7d use under Claude Code’s prompt.

### Which model do Claude Code’s Haiku requests use?

The GPT model you picked, unless you give the haiku tier a model of its own with `magpie claude haiku <model>`.

### How do I go back to Claude’s own models?

Run `magpie claude default`, or pick one of Claude Code’s own models on its row in magpie.

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

No. The gateway runs on your computer. Requests go from it to OpenAI; magpie has no server of its own in that path.

Using an API key instead? See [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or 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. With OpenCode 2 installed, magpie writes OpenCode 2’s own keys instead: the provider under `providers.magpie` and the small model as `agents.title.model`. 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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

## 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), [OpenClaw on any model](https://usemagpie.ai/docs/openclaw). 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/openrouter

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

OpenRouter sells many vendors’ models behind one key and serves them on OpenAI Chat Completions and Anthropic Messages. Add the key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use any OpenRouter model through magpie’s gateway at `127.0.0.1:3425`, each agent on a model of its own.

## Add OpenRouter

1. **Get a key.** Make one on [openrouter.ai/keys](https://openrouter.ai/keys).
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick OpenRouter, paste the key and save. magpie asks OpenRouter which models it serves.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose an OpenRouter model such as `anthropic/claude-opus-5.5`.

```
magpie provider add openrouter sk-…
magpie provider test openrouter
```

Model ids in magpie are `provider/model`, so OpenRouter’s read `openrouter/anthropic/claude-opus-5.5`: the provider, then OpenRouter’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

OpenRouter documents two optional headers that credit an app in its rankings, `HTTP-Referer` and `X-OpenRouter-Title`. magpie doesn’t send them. The provider editor’s Headers field offers them if you want your requests credited.

## Endpoints

| API | Base URL | Used for |
| --- | --- | --- |
| Chat Completions | `https://openrouter.ai/api/v1` | the model list, requests to non-Claude models, image models |
| Anthropic Messages | `https://openrouter.ai/api` | Claude Code’s requests, and Claude models from any agent |
| Decisions | `https://openrouter.ai/api/v1` | decision models for [intent routing](https://usemagpie.ai/docs/intent) |

magpie doesn’t use OpenRouter’s Responses API. An agent that speaks Responses, such as Codex, is translated to one of the two above.

## Model list

- **Where it comes from..** magpie fetches the list from `https://openrouter.ai/api/v1/models`, which gives each model’s context length. Names, reasoning levels and prices come from the `openrouter` catalog on models.dev.
- **Which models agents see..** OpenRouter lists hundreds. Unless you pick some, magpie shows agents the first 24 OpenRouter lists, newest first. Pick the rest in the provider’s model list, or turn on Best in family to keep only the newest of each family.
- **New models..** `auto-include` rules expose matching models now and each one a later fetch lists for the first time, and `refresh-every` has magpie fetch the list again by itself.
- **Image models..** OpenRouter’s `/models` lists text models only, so magpie reads image models such as FLUX, Seedream, Riverflow, Recraft and GPT Image from `/api/v1/images/models`. Choose one in Settings → Models → Images.
- **Decision models..** OpenRouter’s decision models (`liquid/d1`, `cloudflare/clef`, `~typesafe/jev-latest`…) are listed too, so a routing group can classify turns with the same key.

```
magpie provider models openrouter +anthropic/claude-opus-5.5   # expose one more
magpie provider models openrouter best                          # newest of each family
magpie provider auto-include openrouter '*:free'               # every free model, now and later
magpie provider refresh-every openrouter 1d
```

## 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 openrouter/anthropic/claude-opus-5.5
magpie codex openrouter/anthropic/claude-opus-5.5
magpie gemini model openrouter/google/gemini-3-pro
magpie opencode openrouter/anthropic/claude-opus-5.5
```

- **Claude Code.** speaks Anthropic Messages, and so does OpenRouter at `https://openrouter.ai/api`, so its requests are passed on as they are. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses. magpie translates each request and the reply, streaming and tool calls included: a Claude model goes to OpenRouter’s Anthropic endpoint, every other model to Chat Completions. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Gemini’s API. magpie translates it the same way as Codex’s requests. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** speaks Chat Completions, so its requests go to OpenRouter as they are, except for Claude models, which magpie sends to the Anthropic endpoint for their prompt cache (see below). [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

If OpenRouter says a model isn’t served on the endpoint magpie chose, magpie builds the request again for the other one and remembers that for the model.

## Reasoning

- **Models that always reason..** Some OpenRouter models refuse to have reasoning turned off (“reasoning is mandatory for this endpoint and cannot be disabled”). When an agent asks for it off, magpie asks again with the level left to the model, on Chat Completions and on Messages alike.
- **Effort mid-conversation..** Claude Code sends a turn’s effort inside the conversation. OpenRouter’s Anthropic endpoint refuses that on some models, such as DeepSeek and GLM. magpie asks again at once without it, and doesn’t send it to OpenRouter again until magpie restarts.
- **Earlier thinking..** OpenRouter’s Anthropic endpoint turns away a thinking block without a signature, so magpie always sends one. On Chat Completions, earlier reasoning that an agent sends back in OpenRouter’s `reasoning` or `reasoning_details` fields is read as the model’s thinking.

## Cache, cost and credits

- **Claude’s prompt cache..** On Chat Completions, a relay that serves both APIs drops `cache_control`, and every turn is billed uncached. So magpie asks Claude models on OpenRouter’s Messages endpoint, from any agent, with the cache breakpoints the translation adds.
- **Cache tokens..** magpie reads cache reads and OpenRouter’s `cache_write_tokens` from each reply, so the Usage tab counts cache hits and writes apart from the rest.
- **Cost..** The Usage tab prices each call with OpenRouter’s prices from models.dev, or the model maker’s list price when the catalog has none. A model listed at $0, such as one ending in `:free`, shows free beside it in magpie’s pickers.
- **Which provider answered..** OpenRouter names the provider that served each reply. magpie keeps it, and the call’s details in the Usage tab show it as Upstream provider.
- **Credits..** The OpenRouter row shows what is left on the account, in dollars: total credits less total usage, read from `/api/v1/credits`. It’s the whole account’s figure, so each key of one account shows the same.

## Several keys and free models

One OpenRouter provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over. The provider’s routing can also rotate, weight or drain them instead. Adding the preset again makes a second OpenRouter provider; to spread requests over several keys, add them all to the one provider.

- **Spend caps..** `spend-cap` stops a key at a dollar amount a day, a month or in all, as the Usage tab prices its calls; routing then goes on to the other keys and the fallbacks.
- **Fallbacks..** `fallback` names where requests go when OpenRouter is out of quota or down: another provider’s model or a routing group.
- **Free models..** OpenRouter’s free models take 20 requests a minute. `rpm` holds each key to a rate: one request more waits for room, up to 2 minutes, then gets a 429 with a `Retry-After`.
- **Free-model 429s..** When a free model is refused by the shared pool of the provider serving it, magpie rests that model only and keeps the other free models in use. Any other 429 on a free model is OpenRouter’s account-wide free limit, and the key rests.
- **A pool of free models..** A routing group can take every free model OpenRouter lists with the pattern `openrouter/*:free`, today’s and those it lists later.

```
magpie provider rpm openrouter 20
magpie provider spend-cap openrouter <key> 20 month
magpie provider fallback openrouter deepseek/deepseek-v4-pro
magpie group add my-free-pool models='openrouter/*:free' routing=order
magpie group set opus-anywhere stays=session models+=openrouter/anthropic/claude-opus-5.5
```

## Troubleshooting

- **The model list has only `anthropic/` ids, or fails to load..** A provider given only `https://openrouter.ai/api` gets OpenRouter’s catalog under `anthropic/` names it doesn’t serve. Give it the Chat Completions base, `https://openrouter.ai/api/v1`, or use the OpenRouter preset, which has both.
- **“Mid-conversation reasoning effort (configuration_update) is not supported”..** OpenRouter says this about Claude Code’s per-turn effort on models such as DeepSeek and GLM. magpie asks again at once without the effort, so the agent gets its answer, and stops sending it to OpenRouter until magpie restarts.
- **402 with “can only afford” or “fewer max_tokens”..** OpenRouter refused the request’s size or its in-flight budget, not because the balance is spent. magpie rests the key for half an hour and tries it again then; unlike a key out of credit, its rest doesn’t grow with each refusal.
- **Web search asks a model you didn’t pick..** It doesn’t: when OpenRouter answers magpie’s web search, magpie asks one of the OpenRouter models you have picked, since OpenRouter can refuse others for your region. For that search magpie turns on OpenRouter’s own `web` plugin, which works with any of its models.
- **Checking a key..** `magpie provider test openrouter` sends a tiny request through each endpoint, or to each model you name. Add `--as codex` or `--as claude-code` to send it the way that agent would.

## FAQ

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

Add your OpenRouter key in magpie (Providers, Add provider, OpenRouter), then pick a model such as `anthropic/claude-opus-5.5` on Claude Code’s row, or run `magpie claude openrouter/anthropic/claude-opus-5.5`. magpie writes Claude Code’s `settings.json` and passes its requests on to OpenRouter’s Anthropic endpoint as they are.

### Can Codex use OpenRouter models?

Yes. Codex speaks only the Responses API, which magpie doesn’t use at OpenRouter. magpie translates each Codex request: a Claude model goes to OpenRouter’s Anthropic endpoint and every other model to Chat Completions, and the reply comes back to Codex as Responses.

### Can Gemini CLI and OpenCode use OpenRouter?

Yes. Gemini CLI’s requests are translated the same way as Codex’s. OpenCode speaks Chat Completions, so its requests go to OpenRouter as they are, except for Claude models, which magpie sends to the Anthropic endpoint so the prompt cache works.

### How do I use only OpenRouter’s free models?

Make a routing group from the pattern `openrouter/*:free`, for example `magpie group add my-free-pool models='openrouter/*:free' routing=order`. It takes every free model OpenRouter lists, including ones it lists later. Models priced at $0 show free in magpie’s pickers.

### Why do OpenRouter’s free models answer 429?

OpenRouter’s free models take 20 requests a minute. Set `magpie provider rpm openrouter 20` and magpie holds requests back to that rate. When the 429 comes from the shared pool of the provider serving one free model, magpie rests only that model and keeps the other free models in use.

### Does magpie show my OpenRouter credits?

Yes. magpie reads OpenRouter’s credits endpoint and shows what is left in dollars: total credits less total usage. The figure is for the whole account, so every key of one account shows the same.

### Why does magpie fetch OpenRouter’s model list from /api/v1?

Asked at the Anthropic base, OpenRouter answers with its catalog under `anthropic/` names it doesn’t serve. magpie fetches the list from the Chat Completions base, `https://openrouter.ai/api/v1`, and a provider given only OpenRouter’s Anthropic base is told to add that Chat base.

**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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

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/copilot

# GitHub Copilot in Claude Code, Codex, Gemini CLI and OpenCode

A Copilot seat comes with Claude, GPT and Gemini models, among others. Sign in to Copilot once in magpie, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use the models your plan gets, through magpie’s gateway at `127.0.0.1:3425`. No API key.

## Sign in to Copilot

1. **Open Add provider.** In magpie’s Providers tab, press ＋ Add provider and click the Copilot tile.
2. **Enter the code on GitHub.** magpie shows a code and opens GitHub’s device page, `github.com/login/device`. Enter the code and approve. magpie then asks GitHub whose account it is and which plan it has, and the account shows under Copilot.
3. **Pick a model for an agent.** In the Agents tab, click the model on the agent’s row and choose a `copilot/…` model.

```
magpie accounts add copilot                        # github.com
magpie accounts add copilot --host acme.ghe.com    # GitHub Enterprise on GHE.com
magpie accounts copilot                            # each account and what it has used
```

magpie serves a Copilot sign-in from three places:

- **Copilot’s editor plugins..** The sign-in they keep in `~/.config/github-copilot` (`apps.json` or `hosts.json`).
- **The Copilot CLI..** Its sign-in in `~/.copilot/config.json`, with the token in the system keychain or in that file. magpie on Windows also reads the Copilot CLI sign-in of a running WSL distro, from `config.json` only.
- **magpie’s own..** Each account you sign in with a code in magpie. Its token is kept in magpie’s own `logins.json`.

The editors’ and the CLI’s sign-ins are only read; magpie never writes them. When both are there, the editors’ github.com sign-in comes first, then the CLI’s, then an editor’s GHE.com sign-in. If GitHub turns away the editors’ token, magpie uses the CLI’s sign-in of the same account instead, never another account’s.

> **GitHub Enterprise on GHE.com.** An enterprise with data residency signs in at its own `<name>.ghe.com`, so add the account with `--host` (or answer the GHE.com question in the sign-in sheet). magpie accepts github.com or a `<name>.ghe.com` address and nothing else, so a GitHub token is never sent to a host of your choosing. The account is served at its enterprise’s `copilot-api.<name>.ghe.com`. One login on github.com and on GHE.com is two accounts: `you` and `you@acme.ghe.com`.

## The models your seat gets

magpie asks Copilot’s `/models` for each account and lists what comes back, so the list follows your plan rather than a fixed table. The models are named `copilot/` and Copilot’s own id: `copilot/claude-opus-5.5`, `copilot/gpt-5.4`, `copilot/gpt-5.3-codex`. `magpie models` prints them all.

- **Chat models only..** Copilot’s internal models and the ones no model picker offers are left out, and so is a model the account isn’t allowed to turn on.
- **Terms to accept..** A model whose terms are still waiting is listed anyway. The first request for it accepts them, as turning it on in Copilot’s editor would.
- **Reasoning efforts.** come from what Copilot lists for each model, and show in each agent’s picker.
- **Auto.** is always on the list; see Copilot Auto.
- **Image models.** such as GPT Image 2.5 Flare are listed for drawing (Settings → Models → Images), and are never offered as a chat model.
- **Older models..** A model for which Copilot names no API, such as GPT-4.1 and GPT-4o on a Student plan, is asked on Chat Completions only.

Claude Code reads a Claude version written with a dot as an older model, so magpie gives it Copilot’s Claude models with dashes (`claude-opus-5-5`) and turns the name back before the request reaches Copilot. Other agents see Copilot’s own spelling.

## 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 copilot/claude-opus-5.5
magpie codex copilot/gpt-5.4
magpie gemini model copilot/gpt-5.4-mini
magpie opencode copilot/claude-opus-5.5
```

- **Claude Code.** speaks Anthropic Messages. Copilot serves its Claude models on Messages too, so Claude Code’s requests go to them as they are; a GPT or Gemini model gets them translated. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses, and magpie asks Copilot’s OpenAI models on Responses, so they pass through. Codex’s web search runs on Copilot’s side for those models, and Codex’s native compaction works with them too, but not with Copilot’s Claude models. [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. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

The Copilot CLI is one of the agents magpie connects, too. Its row offers `auto` (Copilot picks) and Copilot’s own models, plus every other model you have added to magpie, which reach it through the Copilot CLI’s `providers.json`.

## How requests reach Copilot

Copilot doesn’t serve every model on every API. Its newest OpenAI models answer only on Responses; its Claude models on Chat Completions and Anthropic Messages; its Gemini models and the older ones on Chat Completions only. magpie sends each request on an API the model is served on, and translates between that API and the agent’s when they differ, streaming and tool calls included.

- **Wrong API..** When Copilot answers that a model isn’t served on the API it was asked on, magpie rebuilds the request for the next one and remembers which one worked.
- **Pin one yourself..** `magpie model api copilot/<model> chat` (or `responses`, `anthropic`) asks the model on that API only; `auto` hands the choice back to magpie.
- **Tool schemas for Gemini..** Copilot turned some of Codex’s tool schemas away for its Gemini models with 400 “invalid request body”. magpie rewrites the ones it can prove safe to rewrite, so those tools reach the model.

## Copilot Auto

`copilot/auto` is the model Copilot chooses for your account. It isn’t in Copilot’s `/models`, so magpie always adds it. On a Student plan it is the only model you may choose.

- magpie asks Copilot for a pick with the turn’s prompt, at Copilot Chat’s default setting, and keeps a pick for at most an hour.
- If Copilot has no Auto for the account, or picks a model the account was refused, a model the account may pick by hand stands in for 10 minutes: Copilot’s base model, its default, `gpt-4.1`, a model that isn’t premium, then the rest.
- If Copilot then refuses the model Auto picked, magpie picks another and sends the request again.
- The model Auto chose is noted on the request’s route, so you can see what answered.

## Premium requests, usage and cost

Each Copilot account has a card with three allowances, as GitHub reports them: Premium requests, Chat requests and Completions, each as used / allowance. `magpie accounts copilot` prints the same.

- **Monthly..** The allowances renew each month, on the date GitHub gives.
- **Unlimited.** shows as Unlimited. A window GitHub gives no figure for is left off the card, never shown as unlimited.
- **One request a turn..** A turn you type is billed as one request; the tool replies that carry it on are not.
- **Business and Enterprise..** A seat that uses up its allowance is paused, so magpie counts the account as used up and moves on to the next one. An organization’s pooled premium allowance shows as used up once the pool is spent.
- **Other plans..** When your plan lets you pay past the premium allowance, using it up doesn’t stop the account. Completions are counted too, but no request through magpie uses them.
- **No allowance..** Copilot’s base model, `gpt-4.1`, is billed to no allowance on any plan.

The Usage tab counts tokens, cache hits and cost for each agent and model that went through magpie. Cost on a subscription is an estimate at the model maker’s list price, or at the price you set for the model. One difference from Anthropic’s own pricing: Copilot bills a cache write at one price however long it is kept, so magpie prices a 1-hour write at the 5-minute rate. For `claude-opus-5.5` that is $5 per million tokens, where Anthropic’s 2× input would be $8.

## Several accounts and failover

- **Add another..** Click the Copilot tile again, or run `magpie accounts add copilot` again. The one in use is listed first, then the rest in the order you added them.
- **Choose which goes first..** `magpie accounts switch copilot <login>`; `magpie accounts forget copilot <login>` removes one. With the same login on github.com and GHE.com, name it in full (`you@acme.ghe.com`) or add `--host`.
- **Spread requests..** Tick the accounts to use on Copilot’s row. Routing sets how requests spread over them, Smart by default; the provider’s Fallback lists models to use when every account is out, rate limited or down. See [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions#accounts).
- **One model from two subscriptions..** Claude Opus from your Claude subscription and from Copilot become one group by themselves, `auto/<model>`. To set the order yourself: `magpie group add "Opus anywhere" models=claude/claude-opus-5-5,copilot/claude-opus-5.5 routing=order`.
- **A stale editor sign-in..** When GitHub refuses the token Copilot’s editors keep, an account you signed in to magpie with the same login is kept and used.

## Troubleshooting

| What you see | What it means |
| --- | --- |
| GitHub refused this Copilot sign-in; sign in again | GitHub turned the account’s token away. Sign in again from its row: the account is signed in again in place, and its settings stay. A network error or a 5xx from GitHub never marks an account, and the mark goes when a request is served. |
| the GitHub token Copilot’s editors keep in … was refused | The editors’ sign-in has lapsed. Sign in to Copilot again in your editor or in magpie, or move that file aside. |
| <login> has no Copilot subscription | The GitHub account you approved has no Copilot plan. Sign in with the account that has the seat. |
| Copilot doesn’t serve this model on Anthropic’s Messages API; it isn’t about your plan | Copilot serves that model on other APIs only. `magpie model api copilot/<model> chat` sends it on Chat Completions. |
| The requested model is not supported. | Copilot won’t serve that model to this account now. magpie leaves it out of the account’s models and the agents’ pickers for 6 hours, then tries it again. Under Auto, another model is picked and the request is sent again. |
| Copilot doesn’t offer Auto to this account … | Copilot made no pick and the account lists no model it may pick by hand. Check the plan at `github.com/settings/copilot`. |
| the code expired; start again · the sign-in was declined on GitHub | The device code ran out before it was entered, or the request was declined on GitHub’s page. Start the sign-in again. |
| Copilot signs in on github.com or an enterprise’s <name>.ghe.com, not … | The `--host` given isn’t github.com or a GHE.com address. |
| subscription accounts are off in magpie | Settings → Privacy → Subscription accounts is off (or `magpie accounts discovery off` was run), so magpie reads no sign-in and serves no subscription, Copilot included. Turn it on, or run `magpie accounts discovery on`. |

## FAQ

### How do I use GitHub Copilot in Claude Code?

Sign in to Copilot in magpie (Providers, Add provider, Copilot; GitHub gives you a code to enter), then pick a `copilot/…` model such as `copilot/claude-opus-5.5` on Claude Code’s row, or run `magpie claude copilot/claude-opus-5.5`. magpie writes Claude Code’s `settings.json`. Copilot’s Claude models get Claude Code’s Anthropic requests as they are; its GPT and Gemini models get them translated.

### Can Codex use Copilot’s models?

Yes. Codex speaks OpenAI Responses, and magpie asks Copilot’s OpenAI models on Responses too, so they pass through, web search included. Copilot’s Claude and Gemini models are translated. Pick one on Codex’s row or run `magpie codex copilot/gpt-5.4`; it shows in Codex’s `/model` list.

### Can I use Copilot in Gemini CLI and OpenCode?

Yes. Run `magpie gemini model copilot/gpt-5.4-mini` or `magpie opencode copilot/claude-opus-5.5`, or pick the model on the agent’s row. magpie translates Gemini CLI’s requests, and writes the model into OpenCode’s `opencode.json`.

### Do I need VS Code or another editor signed in to Copilot?

No. magpie signs in to GitHub itself with a device code. If Copilot’s editor plugins or the Copilot CLI are already signed in on this computer, magpie reads that sign-in too, and never changes it.

### Does it spend my premium requests?

Requests go to Copilot on your account, so they count against your plan as Copilot counts them. A turn you type is billed as one request; the tool replies that carry it on are not. magpie shows each account’s Premium requests, Chat requests and Completions as used out of the allowance.

### Does it work with Copilot Business, Enterprise and GHE.com?

Yes. magpie reads the plan from GitHub: Free, Pro, Pro+, Max, Education, Business or Enterprise. An enterprise on GHE.com signs in with `magpie accounts add copilot --host <name>.ghe.com`. A Business or Enterprise seat that uses up its allowance is paused, and magpie counts the account as used up until it renews.

### Why is a Copilot model missing from my list?

magpie lists what Copilot’s `/models` gives the account: chat models only, without the ones no model picker offers or the account can’t turn on. A model Copilot answered with “The requested model is not supported.” is left out for 6 hours, then tried again in case your plan changed.

**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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [Ollama](https://usemagpie.ai/docs/ollama)

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/gemini

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

Google serves Gemini on the Gemini Developer API, the one an AI Studio key opens, and on Vertex AI in your own Google Cloud project. Add either to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Gemini 3 models such as `gemini-3.1-pro-preview` through magpie’s gateway at `127.0.0.1:3425`, each agent on a model of its own.

## Add a Gemini API key

1. **Get a key.** Make one on [aistudio.google.com/apikey](https://aistudio.google.com/apikey).
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick Google Gemini, paste the key and save. magpie asks Google 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 Gemini model such as `gemini-3.1-pro-preview`.

```
magpie provider add google AIza…
magpie provider test google
```

Model ids in magpie are `provider/model`, so the Gemini API’s read `google/gemini-3.1-pro-preview`: the provider, then Google’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

## Endpoints

| API | Base URL | Used for |
| --- | --- | --- |
| Chat Completions (OpenAI-compatible) | `https://generativelanguage.googleapis.com/v1beta/openai` | the model list, and requests from Claude Code, Codex, OpenCode and other agents |
| Gemini API | `https://generativelanguage.googleapis.com/v1beta` | Gemini CLI’s requests, Google Search, image models |

The preset fills in the Gemini API URL once. If you clear it, it stays empty. Every request that doesn’t come from a Gemini client goes to Chat Completions.

## Model list

- **Where it comes from..** magpie asks the OpenAI-compatible endpoint for the list once. It is the Gemini API’s list too, so magpie doesn’t ask twice. Names, reasoning levels and prices come from the `google` catalog on models.dev.
- **Image models..** At Google, a Gemini image model draws on the Gemini API. Choose one in Settings → Models → Images.

## 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 google/gemini-3.1-pro-preview
magpie codex google/gemini-3.1-pro-preview
magpie gemini model google/gemini-3.8-flash
magpie opencode google/gemini-3.1-pro-preview
```

- **Claude Code.** speaks Anthropic Messages. magpie translates each request to Gemini’s Chat Completions and the reply back to Messages, streaming and tool calls included. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks only OpenAI Responses. magpie translates it to Chat Completions the same way, and the reply comes back to Codex as Responses. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Gemini’s own API, so its requests go to the Gemini API as it sends them, and its Google Search runs there. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** speaks Chat Completions, so its requests go to Google as they are. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

## Thinking

- **Visible thoughts..** Gemini’s OpenAI-compatible API gives the model’s thoughts only when asked in `thinking_config`. When an agent asks for visible reasoning, magpie asks for the thoughts with `include_thoughts`, so a long think shows as thinking instead of a first word that comes late.
- **Levels and budgets..** Gemini 3 and later are sent a thinking level. Gemini 2 models are sent a budget instead: 1024 tokens for minimal and low, 8192 for medium and 24576 for high. xhigh and max are sent as high, and an effort with no level is left to the model.
- **Reasoning off..** Gemini 3 can’t stop thinking. When an agent turns reasoning off, magpie asks for the model’s lowest level instead.
- **A level the model doesn’t have..** Not every Gemini 3 has every level: `gemini-3.8-flash` has no minimal. When Google turns a level away with a 400, magpie asks again at the nearest level the model has and remembers it until magpie restarts.
- **`thinking_config` turned away..** That is a different 400: a server in front of Gemini that refuses the field itself. magpie asks again with `reasoning_effort` alone and stops sending `thinking_config` there.
- **Proxies..** A Gemini model behind a proxy on this computer or your network, such as one on `localhost` or a private address, is handled the same way.

## Thought signatures and tools

- **Thought signatures..** Gemini 3 signs the first function call of each step, and the next request fails with 400 “Function call is missing a thought_signature in functionCall parts” if the signature is gone. Agents don’t keep it. magpie carries it in the call id the agent gets, as a short reference to a file in magpie’s folder, and puts it back on the way to Gemini. Signatures are kept for 90 days.
- **Calls Gemini didn’t sign..** A call from another model earlier in the conversation, or one whose id an agent shortened, goes with Google’s documented `skip_thought_signature_validator`, so a conversation can move to Gemini halfway.
- **One provider’s signature..** A signature goes back only to the provider that gave it. In a routing group of Vertex AI and the Gemini API, the other provider gets the call as unsigned history instead of answering “Corrupted thought signature”.
- **Tool schemas..** magpie gives each untyped schema in an agent’s tools a type, which Vertex AI needs, and removes boolean schemas and `x-` keywords such as MCP’s `x-mcp-header`. Tools that need none of this go as they came.
- **The end of a stream..** Gemini’s OpenAI-compatible API sends a whole function call in one chunk and its `finish_reason` in the next. If that reason is lost after the usage arrived, magpie fills it in; without the usage, the reply is reported as cut off rather than passed on as complete.

## Cache, cost and search

- **Prompt cache..** Gemini keeps a prompt cached without saying so on that turn. magpie counts such a turn as a cache write and keeps the next turn on the same provider and key, and remembers which one answered across restarts.
- **Cached and thinking tokens..** magpie reads cached tokens and reasoning tokens from each reply, on Chat Completions and on the Gemini API alike, and the Usage tab counts them.
- **Cost..** The Usage tab prices each call from the `google` catalog on models.dev.
- **Web search..** Gemini runs Google Search on the Gemini API only for a request that declares no function tools. Claude Code’s and Codex’s requests declare tools, so their web search is magpie’s own, which the Google provider answers itself on your key: those searches spend your Gemini API credit.

## Several keys and rate limits

One Google Gemini provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over. The provider’s routing can also rotate, weight or drain them instead.

- **Per-minute 429s..** Gemini’s 429 “You exceeded your current quota … Please retry in 33s” for a per-minute limit is read as a rate limit, not a used-up plan, and so is Vertex AI’s `requests_per_minute_per_project`. The key rests from a minute, doubling, up to `rest-cap`.
- **Holding to a rate..** `rpm` holds each key to a number of requests a minute: one request more waits for room, up to 2 minutes, then gets a 429.
- **Out of quota..** `quota-rest` sets how long a key rests once its quota is spent: 15 minutes by default, up to 8 days, or until a time of day.
- **Spend caps and fallbacks..** `spend-cap` stops a key at a dollar amount a day, a month or in all, and `fallback` names where requests go when Gemini is out of quota or down.

```
magpie provider rpm google 10
magpie provider spend-cap google <key> 20 month
magpie provider fallback google google-vertex/gemini-3.1-pro-preview
```

## Vertex AI

The Google Vertex AI preset asks Gemini in your Google Cloud project, with no API key. Give it the project’s id; the project in each request is the one billed.

```
gcloud auth application-default login
magpie provider add google-vertex project=my-project
magpie claude google-vertex/gemini-3.1-pro-preview
```

- **Credentials..** magpie signs with gcloud’s Application Default Credentials, or with the file `credentials=` names by its full path: a user sign-in, a service account key or an impersonated service account. `impersonate=` takes a service account’s email, and needs `roles/iam.serviceAccountTokenCreator` on it. The metadata server, workload identity federation and Vertex AI’s express-mode API keys aren’t read.
- **Location..** `location=` is `global` (the default), `us`, `eu` or a region such as `us-central1`.
- **Models..** The preset has its own list, among them `gemini-3.8-flash`, `gemini-3.1-pro-preview`, `gemini-2.5-pro`, partner models such as `zai-org/glm-5.2-maas`, and Claude models such as `claude-opus-5-5`. Gemini goes to Vertex AI’s Gemini API, a partner model to its OpenAI-compatible chat completions, and Claude to Anthropic’s Messages API, all in your project.
- **Thinking on Vertex AI..** A Gemini 3 level is fitted to the levels that model has, and reasoning off asks for its lowest. Gemini 2.5 takes a budget: Pro from 128 to 32768 tokens (128 when off), Flash up to 24576 (0 when off), Flash-Lite from 512 to 24576 (0 when off).

## Google sign-ins

Two Google sign-ins give Gemini models without a key. They are subscriptions, set up as on [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions).

- **Gemini (Code Assist)..** Gemini CLI’s Google sign-in, as `gemini/…`: `magpie accounts add gemini`. 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..** As `antigravity/…`: `magpie accounts add antigravity`. Its sign-in gives Antigravity’s Claude and Gemini models.

## Troubleshooting

- **“Thinking level MINIMAL is not supported for this model”..** The model has no minimal level. magpie asks again at the nearest level it has, so the agent gets its answer, and remembers the level until magpie restarts. Only when no level is left does the error reach the agent as Google sent it.
- **“Function call is missing a thought_signature in functionCall parts”..** A Gemini 3 call lost its signature. Through magpie the signature rides in the call id and is put back, and a call with none goes with `skip_thought_signature_validator`.
- **“Corrupted thought signature”..** The signature was cut short or came from another provider. magpie sends a signature only to the provider that gave it.
- **429 with “Please retry in 33s”..** A per-minute limit, not a spent plan. The key rests for a short while, and `rpm` keeps requests under the limit from then on.
- **Vertex AI: a schema “didn’t specify the schema type field”..** magpie types every untyped tool schema it sends to Gemini, so this shouldn’t reach the agent.
- **Vertex AI won’t save..** “Google Vertex AI needs the id of your Google Cloud project”: add `project=`. A credentials file has to be given by its full path.
- **Checking a key..** `magpie provider test google` sends a tiny request through each endpoint, or to each model you name. Add `--as codex` or `--as claude-code` to send it the way that agent would.

## FAQ

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

Add a Gemini API key in magpie (Providers, Add provider, Google Gemini), then pick a model such as `gemini-3.1-pro-preview` on Claude Code’s row, or run `magpie claude google/gemini-3.1-pro-preview`. magpie writes Claude Code’s `settings.json` and translates each Messages request to Gemini’s Chat Completions, tool calls and streaming included.

### Can Codex use Gemini models?

Yes. Codex speaks only the Responses API. magpie translates each Codex request to Gemini’s Chat Completions and the reply back to Responses. Run `magpie codex google/gemini-3.1-pro-preview`, or pick the model on Codex’s row.

### Does Gemini 3 Pro keep working across tool calls in Claude Code?

Yes. Gemini 3 signs its function calls and refuses the next request without the signature. magpie carries each signature in the call id the agent gets and puts it back on the way to Gemini, so tool loops keep going, and a call from another model is sent as unsigned.

### Can Gemini CLI and OpenCode use my Gemini key through magpie?

Yes. Gemini CLI’s requests go to the Gemini API as it sends them, Google Search included. OpenCode speaks Chat Completions, so its requests go to Gemini’s OpenAI-compatible API as they are.

### Why does Gemini answer 429 with “Please retry in 33s”?

That is a per-minute limit, not a spent quota. magpie reads it as a rate limit and rests the key briefly. Run `magpie provider rpm google 10`, with your own limit, and magpie holds requests to that rate.

### Can I use Gemini through Vertex AI instead of an API key?

Yes. Add the Google Vertex AI preset with your project’s id, for example `magpie provider add google-vertex project=my-project`. magpie signs with gcloud’s Application Default Credentials or a credentials file, and your project is billed.

### Can I use my Gemini Code Assist or Antigravity sign-in instead?

Yes. Both are subscriptions: `magpie accounts add gemini` or `magpie accounts add antigravity`, then pick a `gemini/…` or `antigravity/…` model. Code Assist needs a Standard or Enterprise account with a Google Cloud project of its own.

**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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

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/grok

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

xAI serves its Grok models on three APIs at once: OpenAI Chat Completions, OpenAI Responses and Anthropic Messages. Add an xAI API key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Grok through magpie’s local gateway at `127.0.0.1:3425`, each agent with a model of its own.

## Add xAI

1. **Get a key.** Make one on [console.x.ai](https://console.x.ai).
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick xAI, paste the key and save. magpie asks xAI which models the key can use.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose a Grok model such as `grok-4.7`.

```
magpie provider add xai xai-…
magpie provider test xai
```

Model ids in magpie are `provider/model`, so xAI’s read `xai/grok-4.7`: the provider, then xAI’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

## Endpoints

| API | Base URL | Used for |
| --- | --- | --- |
| Chat Completions | `https://api.x.ai/v1` | the model list, OpenCode’s requests, and every request magpie translates, Gemini CLI’s among them |
| Responses | `https://api.x.ai/v1` | Codex’s requests, and web search that xAI runs itself |
| Anthropic Messages | `https://api.x.ai` | Claude Code’s requests |

An agent whose API xAI serves is passed on to that API. When magpie has to translate, it uses Chat Completions: it keeps Responses first only for OpenAI’s own models at OpenAI, and Messages first only for Claude models, and Grok is neither.

## Model list

magpie fetches the list from xAI, at `https://api.x.ai/v1/models`, so agents see the models your key can use. Names, reasoning levels and prices come from models.dev’s `xai` catalog. Pick the models agents see in the provider’s model list, or from the terminal:

```
magpie provider models xai +grok-4.7
magpie provider refresh-every xai 1d
```

## In each agent

```
magpie claude xai/grok-4.7
magpie codex xai/grok-4.7
magpie gemini model xai/grok-4.7
magpie opencode xai/grok-4.7
```

- **Claude Code.** speaks Anthropic Messages, and so does xAI at `https://api.x.ai`, so its requests go there as they are, with the fixes below. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks OpenAI Responses, which xAI serves at `https://api.x.ai/v1`, so its requests go there as they are too. If xAI turns away Codex’s custom tools (“unknown variant `custom`”), magpie translates that model’s Codex requests from then on and offers those tools as ordinary functions. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Google’s Gemini API, which xAI doesn’t serve. magpie translates each request to Chat Completions and the reply back, streaming and tool calls included. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** speaks Chat Completions, so its requests go to xAI as they are. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

Grok Build, xAI’s own CLI, can take magpie’s models too: magpie adds them to `~/.grok/config.toml`, so they join its `/model` picker.

## What magpie fixes for xAI

xAI’s API turns away a few things that agents send. magpie changes them on the way, on requests it passes on and on those it translates alike, so the agent never sees these errors:

- **Tool patterns..** xAI reads a tool’s `pattern` with a different regex engine, so a pattern such as Claude Code’s `^[^\s[\]]+$` on Windows failed with “Schema validation failed: … is not a "regex"”. magpie escapes it so xAI reads it as JavaScript does.
- **Tool roots..** A tool whose parameters start with `anyOf`, `oneOf` or `allOf`, such as a Codex desktop automation tool, is folded into an object from the first request. xAI otherwise answers “tool parameter root must be an object type”.
- **Empty fields..** `"required": null` in a tool’s schema, and `"content": null` on a Codex reasoning item, are left out. xAI otherwise answers “/required: null is not of type "array"” or “Could not decode the compaction blob”.
- **System turns..** Claude Code’s system turns in the middle of a conversation are folded into the top-level system prompt. xAI otherwise answers “Invalid request content: Invalid message role.”
- **A tool choice with no tools..** A request that sets `tool_choice` but offers no tools, such as Codex’s compaction summary, goes without it. xAI otherwise answers “A tool_choice was set on the request but no tools were specified”.
- **Codex’s added tools..** xAI’s Responses API doesn’t know Codex’s `additional_tools` items, so magpie puts their tools in the request’s `tools`.
- **Whole numbers..** Grok writes whole numbers in tool-call arguments with a fraction, such as `2500.0`, which Codex’s whole-number fields refuse. magpie writes `2500`, in streamed replies too.

## Reasoning

- **Effort..** The effort an agent asks for is fitted to the nearest level the model has, as the catalog lists them. A model whose levels aren’t known is asked as the agent asked.
- **Reasoning off..** When an agent whose requests magpie translates, such as Gemini CLI, turns reasoning off and the model lists `none` among its levels, magpie asks for none.
- **Switching models mid-conversation..** xAI reads only the sealed reasoning it wrote itself. When a Codex conversation moves to Grok from GPT or from another account, xAI answers “Could not decrypt the provided encrypted_content”. magpie asks again without those items at once, and leaves them out for the rest of that conversation.

## Web search

- **Codex..** xAI runs web search itself on its Responses API, so Codex’s `web_search` is done by xAI.
- **Claude Code, Gemini CLI and OpenCode..** xAI’s Messages and Chat Completions APIs don’t search, so magpie gives the model its own search tool, answered by the searcher chosen in Settings, or by one magpie picks when none is chosen.
- **xAI as the searcher..** Because xAI searches by itself, magpie can pick an xAI key to search for models that can’t.

## Cache, cost and usage

- **Cache tokens..** magpie reads the cached tokens xAI reports in each reply, so the Usage tab counts cache hits apart from the rest of the prompt.
- **Keeping the cache..** With several keys, a conversation stays on its key while its cache is worth keeping, 1,024 tokens or more, and still warm, read within the last five minutes, so a turn isn’t sent to a key with a cold cache.
- **Cost..** The Usage tab prices each Grok call with xAI’s prices from models.dev.
- **Balance..** magpie reads no balance from xAI. Type it in yourself with `key-balance`, and the Usage page shows it less what magpie has priced the key’s calls at since.

## Several keys and failover

One xAI provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over.

- **Spend caps..** `spend-cap` stops a key at a dollar amount a day, a month or in all, as the Usage tab prices its calls; routing then goes on to the other keys and the fallbacks.
- **Fallbacks..** `fallback` names where requests go when xAI is out of quota or down: another provider’s model or a routing group.
- **A request xAI can’t read..** When xAI answers 422 “Failed to deserialize the JSON body … unknown item type”, the request goes to the next member of the routing group, and the key isn’t rested for it.

```
magpie provider spend-cap xai <key> 20 month
magpie provider key-balance xai <key> 25
magpie provider fallback xai deepseek/deepseek-v4-pro
```

## Troubleshooting

- **“maximum prompt length is …”..** The conversation is longer than the model takes. magpie tells the agent so the way it understands, `context_length_exceeded` or Anthropic’s “prompt is too long”, so the agent compacts and tries again.
- **“Could not decrypt the provided encrypted_content”..** Codex moved to Grok mid-conversation with another vendor’s reasoning in it. magpie asks again without it; see Reasoning.
- **“unknown variant `custom`”..** xAI turned away Codex’s custom tools. magpie translates that model’s Codex requests from then on; the first refusal is the last.
- **Checking a key..** `magpie provider test xai` sends a tiny request through each endpoint, or to each model you name. Add `--as codex` or `--as claude-code` to send it the way that agent would.

## FAQ

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

Add your xAI API key in magpie (Providers, Add provider, xAI), then pick a Grok model such as `grok-4.7` on Claude Code’s row, or run `magpie claude xai/grok-4.7`. Claude Code’s requests go through magpie’s gateway to xAI’s Anthropic Messages endpoint, `https://api.x.ai`.

### Can Codex use Grok 4?

Yes. xAI serves the Responses API that Codex speaks, so `magpie codex xai/grok-4.7` sends Codex’s requests to `https://api.x.ai/v1` as they are, with what xAI would refuse fixed on the way: tool schemas, a tool choice with no tools, and whole numbers Grok writes as `2500.0`.

### Can Gemini CLI and OpenCode use Grok?

Yes. Gemini CLI speaks Google’s API, so magpie translates its requests to xAI’s Chat Completions and the replies back. OpenCode speaks Chat Completions, so its requests go to xAI as they are. Run `magpie gemini model xai/grok-4.7` or `magpie opencode xai/grok-4.7`.

### Does web search work with Grok?

Yes. Codex’s web search is run by xAI itself on its Responses API. For Claude Code, Gemini CLI and OpenCode, magpie gives the model its own search tool, answered by the searcher chosen in Settings, or by one magpie picks.

### Why did Codex fail after switching from GPT to Grok mid-conversation?

xAI can’t read reasoning that another vendor sealed, and answers “Could not decrypt the provided encrypted_content”. magpie asks again without those items and leaves them out for the rest of the conversation.

### Does magpie show my xAI balance?

No. The Usage tab counts tokens, cache and cost for every Grok call, priced from models.dev, but magpie reads no balance from xAI. You can type the balance in with `magpie provider key-balance`, and the Usage page shows it less what magpie has priced since.

**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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

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/mistral

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

Mistral serves its models on one API, OpenAI-style Chat Completions, at `api.mistral.ai`. Add a Mistral API key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Mistral through magpie’s local gateway at `127.0.0.1:3425`, each agent with a model of its own. Agents that speak another API are translated on the way.

## Add Mistral

1. **Get a key.** Make one on [console.mistral.ai](https://console.mistral.ai/api-keys). A Le Chat plan’s Vibe key goes in the same provider.
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick Mistral, paste the key and save. magpie asks Mistral which models the key can use.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose a Mistral model such as `mistral-large-4`.

```
magpie provider add mistral <key>
magpie provider test mistral
```

Model ids in magpie are `provider/model`, so Mistral’s read `mistral/mistral-large-4`: the provider, then Mistral’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

Already set Mistral up in OpenCode or Alma? magpie’s import from those apps brings it in as the Mistral provider. An app that keeps one entry per key (“Mistral #0001”, “Mistral #0002”…) becomes one Mistral provider with that many keys, listed once in every agent’s picker.

## Endpoints

| API | Address | Used for |
| --- | --- | --- |
| Chat Completions | `https://api.mistral.ai/v1` | the model list and every agent’s requests: OpenCode’s as they are, Claude Code’s, Codex’s and Gemini CLI’s translated |
| Billing | `https://api.mistral.ai/v1/billing/budget`, `/v1/billing/subscription` | a key’s month of Vibe or API budget, and the plan it is on |

magpie’s Mistral provider has no Anthropic Messages or Responses address, so an agent that speaks either is translated to Chat Completions and the reply translated back, streaming and tool calls included.

## Model list

magpie fetches the list from Mistral, at `https://api.mistral.ai/v1/models`, so agents see the models your key can use. Names, reasoning levels and prices come from models.dev’s `mistral` catalog, and Devstral, Codestral and Magistral models carry Mistral’s logo in every picker. Mistral also serves models from other labs, such as GLM and DeepSeek’s `deepseek-v4.1-flash-1017`; they come through the same key, and the fixes below apply to them too. Pick the models agents see in the provider’s model list, or from the terminal:

```
magpie provider models mistral +mistral-large-4 +mistral-medium-3.5
magpie provider refresh-every mistral 1d
```

## In each agent

```
magpie claude mistral/mistral-large-4
magpie codex mistral/mistral-large-4
magpie gemini model mistral/mistral-large-4
magpie opencode mistral/mistral-large-4
```

- **Claude Code.** speaks Anthropic Messages, which Mistral doesn’t serve. magpie translates each request to Chat Completions and the reply back; a reasoning model’s thinking reaches Claude Code as thinking, then the text. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks OpenAI Responses, which Mistral doesn’t serve either, so its requests are translated too. Codex’s custom tools, such as `apply_patch`, are offered to the model as functions, and its calls come back as the custom tool calls Codex runs. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Google’s Gemini API. magpie translates each request to Chat Completions and the reply back. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** speaks Chat Completions, so its requests go to Mistral as they are, with the fixes below. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

## What magpie fixes for Mistral

Mistral’s API is strict about what it takes and sends a reasoning model’s thinking in a shape of its own. magpie changes both on the way, on requests it passes on and on those it translates alike:

- **Thinking in typed parts..** Mistral sends a reasoning model’s thinking as typed parts in `content`, thinking and text sometimes in one chunk, where the Chat contract has a string. OpenCode turned the first such chunk away (“Invalid … stream event”). magpie moves the thinking to `reasoning_content` and the text to a plain string, streamed or not.
- **Thinking sent back..** OpenCode sends an earlier turn’s thinking back in `reasoning_content`, which Mistral refuses with 422 `extra_forbidden`. magpie puts it in the thinking part Mistral itself returns, ahead of the turn’s text, so the thinking stays in context. Translated requests get the same, so a Codex tool loop keeps going on a DeepSeek model served by Mistral.
- **Fields Mistral doesn’t know..** OpenCode’s `store` and Kimi Code’s thinking switch got 422 `extra_forbidden`. magpie asks again without the optional fields Mistral named, and doesn’t send them to it again once that works.
- **Ollama options..** An agent that took the gateway for an Ollama server, such as Hermes Agent, sends Ollama’s `options` (its `num_ctx`) beside the Chat fields. magpie leaves them out, so Mistral never sees them.

## Reasoning

- **Effort..** The effort an agent asks for is fitted to the nearest level the model has, as the catalog lists them. A model whose levels aren’t known is asked as the agent asked.
- **Reasoning off..** When an agent whose requests magpie translates, such as Gemini CLI, turns reasoning off and the model lists `none` among its levels, magpie asks for none.
- **Thinking across turns..** Each agent sees a reasoning model’s thinking in its own shape: `reasoning_content` for OpenCode, thinking blocks for Claude Code, reasoning for Codex. When it comes back in a later turn, Mistral gets it as a thinking part; see What magpie fixes.

## Web search

Mistral’s Chat Completions API doesn’t search the web for magpie, so magpie gives the model its own search tool in every agent, answered by the searcher chosen in Settings, or by one magpie picks when none is chosen.

## Vibe, cost and usage

- **Vibe month..** A Le Chat plan (Pro, Student or Team) comes with a month of Mistral Vibe. Its Vibe key’s row shows how much of the month’s budget is used, in the currency Mistral bills in, when it resets, and the plan’s name.
- **API month..** A Studio key made in the console shows the organization’s API budget, as “API · Month”, apart from a Vibe month. The budget is the organization’s, so every key of one organization shows the same numbers. A key with no budget has no card.
- **Pay as you go..** With pay-as-you-go on, what goes past the budget is billed rather than stopped, so a used-up month doesn’t stop the key’s models.
- **Cache tokens..** When a reply reports cached prompt tokens, the Usage tab counts them apart from the rest of the prompt.
- **Keeping the cache..** With several keys, a conversation stays on its key while its cache is worth keeping, 1,024 tokens or more, and still warm, read within the last five minutes.
- **Cost..** The Usage tab prices each call with Mistral’s prices from models.dev. magpie reads no balance from Mistral; type it in with `key-balance`, and the Usage page shows it less what magpie has priced the key’s calls at since.

## Several keys and failover

One Mistral provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over.

- **Spend caps..** `spend-cap` stops a key at a dollar amount a day, a month or in all, as the Usage tab prices its calls; routing then goes on to the other keys and the fallbacks.
- **Fallbacks..** `fallback` names where requests go when Mistral is out of quota or down: another provider’s model or a routing group.

```
magpie provider spend-cap mistral <key> 20 month
magpie provider key-balance mistral <key> 25
magpie provider fallback mistral deepseek/deepseek-v4-pro
```

## Troubleshooting

- **422 `extra_forbidden`, “Extra inputs are not permitted”..** Mistral turned away a field it doesn’t know. magpie fixes the ones agents are known to send and asks again without an optional field Mistral names; see What magpie fixes.
- **“Invalid … stream event” in OpenCode..** That was Mistral’s thinking in typed parts. magpie sends OpenCode the thinking in `reasoning_content` and the text as a string.
- **No Vibe card..** magpie shows the month only for a key Mistral says is a Vibe key or a Studio key, and only when its budget is more than zero.
- **Checking a key..** `magpie provider test mistral` sends a tiny request through each endpoint, or to each model you name. Add `--as codex` or `--as claude-code` to send it the way that agent would.

## FAQ

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

Add your Mistral API key in magpie (Providers, Add provider, Mistral), then pick a Mistral model such as `mistral-large-4` on Claude Code’s row, or run `magpie claude mistral/mistral-large-4`. Mistral serves Chat Completions only, so magpie translates Claude Code’s Anthropic Messages requests to `https://api.mistral.ai/v1` and the replies back, thinking included.

### Can Codex use Devstral and other Mistral models?

Yes. Codex can use any model your Mistral key lists, Devstral among them. Codex speaks OpenAI Responses, which Mistral doesn’t serve, so magpie translates each request to Chat Completions, offers Codex’s custom tools such as apply_patch as functions, and gives the calls back the way Codex runs them.

### How do I use Codestral or other Mistral models in OpenCode?

Pick the model in magpie, or run `magpie opencode mistral/mistral-large-4`; Codestral and Devstral work the same way when your key lists them. OpenCode speaks Chat Completions, so its requests go to Mistral as they are, with what Mistral would refuse fixed on the way: OpenCode’s `store` field, and earlier turns’ thinking sent back in `reasoning_content`.

### Can Gemini CLI use Mistral?

Yes. Gemini CLI speaks Google’s Gemini API, so magpie translates its requests to Mistral’s Chat Completions and the replies back, streaming and tool calls included. Run `magpie gemini model mistral/mistral-large-4`.

### Why does Mistral answer 422 extra_forbidden?

Mistral turns away any field it doesn’t know. magpie sends an earlier turn’s thinking as the thinking part Mistral takes, leaves out Ollama options some agents add, and asks again without an optional field Mistral names, such as OpenCode’s `store`, then stops sending it.

### Does magpie show my Le Chat plan’s Vibe budget?

Yes. A Vibe key from a Le Chat plan (Pro, Student or Team) shows how much of the month’s Vibe budget is used, in the currency Mistral bills in, and when it resets, with the plan’s name. A Studio key made in the console shows the organization’s API budget instead, as “API · Month”.

**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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

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/ollama

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

Ollama serves the models you pull on two APIs, OpenAI Chat Completions and Anthropic Messages, at `http://localhost:11434`. Ollama Cloud serves its models the same way at `ollama.com`, with an API key. Add either to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use them through magpie’s local gateway at `127.0.0.1:3425`, each agent with a model of its own.

## Add Ollama

1. **Pull a model.** Pull a model in Ollama, such as `qwen3`, and leave the server running.
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider and pick Ollama under On this machine. No key is needed. magpie asks the server which models it has, and they show as `ollama/…`.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose an Ollama model.

```
ollama pull qwen3
magpie provider add ollama
magpie provider test ollama
```

Model ids in magpie are `provider/model`, so a model you pulled as `qwen3` reads `ollama/qwen3`. A tag stays in the id, as in `ollama/qwen3:8b`. In the terminal UI, magpie asks for the server’s address when you add it. LM Studio, oMLX, vLLM and llama.cpp’s server are in [Local models](https://usemagpie.ai/docs/local-models).

## Another port or another computer

If Ollama 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. Only the scheme, host and port change; each API keeps its path. The scheme can be left out, and `http` is taken; a path pasted with the address, such as `/v1`, is dropped.

```
magpie provider set ollama address=192.168.1.20:11434
magpie provider set ollama address=     # back to the default
```

- **Proxies..** A server on your own network is reached directly, whatever proxy Settings or the system name. A proxy you set on the provider itself is still used.
- **HTTPS..** An Ollama 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.

## Ollama Cloud

1. **Get a key.** Make one at [ollama.com/settings/keys](https://ollama.com/settings/keys).
2. **Add the provider.** In the Providers tab, press ＋ Add provider, pick Ollama Cloud, paste the key and save. magpie asks Ollama Cloud which models the key can use.
3. **Pick it for an agent.** Choose an Ollama Cloud model, such as `deepseek-v4-pro`, on the agent’s row.

```
magpie provider add ollama-cloud <key>
magpie claude ollama-cloud/deepseek-v4-pro
```

Names, reasoning levels and prices come from models.dev’s `ollama-cloud` catalog. The key is kept in magpie’s settings.

## Endpoints

| Provider | Chat Completions | Anthropic Messages |
| --- | --- | --- |
| Ollama | `http://localhost:11434/v1` | `http://localhost:11434` |
| Ollama Cloud | `https://ollama.com/v1` | `https://ollama.com` |

An agent whose API Ollama serves is passed on to that API. magpie uses no Responses endpoint for either, so when it has to translate, it uses Chat Completions: it keeps Responses first only for OpenAI’s own models, and Messages first only for Claude models.

## Model list

magpie asks the server for its list at the Chat Completions base: `http://localhost:11434/v1/models`, or `https://ollama.com/v1/models` for Ollama Cloud. A model shows in magpie once Ollama has it. After you pull another, press Fetch models in the provider’s editor, or run `magpie provider refresh ollama`. Pick the models agents see in the provider’s model list, or from the terminal:

```
magpie provider refresh ollama
magpie provider models ollama +qwen3
```

Ollama 0.35.0 and later (0.40.5 for its cloud models) also serves decision models, such as Nimble, Clef and Tev. magpie reads Ollama’s `/api/tags` as well, and a model marked there as a decision model becomes one of the provider’s decision models for [intent routing](https://usemagpie.ai/docs/intent), never an agent’s model. An older Ollama lists none.

## In each agent

```
magpie claude ollama/qwen3
magpie codex ollama/qwen3
magpie gemini model ollama/qwen3
magpie opencode ollama/qwen3
```

- **Claude Code.** speaks Anthropic Messages, and so does Ollama at `http://localhost:11434`, so its requests go there as they are. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks OpenAI Responses, which magpie doesn’t send to Ollama. magpie turns each request into Chat Completions and the reply back, streaming and tool calls included. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Google’s Gemini API. magpie translates each request to Chat Completions and the reply back. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** speaks Chat Completions, so its requests go to Ollama’s `/v1` as they are. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

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. To go back to the agent’s own models, run `magpie claude default` or `magpie codex default`.

## Context window and num_ctx

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. magpie doesn’t read an Ollama chat model’s window, so tell it 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
```

- **`num_ctx`..** Some clients send Ollama’s per-request options, such as `{"num_ctx": …}`, beside the Chat Completions fields. magpie leaves them out of every request it sends on: no Chat Completions API reads them, Ollama’s own `/v1` included. The window the model runs with is Ollama’s to set; give magpie the same number.
- **Too long..** When a conversation outgrows the window, Ollama answers “exceeded max context length”. magpie tells the agent so the way it understands, `context_length_exceeded` or Anthropic’s “prompt is too long”, so the agent compacts and tries again.

## Reasoning

- **Effort..** The effort an agent asks for is fitted to the nearest level the model has, as the catalog lists them. A model whose levels magpie doesn’t know is asked as the agent asked.
- **Reasoning off..** When an agent whose requests magpie translates, such as Codex or Gemini CLI, turns reasoning off and the model lists `none` among its levels, magpie asks for none.
- **Your own levels..** `magpie model efforts` offers only the levels you name, or sends a model no reasoning field at all.

```
magpie model efforts ollama/qwen3 low,medium,high
magpie model efforts ollama/qwen3 off
```

## Tool calls

Claude Code’s and OpenCode’s tool calls reach Ollama as the agent wrote them. For Codex and Gemini CLI, magpie translates the tools, the model’s calls and their results to Chat Completions and back, in streamed replies too.

## Privacy 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 Ollama 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`.

- **Cloud models..** Ollama’s cloud models pass a request on to a vendor whatever the address, so it is your call. The editor warns you while it is on for a provider that isn’t local, such as Ollama Cloud.
- **Tool arguments..** In a request in Ollama’s own format, a tool call’s arguments are masked as tool arguments, as in every other API.
- **Anonymous stats..** magpie’s daily stats name an Ollama model only when models.dev knows it; any other counts as “other”. See [Privacy](https://usemagpie.ai/docs/privacy).

## Usage and cost

- **Usage..** The Usage tab counts the tokens of every Ollama call. A model is priced at the price magpie finds for its id, which for a local model can be its maker’s list price. To count a local model at nothing, give it your own price.
- **Free first..** `free=yes` counts every model of the provider as free, so a Free first routing spends it before paid ones. Prices and Usage’s costs stay as listed.
- **Ollama Cloud’s allowance..** magpie reads the account’s balance from Ollama Cloud. The included allowance shows as a plan, in dollars used, with when it resets; an older plan shows its session and weekly limits instead. Credits you bought show as a balance. Past the allowance Ollama Cloud draws on those credits, so a spent allowance with credits left doesn’t stop the key.
- **Peak hours..** On Ollama Cloud, `deepseek-v4.1-flash` and `deepseek-v4-pro` (with their tags) cost double from 12:00 to 18:00 UTC, Monday to Friday. models.dev lists the off-peak price; the Usage tab doubles it in those hours, and a Cheapest first routing counts it.
- **Out of allowance..** When Ollama Cloud says a key is out without saying when it comes back, as its weekly limit does, magpie rests the key for 15 minutes. `quota-rest` sets how long, up to 8 days. With several keys (Add another key) the next one takes over; when every key is out, the gateway answers at once with Retry-After.

```
magpie model price ollama/qwen3 0,0,0,0
magpie provider set ollama free=yes
magpie provider quota-rest ollama-cloud 7d
magpie provider fallback ollama-cloud ollama/qwen3
```

## magpie as an Ollama server

Some apps take a custom model only as an Ollama server: VS Code’s Copilot Ollama provider, Visual Studio’s Copilot BYOK, Zed’s Ollama provider and the `ollama` CLI. Point them at magpie’s gateway, `http://127.0.0.1:3425`, and they see magpie’s models, from every provider, not only Ollama.

- **Routes..** magpie answers `/api/version`, `/api/tags`, `/api/show`, `/api/chat` and `/api/generate`.
- **The same path..** A chat there is served as `/v1/chat/completions` is, so key limits, routing, fallbacks and usage are the same. A gateway key held to some models lists only those.
- **What it tells..** `/api/tags` and `/api/show` mark tools, vision when the model reads images, and thinking when it reasons. `/api/show` also gives the model’s window, or 32768 for one magpie doesn’t know. The `ollama` CLI’s `name:latest` finds a model called `name`.

## Troubleshooting

- **A model you pulled isn’t listed..** The list comes from the server. Press Fetch models, or run `magpie provider refresh ollama`, and pick it in the provider’s model list. Use the name Ollama lists, tag included.
- **Ollama isn’t running..** `magpie provider test ollama` sends a tiny request through each endpoint, or to each model you name; add `--as codex` or `--as claude-code` to send it the way that agent would. Start Ollama, or check Server address. `fallback` names where requests go while it is down.
- **“exceeded max context length”..** The conversation is longer than the model was loaded for. Set the real Context window on the provider, and the agents compact before they reach it.
- **Another computer can’t be reached..** Check the address and port in Server address; for HTTPS with a self-signed certificate, turn on Don't check its certificate.

## FAQ

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

Add Ollama in magpie (Providers, Add provider, Ollama under On this machine), then pick one of its models on Claude Code’s row, or run `magpie claude ollama/qwen3`. Claude Code’s requests go through magpie’s gateway to Ollama’s Anthropic Messages API at `http://localhost:11434` as they are.

### Can Codex use Ollama?

Yes. Codex speaks only the Responses API, so magpie turns its requests into Chat Completions for Ollama, and the replies back, tool calls included. Run `magpie codex ollama/qwen3`.

### Can Gemini CLI and OpenCode use Ollama?

Yes. Gemini CLI speaks Google’s API, so magpie translates its requests to Ollama’s Chat Completions and the replies back. OpenCode speaks Chat Completions, so its requests go to Ollama as they are. Run `magpie gemini model ollama/qwen3` or `magpie opencode ollama/qwen3`.

### How do I run qwen3-coder from Ollama in Claude Code?

Pull it in Ollama, press Fetch models in the provider’s editor in magpie (or run `magpie provider refresh ollama`), and pick it on Claude Code’s row. Its id in magpie is `ollama/` and the name Ollama lists it under, tag included. Set its Context window too: Claude Code takes a model it doesn’t know for 200K.

### Can magpie use Ollama on another computer?

Yes. Set the provider’s Server address to that computer, such as `magpie provider set ollama address=192.168.1.20:11434`. A server on your own network is reached directly, not through a proxy set in Settings or the system.

### Does magpie work with Ollama Cloud?

Yes. Add Ollama Cloud with a key from `ollama.com/settings/keys`. magpie lists the models the key can use, prices them from models.dev, and shows the account’s included allowance and the credits you bought.

### Do I need an API key for a local Ollama?

No. The Ollama preset takes none. Ollama Cloud needs one.

Other local servers, such as LM Studio, oMLX, vLLM and llama.cpp’s server, are in [Local models](https://usemagpie.ai/docs/local-models). To let a local model classify each request for routing, see [Intent routing](https://usemagpie.ai/docs/intent).

**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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot)

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/anthropic

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

Anthropic serves Claude on its Messages API, at `api.anthropic.com`. Add an Anthropic API key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Claude models through magpie’s local gateway at `127.0.0.1:3425`, each agent with a model of its own. Agents that speak another API are translated on the way.

## Add Anthropic

1. **Get a key.** Make one on [console.anthropic.com](https://console.anthropic.com/settings/keys). An API key starts with `sk-ant-api`.
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick Anthropic, paste the key and save. magpie asks Anthropic which models the key can use.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose a Claude model such as `claude-opus-5-5`.

```
magpie provider add anthropic <key>
magpie provider test anthropic
```

Model ids in magpie are `provider/model`, so Anthropic’s read `anthropic/claude-opus-5-5`: the provider, then Anthropic’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

Already set Anthropic up in OpenCode or Alma? magpie’s import from those apps brings it in as the Anthropic provider.

This page is about an API key. A Claude Pro or Max subscription is signed in to separately; see [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions).

## Endpoints

| API | Address | Used for |
| --- | --- | --- |
| Messages | `https://api.anthropic.com/v1/messages` | every agent’s requests: Claude Code’s as sent, Codex’s, Gemini CLI’s and OpenCode’s translated |
| Models | `https://api.anthropic.com/v1/models` | the model list |

magpie’s Anthropic provider has no Chat Completions or Responses address, so an agent that speaks either, or Google’s Gemini API, is translated to Messages and the reply translated back, streaming and tool calls included.

## Model list

magpie fetches the list from Anthropic, at `https://api.anthropic.com/v1/models`, every page of it, so agents see the models your key can use. Names, context windows and prices come from models.dev’s `anthropic` catalog. Pick the models agents see in the provider’s model list, or from the terminal:

```
magpie provider models anthropic +claude-opus-5-5 +claude-sonnet-5-5 +claude-haiku-5-5
magpie provider refresh-every anthropic 1d
```

Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 take 1M tokens. On a window that long, Codex compacts a conversation at 272K rather than send ever more of it on every turn; `magpie model compact off` lets it run to the whole window. In Claude Code a Claude model runs to its own window, as Anthropic runs it: 200K unless a `[1m]` one is picked.

## In each agent

```
magpie claude anthropic/claude-opus-5-5
magpie codex anthropic/claude-opus-5-5
magpie gemini model anthropic/claude-sonnet-5-5
magpie opencode anthropic/claude-sonnet-5-5
```

- **Claude Code.** speaks Anthropic Messages, so its requests go to Anthropic as Claude Code sent them, its own cache marks, thinking and betas included, with the fixes below. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks OpenAI Responses, which Anthropic doesn’t serve. magpie translates each request to Messages and the reply back, marks the prompt for Anthropic’s cache, and keeps Claude’s signed thinking across a tool loop. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Google’s Gemini API. magpie translates each request to Messages and the reply back. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** speaks Chat Completions to magpie, so its requests are translated to Messages too. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

## What magpie does for Anthropic

A request magpie translates is built the way Anthropic’s Messages API wants it, and a few things Anthropic would refuse are fixed on Claude Code’s requests too:

- **Prompt caching..** Anthropic caches a prompt only up to a block marked with `cache_control`, and a request from another API has no marks. magpie marks the system prompt (or the last tool, when there is no system prompt) and the conversation’s last block, two marks at most, so the next turn reads what came before from the cache. A request that brings `cache_control` of its own keeps its marks, and magpie adds none.
- **An hour’s cache for Codex..** Codex’s turns are often more than five minutes apart, so the marks magpie adds to its requests last an hour, unless Codex asks `prompt_cache_retention` `in_memory`. An upstream that turns the hour’s `ttl` away is asked again with five-minute marks, and magpie remembers it.
- **Signed thinking..** Claude signs its thinking and wants it back on a tool loop’s next turn. Codex gets each thinking block, signature included, in its reasoning item’s `encrypted_content`, and magpie sends it back to Anthropic as it was; redacted thinking goes back sealed. Thinking with no signature is left out, and so is thinking another vendor signed, such as DeepSeek’s earlier in a routing group, which Claude refuses.
- **Tool calls..** A call an interrupted turn left unanswered gets a result saying it is unavailable, and a result for a call Anthropic never saw becomes text, where Anthropic would refuse the request. A history with calls but no tools declared declares them, with `tool_choice` none. A required tool goes as `any`, a named one as `tool`, and parallel calls turned off as `disable_parallel_tool_use`.
- **Sampling..** Opus 4.7 and later, Sonnet 5 and 5.5, Haiku 5.5 and Fable 5 refuse `temperature`, `top_p` and `top_k`, which Claude Code’s auto mode classifier sends. magpie leaves them out for those models.
- **Betas..** The betas an agent asks in `anthropic-beta` go on to Anthropic, save Claude Code’s own sign-in beta (`oauth-…`), which names a credential that never leaves magpie.
- **Structured output..** A request for JSON in a schema goes to Anthropic as `output_config.format`.

## Reasoning

- **Effort..** Claude models from 4.6 on think adaptively. A translated request’s effort goes as `output_config.effort`, with thinking adaptive and its summary shown (`display: summarized`), since Opus 4.7 and later leave the thinking text out unless asked. Opus and Sonnet 4.6 have no xhigh, so xhigh is asked as max.
- **Budgets..** Older Claude models get a thinking budget: 4,096 tokens at low, 10,000 at medium, 24,000 at high, 32,000 at xhigh and max, fitted under the request’s `max_tokens`.
- **A budget to a newer model..** A request with a thinking budget to a model from 4.6 on, which Claude Opus 5.5 refuses (“requires adaptive thinking”), goes as adaptive thinking, the budget asked as the nearest effort.
- **Reasoning off..** Codex’s or a Chat client’s effort none turns thinking off, not down to a low budget. Each model takes off its own way: Sonnet 5.5 is sent `between_tools`, an effort above high asked as high; Opus 5.5 and Fable 5 always think, so thinking is left out; Opus 5 and Haiku 5.5 are asked high in place of xhigh or max; older Claudes take it as sent. Claude Code’s requests with thinking off are fitted the same way.

## Web search

Anthropic searches the web itself. Claude Code’s WebSearch goes to Anthropic as it is. When Codex, Gemini CLI or a Chat client asks to search, magpie offers Claude Anthropic’s own `web_search_20250305` tool, up to five searches a request, rather than magpie’s searcher.

## Cost and usage

- **Cache tokens..** The Usage tab counts cache reads, five-minute cache writes and hour-long cache writes apart from the rest of the prompt, as Anthropic reports them.
- **Cost..** The Usage tab prices each call with Anthropic’s prices from models.dev. An hour-long write is priced at twice the input price where the catalog gives none, as Anthropic bills it. magpie reads no balance from Anthropic; type it in with `key-balance`, and the Usage page shows it less what magpie has priced the key’s calls at since.
- **Keeping the cache..** With several keys, a conversation stays on its key while its cache is worth keeping, 1,024 tokens or more, and still warm: read within the last five minutes, or within the hour when it was written for an hour.

## Several keys and failover

One Anthropic provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over.

- **Spend caps..** `spend-cap` stops a key at a dollar amount a day, a month or in all, as the Usage tab prices its calls; routing then goes on to the other keys and the fallbacks.
- **Fallbacks..** `fallback` names where requests go when Anthropic is out of quota or down: another provider’s model or a routing group.
- **Workspaces..** A key that reaches several workspaces names the one each request is for with the `anthropic-workspace-id` header. Add the provider again under an id of its own, with the header set in its Headers field or from the terminal; its models then read `anthropic-ws2/…`.

```
magpie provider spend-cap anthropic <key> 20 month
magpie provider key-balance anthropic <key> 25
magpie provider fallback anthropic deepseek/deepseek-v4-pro
magpie provider add anthropic <key> id=anthropic-ws2 name="Anthropic WS2" header.anthropic-workspace-id=wrkspc_…
```

## Troubleshooting

- **“requires adaptive thinking”..** A thinking budget sent to a model from 4.6 on. magpie sends it as adaptive thinking with the nearest effort; see Reasoning.
- **400 when thinking is turned off..** Sonnet 5.5, Opus 5.5 and Fable 5 each refuse `disabled`, and Opus 5 and Haiku 5.5 refuse it at xhigh and max. magpie sends each model off the way it takes it.
- **“`temperature` is deprecated for this model”..** magpie leaves `temperature`, `top_p` and `top_k` out for the models that refuse them.
- **“`tool_use` ids were found without `tool_result` blocks”..** An interrupted turn left a call unanswered. In a request magpie translates, the call gets a result saying it is unavailable.
- **“Invalid `signature` in `thinking` block”..** The conversation ran on another vendor first. magpie leaves thinking another vendor signed, or left unsigned, out of what goes to Claude.
- **A 400 about `cache_control` and `ttl`..** The upstream doesn’t take the hour-long marks magpie adds for Codex. magpie asks again with five-minute marks and keeps to them for that provider.
- **“this is an Anthropic API key, not a setup-token”..** The key went to the Claude subscription’s sign-in. Add it as the Anthropic provider instead.
- **Checking a key..** `magpie provider test anthropic` sends a tiny request through each endpoint, or to each model you name. Add `--as codex` or `--as claude-code` to send it the way that agent would.

## FAQ

### How do I use an Anthropic API key in Claude Code?

Add your Anthropic API key in magpie (Providers, Add provider, Anthropic), then pick a Claude model such as `claude-opus-5-5` on Claude Code’s row, or run `magpie claude anthropic/claude-opus-5-5`. Claude Code speaks Anthropic Messages, so its requests go to `https://api.anthropic.com` as it sent them, with what the model would refuse fixed on the way.

### Can Codex use Claude models?

Yes. Codex speaks OpenAI Responses, which Anthropic doesn’t serve, so magpie translates each request to the Messages API and the reply back. It marks the prompt for Anthropic’s cache with marks that last an hour, and keeps Claude’s signed thinking across a tool loop in Codex’s `encrypted_content`. Run `magpie codex anthropic/claude-opus-5-5`.

### How do I use Claude in OpenCode through magpie?

Pick the model in magpie, or run `magpie opencode anthropic/claude-sonnet-5-5`. OpenCode speaks Chat Completions to magpie, so magpie translates its requests to Anthropic’s Messages API, marks the prompt for the cache and fits the reasoning effort to the model.

### Can Gemini CLI use Claude?

Yes. Gemini CLI speaks Google’s Gemini API, so magpie translates its requests to Anthropic’s Messages API and the replies back, streaming and tool calls included. Run `magpie gemini model anthropic/claude-sonnet-5-5`.

### Does magpie keep Anthropic’s prompt cache for agents it translates?

Yes. A request from Codex, Gemini CLI or OpenCode has no cache marks of its own, so magpie marks the system prompt and the conversation’s last block, two marks at most, and the next turn reads what came before from the cache. A request that brings its own `cache_control` keeps its marks. Codex’s marks last an hour, the rest five minutes.

### Why does Claude answer 400 when thinking is turned off?

Newer Claude models don’t all take `thinking` `disabled`. magpie sends Sonnet 5.5 `between_tools`, leaves thinking out for Opus 5.5 and Fable 5, which always think, and asks Opus 5 and Haiku 5.5 at high in place of xhigh or max. Older Claudes get it as sent.

**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) · [OpenAI](https://usemagpie.ai/docs/openai) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

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/openai

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

OpenAI serves its models on two APIs at `api.openai.com`: Responses and Chat Completions. Its own models are best asked on Responses, and its newest answer only there. Add an OpenAI API key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use OpenAI’s models through magpie’s local gateway at `127.0.0.1:3425`, each agent with a model of its own. Codex’s requests go to OpenAI as they are; the other agents’ are translated on the way.

This page is about an API key from platform.openai.com. A ChatGPT Plus or Pro subscription is signed in to separately; see [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions).

## Add OpenAI

1. **Get a key.** Make one on [platform.openai.com](https://platform.openai.com/api-keys). It starts with `sk-`.
2. **Add the provider.** In magpie’s Providers tab, press ＋ Add provider, pick OpenAI, paste the key and save. magpie asks OpenAI which models the key can use.
3. **Pick it for an agent.** In the Agents tab, click the model on the agent’s row and choose an OpenAI model such as `gpt-6.1-sol`.

```
magpie provider add openai <key>
magpie provider test openai
```

Model ids in magpie are `provider/model`, so OpenAI’s read `openai/gpt-6.1-sol`: the provider, then OpenAI’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

Already set OpenAI up in OpenCode or another app magpie imports from? The import brings it in as the OpenAI provider.

## Endpoints

| API | Address | Used for |
| --- | --- | --- |
| Responses | `https://api.openai.com/v1` | OpenAI’s own models, ids starting `gpt-`, `codex` or `o` and a digit: Codex’s requests as they are, Claude Code’s, Gemini CLI’s and OpenCode’s translated |
| Chat Completions | `https://api.openai.com/v1` | the model list, and any other model the key lists |

magpie’s OpenAI provider has no Anthropic Messages address, so Claude Code’s requests are always translated. For OpenAI’s own models magpie keeps Responses first even for an agent that speaks Chat Completions. When OpenAI answers that a model is served only on `/v1/responses`, magpie asks again there and remembers it. To send a model on one API yourself:

```
magpie model api openai/gpt-5.5 chat
magpie model api openai/gpt-5.5 --reset
magpie model apis openai
```

**Azure OpenAI** is a provider of its own, Azure OpenAI. Give it your resource’s endpoint, `https://<resource>.openai.azure.com`, and its key. magpie uses the v1 API under `/openai/v1` for Chat Completions and Responses, sends the key in the `api-key` header, and lists the resource’s deployments as its models. A deployment named for its model, such as `gpt-5-codex`, goes to Responses first too.

## Model list

magpie fetches the list from OpenAI, at `https://api.openai.com/v1/models`, so agents see the models your key can use. Names, context windows, reasoning levels and prices come from models.dev’s `openai` catalog. A reasoning model OpenAI has just listed, before its levels are known, gets those of the newest reasoning model in its family: `gpt-6.1-sol` got `gpt-6-sol`’s. Pick the models agents see in the provider’s model list, or from the terminal:

```
magpie provider models openai +gpt-6.1-sol +gpt-6-luna +gpt-5.5
magpie provider refresh-every openai 1d
```

## In each agent

```
magpie claude openai/gpt-6.1-sol
magpie codex openai/gpt-6.1-sol
magpie gemini model openai/gpt-6.1-sol
magpie opencode openai/gpt-6.1-sol
```

- **Claude Code.** speaks Anthropic Messages, which OpenAI doesn’t serve. magpie translates each request to Responses and the reply back; the model’s reasoning summary reaches Claude Code as thinking, then the text. [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models).
- **Codex.** speaks Responses, so its requests go to OpenAI as they are: its custom tools such as `apply_patch`, its reasoning items and its own `prompt_cache_key` included. Codex is also offered Fast here; see Reasoning. [Models in Codex](https://usemagpie.ai/docs/codex-models).
- **Gemini CLI.** speaks Google’s Gemini API. magpie translates each request to Responses and the reply back. [Models in Gemini CLI](https://usemagpie.ai/docs/gemini-cli-models).
- **OpenCode.** speaks Chat Completions. OpenAI’s own models go to Responses first, so magpie translates its requests there and the replies back; any other model the key lists gets OpenCode’s requests as they are. [Models in OpenCode](https://usemagpie.ai/docs/opencode-models).

## What magpie does for OpenAI

- **A prompt cache key..** A translated request to OpenAI that carries no `prompt_cache_key` gets one, made from the session the agent names, or else its first user message, and hashed, so it names nothing of the agent. Codex sends its own, which goes on as it is, and one you set yourself wins. If OpenAI answers 400 over the field, magpie asks again without it.
- **Tools loaded where they were loaded..** A tool that Claude Code’s tool search loads mid-conversation is sent to OpenAI’s Responses API as an `additional_tools` item at that point, not added to the tool list, which keeps the cached prefix. `additional-tools=off` puts it with the other tools.
- **Sealed reasoning from elsewhere..** OpenAI reads only its own sealed reasoning (`encrypted_content`). An item sealed under another key, organization or account is refused (“could not be verified”); magpie asks again without those items and remembers it for the conversation. Claude’s thinking, which Codex carries in a reasoning item after a turn on a Claude model, is taken out before the request reaches OpenAI.
- **Earlier responses..** A Responses client may send only a turn’s new input and name the response it follows (`previous_response_id`). magpie keeps each response it gave such a client, in memory and under the caller’s gateway key. OpenAI keeps responses too, so when the same key answered the one named, OpenAI is sent only the new input after its own id. Codex over HTTP says `store` false and names none.
- **Codex’s own compaction..** With `compaction=native`, Codex’s compaction is asked of OpenAI as Codex sent it and the sealed item comes back to Codex as it came. Only the key that sealed it can read it, so later requests carrying it go only there. The default, `compaction=magpie`, has magpie summarise.

```
magpie provider set openai compaction=native
magpie provider set openai additional-tools=off
```

## Reasoning

- **Effort..** The effort an agent asks for is fitted to the nearest level the model has, as the catalog lists them: `gpt-6-sol` has `none`, `low`, `medium`, `high`, `xhigh` and `max`. On Responses it is sent as `reasoning.effort`, with `summary` set to `auto`, so the model’s reasoning summary comes back.
- **Reasoning off..** When an agent whose requests magpie translates, such as Gemini CLI, turns reasoning off and the model lists `none` among its levels, magpie asks for none.
- **Encrypted reasoning..** magpie passes on what an agent asks to include, but asks for `reasoning.encrypted_content` only with reasoning: OpenAI refuses it of a model that doesn’t reason. Codex sends the sealed items back on the next turn, and magpie passes them on as they are.
- **Fast..** On an OpenAI key, Codex is offered Fast for GPT and o-series models. magpie sends it as `service_tier: "priority"`, OpenAI’s priority processing. A service tier set for Codex in magpie overrides what Codex asked.

## Web search

OpenAI’s Responses API searches the web itself. When an agent offers its model web search, as Codex and Claude Code do, magpie gives the model OpenAI’s own `web_search` tool on Responses, and OpenAI runs the search.

## Cost and usage

- **Cost..** The Usage tab prices each call with OpenAI’s prices from models.dev.
- **Cache tokens..** When a reply reports cached prompt tokens, the Usage tab counts them apart from the rest of the prompt.
- **Keeping the cache..** With several keys, a conversation stays on its key while its cache is worth keeping, 1,024 tokens or more, and still warm, read within the last five minutes.
- **Service tier..** Each call records the tier the agent asked for, the one magpie sent, and the one OpenAI’s reply says it ran at.
- **Balance..** magpie reads no balance from OpenAI; type it in with `key-balance`, and the Usage page shows it less what magpie has priced the key’s calls at since.

## Several keys and failover

One OpenAI provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over. To keep keys apart instead, say from two organizations, add the provider again: the second is `openai-2`.

- **Spend caps..** `spend-cap` stops a key at a dollar amount a day, a month or in all, as the Usage tab prices its calls; routing then goes on to the other keys and the fallbacks.
- **Fallbacks..** `fallback` names where requests go when OpenAI is out of quota or down: another provider’s model or a routing group.

```
magpie provider spend-cap openai <key> 20 month
magpie provider key-balance openai <key> 25
magpie provider fallback openai deepseek/deepseek-v4-pro
```

## Troubleshooting

- **“The encrypted content for item rs_… could not be verified”..** The conversation carries reasoning sealed under another key, organization or account. magpie asks again without those items; see What magpie does.
- **A model that answers only on `/v1/responses`..** magpie moves it to Responses and remembers it. `magpie model apis openai` shows which API each model is asked on.
- **A 400 over `prompt_cache_key`..** magpie asks again without the key it added.
- **Checking a key..** `magpie provider test openai` sends a tiny request through each endpoint, or to each model you name. Add `--as codex` or `--as claude-code` to send it the way that agent would.

## FAQ

### How do I use OpenAI’s models in Claude Code?

Add your OpenAI API key in magpie (Providers, Add provider, OpenAI), then pick a model such as `gpt-6.1-sol` on Claude Code’s row, or run `magpie claude openai/gpt-6.1-sol`. OpenAI serves no Anthropic Messages API, so magpie translates Claude Code’s requests to OpenAI’s Responses API at `https://api.openai.com/v1` and the replies back, the reasoning summary as thinking.

### Can Codex use an OpenAI API key instead of a ChatGPT sign-in?

Yes. Add the key, then run `magpie codex openai/gpt-6.1-sol`. Codex speaks Responses, so its requests go to OpenAI as they are, custom tools and reasoning included, and Fast is sent as priority processing. A ChatGPT Plus or Pro sign-in is set up separately, in Subscriptions.

### How do I use GPT models in OpenCode?

Pick the model in magpie, or run `magpie opencode openai/gpt-6.1-sol`. OpenCode speaks Chat Completions, but OpenAI’s own models go to Responses first, so magpie translates OpenCode’s requests there and the replies back. To send a model on Chat Completions instead, run `magpie model api openai/gpt-5.5 chat`.

### Can Gemini CLI use OpenAI?

Yes. Gemini CLI speaks Google’s Gemini API, so magpie translates its requests to OpenAI’s Responses API and the replies back, streaming and tool calls included. Run `magpie gemini model openai/gpt-6.1-sol`.

### Does magpie keep OpenAI’s prompt cache?

Yes. Codex’s own `prompt_cache_key` goes on as it is. A translated request without one gets a key made from its session or first user message, hashed so it names nothing of the agent. With several keys, a conversation stays on its key while its cache is warm.

### Why does OpenAI say the encrypted content could not be verified?

OpenAI reads only reasoning it sealed for the same key, organization or account. When a conversation carries reasoning sealed elsewhere, magpie asks again without those items and remembers it for the conversation.

### Does magpie support Azure OpenAI?

Yes, as its own provider, Azure OpenAI. Give it the resource’s endpoint and key; magpie uses the v1 API under `/openai/v1`, sends the key in the `api-key` header and lists the resource’s deployments as models.

**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) · [Anthropic](https://usemagpie.ai/docs/anthropic) · [Gemini](https://usemagpie.ai/docs/gemini) · [Grok](https://usemagpie.ai/docs/grok) · [Mistral](https://usemagpie.ai/docs/mistral) · [OpenRouter](https://usemagpie.ai/docs/openrouter) · [GitHub Copilot](https://usemagpie.ai/docs/copilot) · [Ollama](https://usemagpie.ai/docs/ollama)

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. Wallet private keys by the shape their wallets export: a Bitcoin WIF, a BIP32 `xprv`, an Ethereum or TRON `0x` key, a Solana key or `id.json` keypair, a Sui `suiprivkey1…`, an Aptos `ed25519-priv-0x…`, a Stellar seed, a NEAR `ed25519:…` key, a Nostr `nsec1…`, an age identity, a Zcash extended spending key, and a 12 to 25 word seed phrase after *seed* or *mnemonic* whose every word is in the BIP39 list. A key with no prefix of its own is masked only when it checks out: a WIF or `xprv` by its checksum, a Solana key by its public half, a Stellar seed by its CRC, so a Solana transaction signature goes as written. A `0x` key has the shape of a transaction hash, so it is masked only after a key&rsquo;s name (`PRIVATE_KEY=`, `--private-key`, `new Wallet(…)`, 私钥); a hash, a storage slot or a sha256 sum goes as written. An exchange&rsquo;s API key, secret and `passphrase` go by their fields&rsquo; names. |
| 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/claude-desktop

# Claude Desktop on any model

Claude Desktop has a third-party gateway mode: no Anthropic sign-in, and its Code and Cowork tabs work on any plan. magpie sets Desktop up in that mode with magpie’s gateway, so Desktop runs on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription.

In its gateway mode Claude Desktop sends every request to one address instead of Anthropic. magpie writes that mode and a profile named magpie, pointing at its gateway, `http://127.0.0.1:3425`, into Desktop’s configuration folders. The gateway speaks Anthropic’s Messages API and translates each request for the model you picked, streaming, tool calls and reasoning included. It works on macOS, Windows (the Store package too) and Linux.

## Turn it on

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Choose magpie on Claude Desktop’s row.** In the Agents tab, Claude Desktop’s row offers magpie: Desktop’s third-party gateway, Code and Cowork on magpie’s models, no Anthropic sign-in.
3. **Quit and reopen Claude Desktop.** Desktop reads this only as it starts.

```
magpie claude-desktop magpie      # Desktop on magpie's gateway
magpie claude-desktop default     # back to the Anthropic sign-in
```

## Pick a model

Desktop lists the gateway’s models when it starts, so its model picker shows the models you have in magpie. A model with a 1M context window is listed once, as its 1M entry. After you add a provider in magpie, quit and reopen Desktop to see its models.

## The Code tab’s tiers

The Code tab runs Claude Code, which asks for models by tier: opus, sonnet, haiku. Left unset, a tier runs on the chat’s model. Pick a model for a tier on Claude Desktop’s row, or from a terminal, and restart Desktop after a change:

```
magpie claude-desktop sonnet deepseek/deepseek-v4-pro
magpie claude-desktop haiku deepseek/deepseek-v4-flash
```

A picked model runs with the prompt of the Claude model of its tier. The row also has a subagent model, which takes effect without a restart.

## Your chats and projects

Desktop keeps its gateway mode in a profile of its own, so chats and projects from your Anthropic sign-in don’t show while it runs on magpie. Nothing is deleted, and switching back brings them back. To go on with them on magpie, use Settings → Import in Desktop, which copies in your Claude.ai chats and projects and leaves the originals as they are.

## A separate Claude Magpie app (Mac)

On a Mac, magpie can run Desktop’s gateway mode in a folder of its own, started by `~/Applications/Claude Magpie.app`. Your own Claude Desktop stays signed in with Anthropic, and both run side by side. It is off by default.

```
magpie claude-desktop launcher add      # make Claude Magpie.app
magpie claude-desktop launcher remove
```

## Switch back

Take Claude Desktop’s row off magpie, or run `magpie claude-desktop default`, then quit and reopen Desktop. magpie puts Desktop’s files back as they were, and your chats from before are there again.

## FAQ

### Do I need a Claude subscription for Cowork and the Code tab?

No. In gateway mode, Desktop’s Code and Cowork tabs work without an Anthropic sign-in, on whatever model magpie serves.

### Can I use my ChatGPT subscription in Claude Desktop?

Yes. Sign in to ChatGPT in magpie, and its GPT models appear in Desktop’s model picker after a restart.

### Why doesn’t Claude Desktop show a new model?

Desktop reads the model list as it starts. Quit and reopen it.

### Why is Claude Desktop in English on magpie?

Desktop’s gateway-mode window has no translation of its own. Switching back brings your language back.

### Are my old chats gone?

No. They stay in Desktop’s own profile and come back when you switch back, or you can import them with Settings → Import.

The same models in the terminal: [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models) and [ChatGPT in Claude Code](https://usemagpie.ai/docs/claude-code-chatgpt). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# OpenClaw on any model

OpenClaw answers you on WhatsApp, Telegram, Discord and more, on whatever model its config names. magpie adds itself to OpenClaw as one provider, so OpenClaw can run on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into OpenClaw.

OpenClaw keeps its settings in `~/.openclaw/openclaw.json`. magpie adds a provider named magpie there: its gateway’s `/v1` address, OpenAI’s chat completions API, a key of OpenClaw’s own, and one entry per model you have in magpie. Then it makes the model you pick OpenClaw’s default. The gateway translates each request for that model’s provider, tool calls and reasoning included.

## Connect OpenClaw

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Pick a model on OpenClaw’s row.** In the Agents tab, choose a model on OpenClaw’s row. OpenClaw takes it up without a restart.

```
magpie openclaw deepseek/deepseek-v4-pro    # OpenClaw on DeepSeek
magpie openclaw                             # what OpenClaw runs on now
```

## Pick a model

In OpenClaw a model is named `provider/model`, so magpie’s models show up as `magpie/deepseek/deepseek-v4-pro`, `magpie/openai/gpt-6.1` and so on. magpie sets the primary model and keeps your fallbacks. If your config has a list of allowed models, magpie adds `magpie/*` to it so its models aren’t refused. A model whose context magpie doesn’t know is given 128K.

## Chats that already have a model

A change to the default model reaches new chats at once. A chat that already has a model keeps it: send `/model default` in that chat to move it onto the new one.

## What magpie writes

Only `models.providers.magpie`, the default model, and the allow list when you have one. Your other providers, channels and keys stay as you wrote them, and so do keys you add to magpie’s provider yourself (headers, timeoutSeconds, a model’s maxTokens). A model set for one agent (`agents.entries.*.model`) stays yours, and a config split with `$include` isn’t changed.

magpie finds the file where OpenClaw does: `$OPENCLAW_CONFIG_PATH`, else `openclaw.json` in `$OPENCLAW_STATE_DIR`, else `~/.openclaw-<profile>` for `$OPENCLAW_PROFILE`, else `~/.openclaw`. A file written in JSON5 that isn’t plain JSON is left alone, and magpie says so.

## Switch back

Take OpenClaw’s row off magpie, or run `magpie openclaw default`. magpie removes its provider and puts back the model OpenClaw ran on before, as long as magpie’s model is still the default; a model you picked since stays.

## FAQ

### Can OpenClaw use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and pick a GPT model on OpenClaw’s row. OpenClaw sends its requests to magpie, which uses the subscription.

### Do I need to restart OpenClaw?

No. OpenClaw’s gateway takes up a change of models and default model by itself. Chats that already have a model keep it until you send /model default there.

### Does magpie touch my channels or other providers?

No. It writes only its own provider, the default model and, if you have one, the allow list.

### I use an OpenClaw profile. Does magpie find it?

Yes. It reads OPENCLAW_PROFILE, OPENCLAW_STATE_DIR, OPENCLAW_CONFIG_PATH and OPENCLAW_HOME the way OpenClaw does.

More agents on the same models: [Models in OpenCode](https://usemagpie.ai/docs/opencode-models), [Hermes Agent on any model](https://usemagpie.ai/docs/hermes) and [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Hermes Agent on any model

Hermes Agent, from Nous Research, runs on the model its config.yaml names. magpie adds itself to Hermes as one provider, so Hermes and each of its bots can run on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into Hermes.

Hermes keeps its settings in `~/.hermes/config.yaml` (`%LOCALAPPDATA%\hermes` on Windows, or `$HERMES_HOME`). magpie adds a provider named magpie to its `providers`: the gateway, spoken to as chat completions, with your models in magpie as its models. Then it points `model.provider` at it and sets `model.default` to the model you pick. The provider and model you had are kept aside and put back when you switch back.

## Connect Hermes

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Pick a model on Hermes Agent’s row.** In the Agents tab, choose a model on Hermes Agent’s row.
3. **Restart open Hermes sessions.** Hermes reads its settings as it starts.

```
magpie hermes deepseek/deepseek-v4-pro    # Hermes on DeepSeek
magpie hermes                             # what Hermes runs on now
```

## Model and reasoning effort

In Hermes’s own model picker, magpie’s models are named `magpie/<provider>/<model>`. The row also sets the reasoning effort, the same setting as Hermes’s `/reasoning`: none, minimal, low, medium, high or xhigh. Left unset, Hermes asks for medium.

```
magpie hermes effort high
magpie hermes effort default    # back to Hermes's own
```

## Bots and profiles

Each Hermes bot is a profile with a config.yaml of its own. magpie connects the profile `hermes` starts in: the one `$HERMES_HOME` names, else the one `hermes profile use` made sticky, else the default. It also adds its provider to every other profile, so magpie’s models are in every bot’s picker. A bot’s own model is left as you set it. With more than one profile, each other bot gets a model picker of its own on the Agents page; a bot still on the model magpie last set follows the next one, until you pick one for it.

## Your own models stay

Pick one of your own models in Hermes, or on the Agents page, and Hermes runs on it, but magpie’s provider stays: Hermes is still connected, and its picker still offers magpie’s models beside yours. Only switching back takes the provider out.

Hermes inside WSL on Windows is found too: magpie writes the distro’s `~/.hermes`, with the gateway at the address the distro reaches it.

## Switch back

Take Hermes Agent’s row off magpie, or run `magpie hermes default`. magpie removes its provider from every profile, puts back the provider and model you had, and leaves each bot on a model it can start with. Connecting again puts the bots back on the models they had.

## FAQ

### Can Hermes Agent use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and pick a GPT model on Hermes Agent’s row. Hermes sends its requests to magpie, which uses the subscription.

### I picked a model in magpie but my bot still uses the old one.

Restart the bot’s Hermes session: Hermes reads config.yaml as it starts. A bot you gave a model of its own on the Agents page doesn’t follow the main one.

### Why does Hermes still say connected after I picked my own model?

magpie’s provider stays so its models remain in Hermes’s picker. Switch back to take it out.

### Does magpie touch my other Hermes providers?

No. It adds its own provider and changes only model.provider, model.default and, when you set it, the reasoning effort.

More agents on the same models: [OpenClaw on any model](https://usemagpie.ai/docs/openclaw), [Models in OpenCode](https://usemagpie.ai/docs/opencode-models) and [Cline on any model](https://usemagpie.ai/docs/cline). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Cline on any model

Cline runs on the provider and model in its settings. magpie sets Cline’s built-in OpenAI-compatible provider to magpie’s gateway, so Cline’s CLI, VS Code extension and desktop app can run on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into Cline.

Cline keeps its providers in `~/.cline/data/settings/providers.json` (or under `$CLINE_DIR`). magpie sets Cline’s own openai-compatible provider to the gateway’s address with a key of Cline’s own, makes it the provider in use, and lists magpie’s models for it in `models.json`, in place of the one model that provider lists by itself. What was there, and the provider you used, are kept aside and put back when you switch back. The gateway translates each request for the model’s provider, tool calls and reasoning included.

## Connect Cline

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Pick a model on Cline’s row.** In the Agents tab, choose a model on Cline’s row.
3. **Start a new Cline session.** Cline reads its provider as a session starts: open sessions keep the model they have, new ones use this.

```
magpie cline deepseek/deepseek-v4-pro    # Cline on DeepSeek
magpie cline                             # what Cline runs on now
```

## Model and reasoning effort

The row also sets the reasoning effort Cline asks for: none, low, medium, high or xhigh. None turns thinking off, as Cline’s own picker does.

```
magpie cline effort high
magpie cline effort default    # back to Cline's own
```

## The VS Code extension

Cline’s VS Code extension uses the same folder but reads the provider, model, address and key from its own state first: the Act and Plan modes’ provider and model, and the OpenAI-compatible key. magpie sets those too, keeping what they were. The extension reads them once, as it starts, so after a change run Developer: Reload Window in VS Code.

## The desktop app

Cline’s desktop app keeps the model and effort you pick in its own composer and doesn’t read them from these files. magpie’s models are in its picker, under magpie: pick one there. magpie’s row sets the CLI and the VS Code extension.

## Switch back

Take Cline’s row off magpie, or run `magpie cline default`. magpie puts back the provider you used, the model list, and the extension’s settings as they were.

## FAQ

### Can Cline use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and pick a GPT model on Cline’s row. Cline sends its requests to magpie, which uses the subscription.

### I changed the model but Cline still uses the old one.

A session keeps the model it started with. Start a new one; for the VS Code extension, reload the window.

### Why doesn’t magpie add its own provider to Cline?

Cline refuses a provider it doesn’t know when a session starts, so magpie uses Cline’s built-in OpenAI-compatible provider instead.

### Does this work in Cline’s desktop app?

Its picker lists magpie’s models under magpie; pick the model there, since the app doesn’t read it from Cline’s files.

More agents on the same models: [Models in OpenCode](https://usemagpie.ai/docs/opencode-models), [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Hermes Agent on any model](https://usemagpie.ai/docs/hermes) and [Goose on any model](https://usemagpie.ai/docs/goose). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Goose on any model

Goose, Block’s open-source agent, runs on the provider and model in its config. magpie adds itself to Goose as a custom provider, so Goose’s CLI and desktop app can run on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into Goose.

Goose keeps its settings in `~/.config/goose/config.yaml` (under `$XDG_CONFIG_HOME` if set; `%APPDATA%\Block\goose\config` on Windows). magpie writes a custom provider, `custom_providers/magpie.json` beside it, with the gateway’s address, a key of Goose’s own and magpie’s models, then makes it the provider Goose uses. The gateway translates each request for the model’s provider, tool calls and reasoning included. A Goose in WSL is set up the same way, reaching the gateway as the distro sees it.

## Connect Goose

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Pick a model on Goose’s row.** In the Agents tab, choose a model on Goose’s row. The picker also lists the models of providers Goose is set up with itself.
3. **Restart Goose.** Goose loads its custom providers as it starts: quit and reopen the desktop app, and open `goose` sessions again.

```
magpie goose deepseek/deepseek-v4-pro    # Goose on DeepSeek
magpie goose                             # what Goose runs on now
```

## Model and thinking effort

Each model magpie lists for Goose carries its context window, so Goose doesn’t have to guess it, and whether it takes a thinking level. The row also sets `GOOSE_THINKING_EFFORT`, the effort Goose asks of a model that thinks: off, low, medium, high or max.

```
magpie goose effort high
magpie goose effort default    # back to Goose's own
```

## What magpie writes

Goose has two layouts for the provider in use: `active_provider` with `providers.magpie.model`, and the older `GOOSE_PROVIDER` and `GOOSE_MODEL`. magpie writes the one your config already uses. Keys you added to magpie’s provider file yourself, such as `timeout_seconds`, `headers` or `toolshim`, stay when magpie rewrites the models.

## Switch back

Pick one of your own providers’ models on Goose’s row, take the row off magpie, or run `magpie goose default`. Once Goose no longer uses a model of magpie’s, magpie removes its provider file.

## FAQ

### Can Goose use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and pick a GPT model on Goose’s row. Goose sends its requests to magpie, which uses the subscription.

### Goose doesn’t show magpie’s models.

Goose reads custom providers only as it starts. Quit and reopen Goose, and start a new goose session.

### Does this work in the Goose desktop app?

Yes. The CLI and the desktop app read the same config, so both use the model on Goose’s row after a restart.

### Does it work with goose in WSL?

Yes. magpie sets up a Goose in a WSL distro too, with the gateway’s address as the distro reaches it.

More agents on the same models: [Models in OpenCode](https://usemagpie.ai/docs/opencode-models), [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Cline on any model](https://usemagpie.ai/docs/cline) and [Droid on any model](https://usemagpie.ai/docs/droid). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Droid on any model

Droid, Factory’s coding agent, can run on custom models of your own. magpie adds the models you have in magpie to Droid as custom models, so droid can run on DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into Droid.

Droid keeps its settings in `~/.factory/settings.json` (under `$FACTORY_HOME_OVERRIDE` when set). magpie adds one entry to its `customModels` per model in magpie, with the gateway’s address and a key of Droid’s own, and sets `sessionDefaultSettings.model`, the model sessions start on. Each model goes on the API its provider speaks, Anthropic Messages, OpenAI Responses or Chat Completions, so the gateway relays it as it is. A droid in WSL is set up the same way, reaching the gateway as the distro sees it.

## Connect Droid

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Pick a model on Droid’s row.** In the Agents tab, choose a model on Droid’s row.
3. **Restart droid.** Droid reads its settings as it starts: open sessions keep what they have, so start droid again.

```
magpie droid deepseek/deepseek-v4-pro    # Droid on DeepSeek
magpie droid                             # what Droid runs on now
```

## Models and thinking levels

magpie’s models are in droid’s `/model` picker too, under Custom models, so you can switch inside a session. A model that reasons is given a starting effort, so the picker offers its levels (off, low, medium and high); one that is a model Droid has built in takes Droid’s own levels and default. A model whose name Droid reads as OpenAI’s or Claude’s is written on the API Droid expects for it, so Droid doesn’t warn at each session start.

## Your own models

Custom models you added yourself stay as they were, ahead of magpie’s, so their ids don’t move. If you change a field of one of magpie’s entries in settings.json, such as its name or effort, magpie keeps your value; only the address and key are put back at each sync. The older `~/.factory/config.json` is left alone.

## Switch back

Take Droid’s row off magpie, or run `magpie droid default`. magpie removes its custom models and puts back the default model you had.

## FAQ

### Can Droid use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and pick a GPT model on Droid’s row. droid sends its requests to magpie, which uses the subscription.

### I changed the model but droid still uses the old one.

Droid reads its settings as it starts. Restart droid, or switch with /model inside the session.

### Why does /model show no thinking levels for a model?

That model doesn’t reason. For one that does, magpie gives it a starting effort, and droid then offers its levels.

### Will magpie touch my own BYOK models?

No. Your custom models stay as they were and in front of magpie’s.

More agents on the same models: [Models in OpenCode](https://usemagpie.ai/docs/opencode-models), [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Goose on any model](https://usemagpie.ai/docs/goose) and [Zed on any model](https://usemagpie.ai/docs/zed). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Zed on any model

Zed’s agent panel runs on the language model provider in its settings. magpie adds itself to Zed as an OpenAI-compatible provider, so Zed’s agent can run on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into Zed.

Zed keeps its settings in `~/.config/zed/settings.json` on macOS and Linux (under `$XDG_CONFIG_HOME` if set) and in `%APPDATA%\Zed` on Windows. magpie adds `language_models.openai_compatible.magpie`, with the gateway’s address and magpie’s models, and sets `agent.default_model` to the model you pick. Zed reads the change as it runs. The gateway translates each request for the model’s provider, tool calls and reasoning included.

## Connect Zed

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Pick a model on Zed’s row.** In the Agents tab, choose a model on Zed’s row.
3. **Open Zed’s agent panel.** The model is the panel’s default, and magpie’s models are in its model picker under magpie.

```
magpie zed deepseek/deepseek-v4-pro    # Zed's agent on DeepSeek
magpie zed                             # what Zed runs on now
```

## The API key

Zed keeps an OpenAI-compatible provider’s key in the system’s credential store, keyed by the provider’s address, not in settings.json. magpie saves a key of Zed’s own there for you: in the Keychain on macOS, in the Secret Service on Linux and in the Credential Manager on Windows. If Zed still asks for an API key, restart Zed.

## Models and thinking

Each model carries its context window and reply limit, so Zed knows when to compact, and whether it takes images. A model that thinks is written with `reasoning_effort` high, or the strongest level it has, so Zed shows its thinking switch and levels. A level you set on a model in settings.json yourself, `none` included, stays when magpie rewrites the list. If Zed reaches the gateway through a proxy of yours, magpie keeps that address.

## Switch back

Pick one of Zed’s own models on its row, take the row off magpie, or run `magpie zed default`. magpie puts back the default model, and the provider entry, you had before.

## FAQ

### Can Zed use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and pick a GPT model on Zed’s row. Zed sends its requests to magpie, which uses the subscription.

### Zed asks for an API key for magpie.

magpie saved the key in the system credential store. Restart Zed so it reads it.

### Why doesn’t Zed show a thinking switch for a model?

That model doesn’t think. For one that does, magpie sets reasoning_effort, and Zed then shows the switch.

### Does this change Zed’s edit predictions?

No. magpie sets the agent panel’s default model and adds a provider; edit predictions are left as they were.

More agents on the same models: [Models in OpenCode](https://usemagpie.ai/docs/opencode-models), [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Droid on any model](https://usemagpie.ai/docs/droid) and [Crush on any model](https://usemagpie.ai/docs/crush). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Crush on any model

Crush, Charm’s coding agent for the terminal, runs on the providers in its config. magpie adds itself to Crush as a provider, so Crush can run on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into Crush.

Crush’s config is `~/.config/crush/crush.json` (under `$XDG_CONFIG_HOME` if set; `%LOCALAPPDATA%\crush` on Windows). magpie adds `providers.magpie` there, with the gateway’s address, a key of Crush’s own and magpie’s models, and sets the models Crush runs on. The gateway translates each request for the model’s provider, tool calls and reasoning included. A Crush in WSL is set up the same way, reaching the gateway as the distro sees it.

## Connect Crush

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Pick a model on Crush’s row.** In the Agents tab, choose Crush’s large model, and its small one if you like.
3. **Start crush.** magpie’s models are in Crush’s own model picker too, under magpie.

```
magpie crush deepseek/deepseek-v4-pro     # Crush's large model on DeepSeek
magpie crush small deepseek/deepseek-v4-flash
magpie crush                              # what Crush runs on now
```

## Large, small and effort

Crush has two model slots: `large` for the work and `small` for lighter tasks. Each can be any model, magpie’s or one of your own providers’. The row also sets the large model’s `reasoning_effort`: low, medium or high.

```
magpie crush effort high
magpie crush effort default    # back to Crush's own
```

## The two files

Crush saves the models its own picker chooses to a data file, `~/.local/share/crush/crush.json` (under `$XDG_DATA_HOME` if set), which wins over the config. So magpie writes the picks there too, where Crush writes them, and its provider stays in the config. When magpie picks a model, settings Crush’s picker saved for the previous model, such as its `max_tokens`, are dropped, so a limit meant for one model doesn’t reach another. Keys you added to magpie’s provider yourself stay when magpie rewrites the models.

## Switch back

Pick one of your own providers’ models for both slots, take the row off magpie, or run `magpie crush default`. Once neither slot uses a model of magpie’s, magpie removes its provider from crush.json.

## FAQ

### Can Crush use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and pick a GPT model on Crush’s row. Crush sends its requests to magpie, which uses the subscription.

### Which wins, a pick in magpie or one in Crush?

The latest. Both are saved to Crush’s data file, so the last model picked, on Crush’s row or in Crush’s own picker, is the one Crush uses.

### What is Crush’s small model for?

Lighter tasks next to the main work. Set it on Crush’s row as small, to any model.

### Does it work with Crush in WSL?

Yes. magpie sets up a Crush in a WSL distro too, with the gateway’s address as the distro reaches it.

More agents on the same models: [Models in OpenCode](https://usemagpie.ai/docs/opencode-models), [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models), [Zed on any model](https://usemagpie.ai/docs/zed) and [Raycast on any model](https://usemagpie.ai/docs/raycast). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Raycast on any model

Raycast AI takes models of your own as custom providers (Raycast Pro, on Mac and Windows). magpie adds itself to Raycast as one, so Quick AI, AI Chat and AI Commands can run on any model you have in magpie: DeepSeek, Kimi, GLM, Qwen, an OpenAI key, or a ChatGPT or Copilot subscription, with no key pasted into Raycast.

Raycast reads its custom providers from `~/.config/raycast/ai/providers.yaml` in your user folder, on Mac and on Windows. magpie adds one entry to its `providers` list, with the id `magpie`: the gateway’s OpenAI-compatible address, a key of Raycast’s own and magpie’s models. Raycast watches the file, so the models show up without a restart. The gateway translates each request for the model’s provider, tool calls and reasoning included.

## Connect Raycast

1. **Add providers in magpie.** In the Providers tab, add an API key or sign in to a subscription.
2. **Put magpie on Raycast’s row.** In the Agents tab, set Raycast’s provider to magpie.
3. **Pick a model in Raycast.** Open Raycast’s model picker in Quick AI, AI Chat or an AI Command. magpie’s models are listed under magpie.

```
magpie raycast magpie     # magpie's models in Raycast AI's picker
magpie raycast            # what Raycast is set to now
```

On Windows, Raycast makes its config folder when you open Reveal Providers Config in its settings; magpie finds Raycast by that folder there.

## Which models it lists

The model is picked in Raycast, not in a file, so Raycast’s picker lists the models picked for Raycast on the Agents page. Hide one there and it leaves Raycast’s list. Each model comes with its name, context window and abilities, all spelled out, because Raycast assumes tools and vision off when they aren’t:

- **Tools.** on for every model, so AI Extensions work.
- **Vision.** on for a model that takes images.
- **Reasoning effort.** on for a model with effort levels.
- **Temperature.** off for a model that refuses it.

## Your providers.yaml

magpie writes only its own entry. Your other providers, the top-level `tools` block and your comments stay. So do keys you add to magpie’s entry yourself, such as `include_user_email`, `additional_parameters` or a model’s `description`. The file is written only when magpie’s entry would change.

## Switch back

Take Raycast’s row off magpie, or run `magpie raycast default`. magpie removes its entry, the `providers` list too if it was the only one, and the file if nothing else is left in it.

## FAQ

### Do I need Raycast Pro?

Yes. Custom providers are a Raycast Pro feature, so magpie’s models show in Raycast’s picker on a Pro plan.

### Can Raycast use my ChatGPT subscription?

Yes. Sign in to ChatGPT in magpie and put magpie on Raycast’s row, then pick a GPT model in Raycast. Raycast sends its requests to magpie, which uses the subscription.

### Do I need to restart Raycast?

No. Raycast watches providers.yaml and picks up magpie’s entry when it changes.

### Do AI Extensions work?

Yes. Every model is listed with tools on, and the gateway carries tool calls to each model’s provider.

More agents on the same models: [Models in OpenCode](https://usemagpie.ai/docs/opencode-models), [Models in Claude Code](https://usemagpie.ai/docs/claude-code-models) and [Crush on any model](https://usemagpie.ai/docs/crush). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

Source: https://usemagpie.ai/docs/cherry-studio

# Every model in Cherry Studio, through magpie

Cherry Studio is a desktop chat client that takes any OpenAI-compatible provider. magpie adds itself there as one provider, named magpie, so every model you have in magpie shows up in Cherry Studio: providers with an API key and the Claude, ChatGPT or Copilot subscriptions you signed in to.

magpie runs a gateway on your computer at `http://127.0.0.1:3425`. It speaks the OpenAI Chat Completions API and translates each request for the provider behind the model, Anthropic’s, Google’s or a subscription’s, with streaming, tool calls and reasoning. Cherry Studio sees one OpenAI-compatible provider at `http://127.0.0.1:3425/v1`.

Cherry Studio keeps its providers in its own database, and magpie never writes to it. It adds itself through Cherry Studio’s add-provider link instead, and you confirm it in Cherry Studio. This works in Cherry Studio 1.x and 2.x.

## Add magpie to Cherry Studio

1. **Add providers in magpie.** In the Providers tab, add an API key (DeepSeek, Kimi, GLM, Qwen, OpenRouter…) or sign in to a subscription.
2. **Open the Agents tab.** magpie lists Cherry Studio once it has run on this computer, including a data folder you moved elsewhere.
3. **Click Add magpie.** On Cherry Studio’s row, press Add magpie. Cherry Studio opens its model provider settings with magpie filled in: name magpie, type OpenAI, the gateway’s address and a key.
4. **Confirm it in Cherry Studio.** Nothing is added until you do.

If nothing opens, no app on this computer handles Cherry Studio’s links yet: open Cherry Studio once, or install it again, then click Add magpie again.

## Pick the models

Cherry Studio lists a provider’s models from `/v1/models`, so the magpie provider offers every model magpie has, named `provider/model` (for example `deepseek/deepseek-v4-pro`). Add the ones you want to the magpie provider in Cherry Studio, and choose them in a chat like any other model.

A provider you add in magpie later shows up the next time Cherry Studio fetches the list; there is nothing to change in Cherry Studio. Several accounts behind one model, rest periods after a 429 and failover work as they do for every agent.

## From a terminal

```
magpie cherrystudio add      # opens Cherry Studio to add magpie, confirm it there
```

`cherry-studio` works as the name too.

## How magpie knows it was added

Once Cherry Studio has a provider at the gateway’s address, the row shows magpie instead of the button. magpie reads Cherry Studio 2.x’s database for this, read-only. Cherry Studio 1.x keeps providers where magpie doesn’t read them, so there the button stays.

## Usage and keys

On a gateway that isn’t shared, the key in the link is Cherry Studio’s own, so its requests are counted as Cherry Studio’s in magpie’s Usage, apart from your coding agents. When the gateway is shared on your network with gateway keys, the link carries a key that works there.

## FAQ

### Do I need an API key to use Claude or ChatGPT in Cherry Studio?

No. Sign in to a Claude, ChatGPT or Copilot subscription in magpie, and its models appear in the magpie provider in Cherry Studio.

### Does magpie change Cherry Studio’s settings?

No. magpie opens Cherry Studio’s own add-provider dialog, and you confirm it. It only reads Cherry Studio’s database to show whether magpie was added.

### What address and type does the magpie provider use?

Type OpenAI, at http://127.0.0.1:3425/v1, or the gateway address you set in magpie.

### Why don’t I see a new model in Cherry Studio?

Cherry Studio shows models you added to the provider. Fetch the magpie provider’s model list again and add the new one.

### Cherry Studio isn’t in magpie’s Agents tab.

magpie lists it once Cherry Studio has run on this computer. Open Cherry Studio once, then look again.

Using a coding agent too? See [Subscriptions in any agent](https://usemagpie.ai/docs/subscriptions) and [Get started](https://usemagpie.ai/docs/start). Something fails? See [Fixing common errors](https://usemagpie.ai/docs/troubleshooting), or ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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

# Fixing common errors: 401, 429, 502, 504 and more

An error from magpie’s gateway says what went wrong in its own words. This page lists the common ones, what causes them, and the fix.

Every request is listed on magpie’s Routing page, with which provider and account it went to and how each try ended. Copy Report on a request copies what you need to ask for help.

## 401 and 403: a key or sign-in refused

**From the vendor.** The provider turned down the key or sign-in magpie sent. magpie sets that key or account aside and tries the next one, so you see the error only when none is left. A sign-in that has run out says so, for example “the ChatGPT sign-in has expired — sign in again”.

- **Fix:.** sign in again from ＋ Add provider (or `magpie accounts add <provider>`), or give the provider a new key.

**From magpie itself.** magpie answers 403 on its own in a few cases, before anything is sent:

| Error | Cause | Fix |
| --- | --- | --- |
| model disabled | You turned the model off in magpie. | Turn it on again on its provider. |
| model not allowed for the gateway key | The gateway key is held to some models. | `magpie gateway-key models <id>` lists or changes them. |
| magpie doesn’t answer the web page … | A web page called the gateway from a browser. | List it in Settings › Network and sharing › Web pages, and send a gateway key. |

## 429 and rest periods

A 429 means the provider is out of quota, out of credit or rate limiting you. magpie rests the key or account that was refused and sends the request to the next account, the next member of a routing group, or the provider’s Fallback. The provider’s row shows Resting · {why} · back at {time}.

| Refused for | Rests |
| --- | --- |
| Quota, with a reset time | Until the reset |
| Rate limit, with Retry-After | Until then |
| Credit | 30 minutes, then 2 hours, 8 hours, a day, 3 days and a week if it is refused again |
| A ChatGPT account out of credits | Until the reset its refusal names, else until its full window renews, else 5 hours |
| Any other failure | A minute, doubling on repeats up to 10 minutes (30 for a rate limit) |

- **Ask it again now..** Try now ends the rest: the next request asks it again. Refused again, it rests again.
- **Cap the rest..** `magpie provider rest-cap <id> 4h` sets the longest rest for a provider; `off` stops it resting for failures that say nothing of why.
- **A relay whose limits pass in a moment..** Untick Set it aside when out of quota or rate limited in the provider editor’s Advanced: a 429 then rests nothing, and the next request goes to it as usual.
- **Never all at once..** Add a second account or a fallback model, so a spent one never stops the agent. `magpie accounts` shows how much of each account’s allowance is used.

Rests are kept across restarts, so quitting magpie doesn’t bring a resting account back early.

## 502: the provider didn’t answer

A 502 means magpie couldn’t get an API reply from the provider. What follows the provider’s name says which case it is:

- **“didn’t answer: …”.** The connection failed: a name that doesn’t resolve, a refused connection, a proxy that is down. When this computer has no network at all, magpie notices and rests nobody.
- **“… not an API reply”.** The provider answered, but with a web page (a sign-in page, a Cloudflare challenge), nothing at all, or something that isn’t JSON. The base URL usually points at a web site instead of the API: check it against the vendor’s docs, and whether it should end in `/v1`.
- **OpenCode: “… which is no error, not an API reply”..** OpenCode’s gateway sometimes answers a 400 holding only the model’s name. The same request is answered some seconds later, so magpie reads it as a 502, asks again within the request’s patience or tries a group’s next member, and rests nobody. It is tied to requests carrying very large tool lists.

A 502, 503, 504, 529 or Cloudflare’s 520 to 524 counts as busy: magpie asks again or moves to a routing group’s next member before the agent sees it.

## 504: no answer in time

- **“<provider>: no first token in Ns”..** A routing group gives each member a time to start answering (First token). The member was slower, so the next was asked. Raise it on the group for a slow model.
- **“no member of the group answered within its Ns budget”..** Every member of the group was tried within the group’s time and none answered.
- **“magpie held this request for … without routing it to any provider”..** The request waited inside magpie and was stopped rather than left waiting. Send it again; if it comes back, Copy Report on that request on the Routing page and share it.

## Model not found (404)

The error reads *magpie knows no model “…”*, often with *did you mean …?* and the list of your provider ids.

- **Name it as magpie does..** Use `provider/model`, as `magpie models` lists it, a routing group’s id or name, or a bare model id.
- **“… is switched off in Magpie, so … is not served”..** The provider or routing group is off. Switch it on again on the Providers or Routing page.
- **No providers yet..** The error says “add a provider in magpie first”.

## The agent doesn’t show the model

- **Restart the agent..** Most agents read their config only when they start. magpie says so on the agent’s row after a change, for example “Codex builds its model list at start-up”. Codex’s app also keeps an app-server running; restart it as the notice says.
- **Check magpie serves it..** `magpie models` lists every model you can pick. A model you turned off, or one whose provider is switched off, isn’t listed.
- **Claude Code..** `/model` lists magpie’s models marked “via magpie”. If `CLAUDE_CODE_USE_BEDROCK` or `CLAUDE_CODE_USE_VERTEX` is set in your shell, Claude Code goes to that cloud instead of magpie; remove it from your shell profile.

## Port 3425 is in use

The gateway listens on `127.0.0.1:3425`. To move it, open Settings › Network and sharing › Gateway address. Only the port is set there, 1024 to 65535, and the agents magpie connected move with it.

| magpie says | Fix |
| --- | --- |
| Port … is in use by another program: pick another one | Pick a free port. |
| Another magpie serves the gateway at …: set its port there, or quit it first | Two copies of magpie are running. Quit one. |
| Port … is taken by another program, magpie web perhaps: magpie tries again every few seconds | Find what holds the port, or move the gateway to another. |
| MAGPIE_ADDR=… sets the gateway’s whole address, host:port: unset it to set the port here | Unset `MAGPIE_ADDR`, or change it. |

## Agents in WSL

On Windows, magpie looks in running WSL distros for agents such as Claude Code, Codex, OpenCode, Kimi Code and Qwen Code. Each one it finds gets a row of its own on the Agents page, and magpie sets it up as it does on Windows. It never starts a stopped distro.

- **The agent isn’t listed..** Start the distro, and check Settings › General › Detect agents in WSL is on.
- **It can’t reach magpie..** Under WSL’s default NAT networking, magpie also serves the gateway at Windows’ address on the WSL network, with a key of its own, and writes that address into the agent’s config. With mirrored networking the agent uses `127.0.0.1` as on Windows. Windows’ firewall still decides: WSL’s network counts as Public, so allow magpie there if the connection is blocked.
- **A change doesn’t show..** An agent in WSL reads its config at start-up: restart it there.

## From another computer on the network

By default the gateway answers only this computer. To use it from another: Settings › Network and sharing › Share on local network. The other computer sends a gateway key from the Gateway page’s Gateway keys.

- **“magpie isn’t shared on the local network”..** Turn sharing on, on the computer that runs magpie.
- **401..** The key is missing, off or expired. Send an enabled gateway key as `Authorization: Bearer <key>` or `x-api-key`.
- **403 for a model..** The key is held to some models: `magpie gateway-key models <id>`.

Don’t open the port to the internet; use a VPN between your computers. The full setup, another magpie included, is in [Remote magpie](https://usemagpie.ai/docs/remote).

## A subscription moved to a plugin isn’t served

Command Code, Cursor, Devin, Factory, Grok, Kiro, Xiaomi MiMo, Qoder, WorkBuddy, ZCode and Zed are no longer built into magpie. Each is served by a community plugin that does the same job. Accounts added before still need to move to the plugin, and nothing serves them until they do.

- **Fix:.** a line over the Providers list says “… built-in subscription is retired, and its accounts haven’t moved to its plugin yet”. Press Move to the plugin: magpie installs the plugin and checks each account. Moving keeps your accounts, models and agents as they are. magpie also moves them by itself, and installing the plugin from the Plugins page does too.

An error after the move comes from the plugin, which does the sign-in, models and requests.

## FAQ

### Why does magpie answer 502 when the provider is up?

The provider answered with something that isn’t an API reply, such as a web page or an empty body. The base URL usually points at the vendor’s web site instead of its API.

### Why does an account stay unused after a 429?

magpie rests it until the reset the vendor named, or for a while if none was named. The provider’s row says when it is back, and Try now ends the rest.

### What does “magpie knows no model” mean?

No provider serves a model by that name. Name it as provider/model, as magpie models lists it, or switch its provider on again.

### How do I change magpie’s port?

Settings › Network and sharing › Gateway address. The agents magpie connected move with it.

### Can an agent in WSL use magpie on Windows?

Yes. magpie finds agents in running WSL distros and sets each up with an address it can reach. Under NAT networking, Windows’ firewall must let WSL’s connection through.

### Can I use magpie from another computer?

Yes. Turn on Settings › Network and sharing › Share on local network, and send a gateway key from the other computer. Don’t open the port to the internet.

Still stuck? Copy the request’s report from the Routing page and ask on [Discord](https://discord.gg/vGSnD3ZKQF).

---

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 seven tabs: Instructions, MCP servers, Skills, Hooks, Subagents, RTK and billion-context. 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.

## billion-context

The billion-context tab turns on [billion-context](https://github.com/ranxianglei/billion-context)’s plugin per agent: it folds older turns of a long session into summaries the model can open again, so the session stays inside the model’s window. It is offered for Pi, omp, OpenCode, Claude Code, Hermes and Zed, whose requests still go through magpie with it on. magpie can install it for you (`npm install -g billion-context --prefix=~/.local`) and runs its own installer and remover; turning it off puts back what the install changed in the agent’s settings. An agent turned on here can’t also run billion-context-pi or opencode-acp.

For Claude Code, billion-context’s install turns Claude Code’s own auto-compaction off. magpie turns it back on, so a session billion-context doesn’t fold, such as one in the Claude desktop app’s Code tab, compacts instead of stopping at “Prompt is too long”. A `DISABLE_AUTO_COMPACT` you set yourself is left as it is.

Zed has no billion-context plugin, and Hermes’ plugin only catches HTTPS traffic, which magpie’s local address isn’t. Turned on, magpie runs `bili start` and points the agent’s magpie provider at `http://127.0.0.1:8787/bili/` followed by magpie’s address, the route billion-context documents for any client; for Hermes, in every profile that has magpie’s provider. Pick one of magpie’s models for the agent on the Agents page first, and restart it after turning it on or off.

The card shows how many tokens billion-context saved, in its own count: the net savings its dashboard shows, after the rebuilds a fold causes and the summaries’ cost, with how many folds and sessions, over every session it ran on this computer. magpie asks a running billion-context for it (`/__bili/overview`); when none runs, the card shows the last count it read and when. It shows nothing until billion-context has run for an agent.

## 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`). From a terminal, `magpie library project add .` adds the folder you are in, `magpie library project skill add . pdf docx` gives it skills, `magpie library project skill rm . pdf` takes one away, and `magpie library project skills .` lists them.

---

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, Shelley): 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.

### In front of a vendor magpie knows

When the provider’s `api` is the API of a vendor magpie has a preset for (`https://api.mistral.ai/v1`, `https://api.deepseek.com/v1`, `https://openrouter.ai/api/v1`, …), magpie shapes requests to your provider as it does for that vendor before they reach your `fetch`: Mistral’s thinking parts in place of `reasoning_content`, DeepSeek’s and xAI’s schema rules, OpenRouter’s free pool, and the rest. There is nothing to add; the base URL you already give is what it reads, even when your loader’s `baseURL` sends elsewhere. A base on no preset’s host, on `localhost` or on your network gets no vendor’s handling.

### 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
    family: "Gemini", pool: "Gemini", // a model's family, and the group sharing its allowance: the card shows a pool's own windows (no model, no family) in place of its models'
    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 › Models › Routing › 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.

Optional async `onSignIn(event, ctx)` hears of a subscription account that has to be signed in again: `event` is `{provider, providerName, account, state, endsAt?}`, `state` `signed-out`, or `ending` for a Claude sign-in within three days of its end. It is told once until the account works again, and carries no token. A hooks file may export only `onSignIn`.

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 30000 milliseconds; a value outside that range is clamped to the nearer bound. The chain sums budgets, clamped to 2–10 seconds, or takes the longest hook's own timeout when that is longer; host startup is bounded to 11 seconds, and startup plus RPC to the chain budget plus one second (at least 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.

With that part on, magpie also tells `usemagpie.ai`, on the same day, which of the plugins Discover lists are installed and on, so Discover can say how many use each one: `POST /api/plugins/report` with the same random id and the plugins’ npm names, or `github:owner/repo` for a repository tagged `magpie-plugin` (at most 50). A plugin from a folder, a private repository or a package Discover doesn’t list is never named. A like on a plugin’s page goes as `POST /api/plugins/like` with the id, the plugin and whether it is on, and only for a plugin installed here; the plugins you liked are kept in `plugin-likes.json`. The site counts the ids that reported a plugin in the last 7 days, drops a report after 30 days, and keeps your address only hashed, for an hour, to limit how often it is asked. Discover reads the counts from `GET /api/plugins/stats`, which carries no id. The code is [internal/stats/plugins.go](https://github.com/yetone/magpie/blob/main/internal/stats/plugins.go) and [site/pluginstats.js](https://github.com/yetone/magpie/blob/main/site/pluginstats.js).

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, models and plugins I use off, or `"noUsageStats": true` leaves out the `magpie uses` and `magpie partner` events, the counts in `magpie active` and the plugin report; 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 |
| `plugin-likes.json` | The plugins you liked in Discover |
| `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/plugins/stats`: Discover’s counts of how many use and like each plugin, at most once an hour. It carries no id; the plugin report and likes do, and go only with sharing what you use 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.
