SlouchyQuill on Discord asked for a Tavily key pool after dsh-tavily-pool: several keys, each key's quota shown, keys rotated. Before this, the comma-separated keys (#1477) always started from the key that last answered, so one key took every search until it was refused, a refused key kept no rest of its own, and nothing showed what a key had left. What changed: - Turns (internal/gateway/search_keys.go). Searches take turns over the keys by default (round robin, a counter per vendor). pick=order (CLI) or In order (Settings) always starts from the first key; the pick is saved in SearchAPI.Pick. - Rests. A refused key rests: 401/403 for 10m ("turned away"), 402 for 1h ("out of credit"), 429 for its Retry-After held to 30s-10m (1m without one). 432/433 count as out of credit from Tavily only; from any other vendor they rest as a rate limit. A resting key is asked after the others, soonest back first, so failover is kept, and it wakes when it answers. Rests are keyed by a hash of the key. - Quota (internal/gateway/search_quota.go). Each Tavily key's quota is read from GET /usage with that key. The fixture is the documented reply from docs.tavily.com. The key's own limit is used when it has one; otherwise its plan's plan_limit/plan_usage, which the account's keys share. A failed read, or a reply missing those fields, says unknown and why, never 0. A read is kept 2m unless asked fresh. A key found used up with no pay-as-you-go credit rests 1h; a later read with credit wakes it. - Keys never appear in full. The vendor's error has the key masked (tvly-…abcd), and errors name "key N (tvly-…abcd)". - GUI. Settings › Models › Web search adds a "Keys of <API>" row under an API with several keys or with Tavily's: In turn / In order, each key masked with what it has used and why it is asked last, and Check again. There is an API for it (POST /api/settings/search-quota), and 13 strings in zh, zh-TW, ja and de. - CLI. `magpie search` lists the pick and each Tavily key's quota, read fresh; `magpie search add … pick=turns|order`. - Docs. gateway-routing.md has a new section "A search API's keys"; both READMEs have a line on web search. What was run: - go test -tags nogui ./internal/gateway ./internal/provider ./internal/cli ./internal/gui: ok. After the last rebase, provider and cli again, and gateway -race -run Search. - New tests: TestReadTavilyUsage, TestSearchKeysTakeTurnsRoundRobin, TestSearchKeyRefusedRests, TestSearchRestFor, TestSearchQuotas and TestSearchKeyNeverInFull. Each guarantee was broken by hand and its tests went red: - turns pinned to the first key: RoundRobin and RefusedRests; - rests ignored: TestSearchAPIKeysTakeTurns, RefusedRests and TestSearchQuotas; - key masking removed: NeverInFull; - a failed read reported as known: TestSearchQuotas. - gofmt -l; go vet -tags nogui for darwin, linux and windows on the four packages. - GUI: search-keys.test.cjs covers en, zh, zh-TW, ja and de × Chromium and WebKit × 1100 and 420px: 20/20. Without the new .search-keys .val wrap rule, de at 420px fails ("Erneut prüfen" went past the window's edge). - search-api, search-first, search-instead, search-mcp, searcher-pick, settings-search, provider-search, gui-de, gui-ja and i18n-keys: 56/56 in each engine. - Full suite in Chromium (concurrency 6, load ~40): 4498/4504. The files that failed (gateway-key-groups, rest-try-now, routing-wb-restricted, text-size, usage-sum-whole) were rerun alone. All pass except usage-sum-whole, which fails now and then on an origin/main worktree too under the same load (#1864, #2023; rest-try-now and routing-wb-restricted are #1905). None of them touch search. - Real Tavily API with two invalid keys: /search returns 401 {"detail":{"error":"Unauthorized: missing or invalid API key."}}, which counts as a refusal. Both keys rest 10m as turned away, the error names them only masked, and both quotas read "unknown · 401". Checked through a test and through the nogui CLI binary in a sandbox HOME. Not tried: a valid key's /usage against the real API. No Tavily key was at hand, so the quota parsing is checked against the documented bytes only.
18 KiB
magpie
所有 Agent 的模型,一处搞定。
Claude Code 跑 Kimi,Codex 跑 DeepSeek,Gemini CLI 跑 GLM,OpenCode 用你的 ChatGPT 订阅。
在菜单栏一点就能切换。所有 Agent 共用一个本地网关,
额度用完时,它会悄悄切到下一个账号。
下载 · 文档 · 完整参考(英文) · 插件 · Discord · English · 简体中文
magpie 适合你吗?
每个 Agent 都把模型写在自己的配置文件里,格式各不相同,key 和 base URL 各管各的。花钱买的订阅只能在一个 Agent 里用。magpie 把这些收进一个应用和一个本地网关:
- 任意 Agent 用任意模型,在一张表里选。magpie 只改 Agent 配置里该改的那一个键。
- 一个 provider 处处能用:API key、本地模型,或者你登录着的 Claude、ChatGPT、Copilot、Gemini、Grok 订阅。
- 额度用完也不断:路由组自动切到下一个账号或模型,Agent 看不到报错。
如果你用不止一个 Agent、不止一个 provider 或不止一个账号,它就适合你。如果你只用一个 Agent、只用它自家的订阅,而且够用,那就不需要 magpie。
支持 macOS、Windows 和 Linux(菜单栏应用、窗口、TUI、Web 界面和 CLI),也能跑在 Docker 和 Termux 上。
快速开始
1 · 安装。从 usemagpie.ai 下载应用,或者运行:
curl -fsSL https://usemagpie.ai/install.sh | sh
Mac 版已签名并公证,每个版本都会自动更新。网络受限时可用 --proxy 或 --mirror。也可以 go install github.com/yetone/magpie@latest,或者用 Docker 镜像。
2 · 添加 provider。打开 magpie,进入 Providers → 添加 provider。选一个预设、粘贴 key,或者登录一个订阅。
3 · 选模型。在 Agents 页给每个 Agent 选一个模型。开一个新会话就用上了。
也可以全程在终端里操作:
magpie provider add deepseek sk-… # 预设只需要 key
magpie claude deepseek/deepseek-v4-pro # Claude Code 用 DeepSeek
magpie codex moonshot/kimi-k2.5 # Codex 用 Kimi
magpie group add "Opus anywhere" models=claude/claude-opus-5-5,copilot/claude-opus-5.5 routing=smart
magpie claude group/opus-anywhere # 在多个订阅间自动切换
magpie save work && magpie use work # 方案
magpie quota # 每个套餐还剩多少
magpie tui # 全部功能,在终端里
magpie 通过读取智能体的登录信息(Claude Code 和 Codex 的文件、钥匙串)找到它们登录的订阅。不想让它读取,可以在 设置 → 隐私 里关闭「订阅账号」,或运行 magpie accounts discovery off(on 重新开启)。MAGPIE_NO_ACCOUNTS=1 只对这一次运行关闭,不改动保存的设置。API Key 服务商不受影响。
支持的 Agent
|
Claude Code · Claude Desktop · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Ante · AstrBot |
magpie 只显示你电脑上装了的 Agent;部分 Agent 的配置说明见参考文档(英文)。其他任何能填 base URL 的工具也都能用这个网关:
export OPENAI_BASE_URL=http://127.0.0.1:3425/v1 OPENAI_API_KEY=magpie
export ANTHROPIC_BASE_URL=http://127.0.0.1:3425 ANTHROPIC_API_KEY=magpie
export GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:3425 GEMINI_API_KEY=magpie
整体结构
127.0.0.1:3425 上的网关同时支持 OpenAI Chat、OpenAI Responses、Anthropic Messages 和 Gemini,并在它们之间互相转换,流式输出、工具调用和推理都支持。
功能
任意模型,任意 Agent
点一下模型,弹出可搜索的列表:你添加的每个 provider 的每个模型,格式是 provider/model。选中后 magpie 原子地改写 Agent 的配置,注释、顺序和格式原样保留。方案(Profile)把所有 Agent 的配置存成一个名字,比如「省钱」「专注」,一键全部切回去。每个 Agent 还可以有自己的常用模型短名单,方案也会一并保存。
|
|
Provider
选一个预设,粘贴 key。模型列表直接来自厂商,名称和推理档位从 models.dev 补全,今天早上刚发布的模型,下次刷新就出现在你的选择器里。
预设包括 Anthropic · OpenAI · Google Gemini · DeepSeek · Kimi · 智谱 GLM · MiniMax · 阶跃星辰 · 通义千问 · 百度千帆 · 腾讯云 · 华为云 MaaS · 火山方舟 · Mistral · Groq · Nous Portal · xAI · OpenRouter · Together · Fireworks · 硅基流动 · NVIDIA NIM · 魔搭 · Ollama · LM Studio …… 以及任何兼容 OpenAI 或 Anthropic 的地址。
导入能读取你在 CC Switch、Claude Code、Codex 和 Alma 里配置的 provider。「添加到 magpie」链接让 provider 网站一键把配置交给 magpie。每个 key 和每个账号都可以走自己的代理。
订阅
你登录过的 Agent 背后就是一个带模型的订阅,magpie 把它当成 provider 给其他所有 Agent 用。每个订阅可以加多个账号,magpie 会在它们之间自动切换。
- Claude:驱动本机真正的
claude程序,通过 MCP 桥接你的 Agent 的工具 - Codex / ChatGPT:你的 ChatGPT 订阅里的模型,给所有其他 Agent 用
- GitHub Copilot、Gemini(Code Assist)、Antigravity、Grok(SuperGrok) 等等
- 任何 OpenCode 登录插件或 pi 包,直接从 npm 安装
每日预热会在你选定的时间,或者上一个窗口刚重置时,启动每个 Claude 和 ChatGPT 账号的 5 小时窗口。
路由组
路由组是 Agent 当作一个模型来选的一组模型,比如 group/daily-coding。网关会把请求分摊到每个成员的 key 和账号上:
| 模式 | 作用 |
|---|---|
smart |
在还有额度的订阅里,优先用最快重置的那个,重置时浪费得最少 |
order |
先用第一个模型,它答不了再用下一个 |
rotate |
每一轮换下一个成员 |
usage |
优先用用得最少的成员 |
pace |
优先用距离重置前每小时剩余周额度最多的账号 |
只要厂商的提示词缓存还值得保留,对话就留在回答它的那个账号上。路由组可以嵌套。意图路由由你选的一个小模型读每一轮新消息,写测试交给强模型,简单问题交给便宜的模型。路由页实时展示每一次决策。
|
|
插件
magpie plugin add opencode-gemini-auth # npm 上的 OpenCode 插件
magpie plugin add pi-antigravity # pi 包,同样的方式
magpie plugin login google-plugin # 在 magpie 里走它自己的登录流程
插件运行在 Bun 上,第一次需要时自动下载。插件负责登录、列出模型和发送请求,Agent 像用其他 provider 一样用它的模型。去 magpie-community/plugins 逛逛,或者自己写一个。
插件还可以是网关中间件:一段 JavaScript,能看到每个 Agent 发出和收到的内容。onRequest 可以改写或拒绝请求,onEvent 看到每个流式事件,onResponse 看到完整回复。钩子抛错或超时,请求原样放行。
// alias.middleware.js — magpie plugin add ./alias.middleware.js
export function onRequest(body, ctx) {
if (body.model === "fast") return { ...body, model: "deepseek/deepseek-chat" };
}
现成的中间件,大多对应 New API 给渠道做的事,JSON 格式也一样
| 包 | 作用 |
|---|---|
param-override |
New API 的 param_override:按条件设置、删除、移动或改写请求字段,或拒绝请求 |
model-map |
New API 的 model_mapping:把模型换个名字发出去,回复里仍是原来请求的名字 |
system-prompt |
给所有请求,或某些 Agent、某些模型的请求加上你的系统提示词 |
word-guard |
New API 的敏感词过滤:在用户发送的内容和回复里拒绝或屏蔽敏感词 |
think-tags |
去掉回复里的 <think>…</think>,或把 reasoning_content 放进回复 |
magpie plugin add @magpie-community/middleware-model-map
magpie plugin options model-map '{"mapping": {"fast": "deepseek/deepseek-chat"}}'
在「插件 › 发现 › 网关中间件」里可以找到它们。详见网关中间件。
用量和花费
| token 和花费 | token、缓存读写、推理和调用次数,按官方价格算花费,美元或人民币;任何模型都能自定义价格 |
| 额度 | 每个 key、套餐和账号的余额和额度窗口(magpie quota),窗口还剩很多就要重置时提醒你 |
| 会话 | 每个 Agent 对话的花费和标题,一键在终端里重新打开 |
| 上下文 | 每个请求的上下文窗口用了多满、多少来自缓存、被什么占着 |
| 账单 | 按账号、按上游 key 统计,还能 OTLP 导出到你自己的可观测性系统 |
共享
| 局域网 | 打开「在局域网共享」,给每个客户端一个命名的网关 key,各自设每天、每周或每月的 token 和花费上限 |
| 远程 magpie | 笔记本用台式机上那个 magpie 的 provider、账号和路由组,同时照样配置自己的 Agent |
| Docker | 在服务器或 NAS 上跑 ghcr.io/yetone/magpie,用 Web 界面管理 |
| 同步 | 备份到文件,或者通过 WebDAV(坚果云、Nextcloud……)或 S3 在多台机器间同步 |
还有
- 资料库:指令、MCP 服务器和技能只写一次,magpie 按每个 Agent 的格式写进它的文件,删除时只删自己写的部分。
- 任何模型都能联网搜索:不能搜索的模型由 magpie 代为搜索,用能搜索的 provider 或搜索 API(Tavily、Brave、Exa、Firecrawl、You.com、SearXNG)。一个 API 可以填多个密钥:搜索默认轮流使用(
pick=order则按顺序),最近被拒的密钥最后才用;Tavily 的每个密钥用了多少额度,在设置页和magpie search里都能看到。 - 图片和视频:通过 MCP 给任何 Agent 一个生图工具,用你选的模型;有 Grok 订阅还能生成视频。
- Agent 保持最新:Agents 页显示每个 CLI 的版本,按当初的安装方式更新,没装的也给出安装命令。
- WSL:在 Windows 上,WSL 发行版里的 Agent 一样能配置,会话也一样统计。
- 保持唤醒、浅色和深色,在 Omarchy 上跟随你的主题。
文档
| 快速上手 | 入门导览 |
| 完整参考(英文) | 每个 Agent、provider 选项、网关接口、CLI 命令和文件 |
| 插件 | 使用插件和编写插件 |
| 意图路由 | 按每轮对话的内容选择模型 |
| 导入链接 | 给 provider 网站用的「添加到 magpie」按钮 |
| 远程 magpie | 在其他电脑上用同一个 magpie 的 provider 和路由组 |
| Docker | 在服务器或 NAS 上运行 magpie |
隐私
你的提示词、回复、密钥和账号只发给你用的供应商。正式版 magpie 每天告诉我们一次它在用:一个随机 ID、版本和系统,以及用了哪些 agent、供应商和模型,只用 magpie 自己的 ID(你自己添加的供应商只记作 custom),以及添加供应商页里排在最前的合作伙伴每天被展示、打开和添加的次数(只有次数)。不发送名称、URL、账号、密钥、提示词和用量。可以在 设置 → 隐私 里关掉一部分或全部,也可以设 DO_NOT_TRACK=1。合作伙伴的官网和获取 Key 链接经 usemagpie.ai/go/… 跳转并计一次点击,usemagpie.ai 也统计合作伙伴列表的拉取次数;这是服务器本身看到的,不受设置影响,不记录 ID 和 IP。插件、导入链接和库里的图标经 usemagpie.ai/api/icon 获取,图标所在的服务器只看到 Cloudflare 的地址,看不到你的 IP;这台服务器只转发图片,不计数也不记录。隐私页列出了 magpie 自己发出的所有内容,附示例和每个开关;规则见参考文档。
社区
有问题、有想法,或者某个模型就是不出现?请到 Discord 反馈。
本仓库不接受 Pull Request,只有维护者能提交。想要修复或新功能,请在 Discord 里描述清楚,我们来实现。
如果 magpie 帮你少改了一次配置文件,点个 ⭐ 能让更多人发现它。



