文档 · 供应商

Mistral 接入 Claude Code、Codex、Gemini CLI 和 OpenCode

Mistral 的模型只通过一种接口提供:api.mistral.ai 上的 OpenAI 风格 Chat Completions。把 Mistral 的 API Key 添加到 magpie 一次,Claude Code、Codex、Gemini CLI、OpenCode 以及你接入的其他工具,都能通过 magpie 的本地网关 127.0.0.1:3425 使用 Mistral,每个工具各用各的模型。说其他接口的工具,magpie 会在路上替它转换。

添加 Mistral

  1. 拿到 Key在 console.mistral.ai 创建。Le Chat 套餐的 Vibe Key 也加在同一个供应商里。
  2. 添加供应商在 magpie 的 供应商 页点 + 添加供应商,选 Mistral,粘贴 Key 并保存。magpie 会向 Mistral 查询这个 Key 能用哪些模型。
  3. 给工具选上在 Agent 页点工具那一行的模型,选一个 Mistral 模型,比如 mistral-large-4。
终端
magpie provider add mistral <key>
magpie provider test mistral

magpie 里的模型 id 是 供应商/模型,所以 Mistral 的模型写作 mistral/mistral-large-4:前面是供应商,后面是 Mistral 自己的 id。Key 保存在 magpie 的设置里,magpie 不会从 shell 里读取它。

已经在 OpenCode 或 Alma 里配好了 Mistral?magpie 从这些应用导入时,会把它变成 Mistral 供应商。有的应用一个 Key 存一条(“Mistral #0001”“Mistral #0002”……),导入后会合并成一个 Mistral 供应商,里面放着同样多的 Key,在每个工具的模型选择器里只出现一次。

接口地址

接口地址用途
Chat Completionshttps://api.mistral.ai/v1模型列表和所有工具的请求:OpenCode 的原样发送,Claude Code、Codex 和 Gemini CLI 的转换后发送
计费https://api.mistral.ai/v1/billing/budget、/v1/billing/subscriptionKey 当月的 Vibe 或 API 额度,以及所在的套餐

magpie 的 Mistral 供应商没有 Anthropic Messages 或 Responses 地址,所以说这两种接口的工具,请求都会转换成 Chat Completions,回复再转换回去,流式输出和工具调用都包括在内。

模型列表

magpie 从 Mistral 的 https://api.mistral.ai/v1/models 拉取列表,所以工具里看到的就是这个 Key 能用的模型。名称、推理档位和价格来自 models.dev 的 mistral 目录;Devstral、Codestral 和 Magistral 模型在每个选择器里都带着 Mistral 的图标。Mistral 也提供其他厂商的模型,比如 GLM 和 DeepSeek 的 deepseek-v4.1-flash-1017,它们走同一个 Key,下面的修正对它们同样有效。工具能看到哪些模型,可以在供应商的模型列表里挑,也可以在终端里设置:

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

在各个工具里用

终端
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

magpie 替你修正的请求

Mistral 的接口对收到的内容很严格,推理模型的思考也用它自己的格式返回。magpie 在路上把两边都调整好,原样转发的请求和转换过的请求都一样:

推理

Mistral 的 Chat Completions 接口不会替 magpie 联网搜索,所以在每个工具里,magpie 都给模型提供自己的搜索工具,由设置里指定的搜索服务回答;没指定时,由 magpie 自己挑一个。

Vibe、费用与用量

多个 Key 与故障切换

一个 Mistral 供应商可以放多个 Key:在它下面点 添加另一个密钥,也可以一次粘贴好几个。请求先走第一个开着的 Key,它用完或被限流时由下一个接替。

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

常见报错

常见问题

怎么在 Claude Code 里用 Mistral?

在 magpie 里添加 Mistral API Key(供应商、添加供应商、Mistral),然后在 Claude Code 那一行选一个 Mistral 模型,比如 mistral-large-4,或者运行 magpie claude mistral/mistral-large-4。Mistral 只提供 Chat Completions 接口,所以 magpie 把 Claude Code 的 Anthropic Messages 请求转换后发到 https://api.mistral.ai/v1,再把回复转换回来,思考内容也一样。

Codex 能用 Devstral 等 Mistral 模型吗?

能。你的 Mistral Key 列出的模型,包括 Devstral,Codex 都能用。Codex 说的是 OpenAI Responses 接口,Mistral 不提供,所以 magpie 把每个请求转换成 Chat Completions,把 apply_patch 这类 Codex 自定义工具当作函数交给模型,再把调用按 Codex 能执行的方式还回去。

怎么在 OpenCode 里用 Codestral 等 Mistral 模型?

在 magpie 里选好模型,或者运行 magpie opencode mistral/mistral-large-4;只要你的 Key 列出了 Codestral 或 Devstral,用法完全一样。OpenCode 说的是 Chat Completions,请求原样发给 Mistral,只在路上修掉 Mistral 会拒绝的内容:OpenCode 的 store 字段,以及放在 reasoning_content 里回传的上一轮思考。

Gemini CLI 能用 Mistral 吗?

能。Gemini CLI 说的是 Google 的 Gemini 接口,magpie 会把它的请求转换成 Mistral 的 Chat Completions,再把回复转换回来,流式输出和工具调用都包括在内。运行 magpie gemini model mistral/mistral-large-4 即可。

Mistral 为什么回 422 extra_forbidden?

Mistral 会拒绝它不认识的任何字段。magpie 会把上一轮的思考改成 Mistral 接受的思考片段,去掉部分工具附带的 Ollama 参数;遇到 Mistral 点名的可选字段(比如 OpenCode 的 store),就去掉它重新请求,之后也不再发送。

magpie 能显示 Le Chat 套餐的 Vibe 额度吗?

能。Le Chat 套餐(Pro、Student 或 Team)的 Vibe Key 会显示本月 Vibe 额度用了多少、按 Mistral 计费的币种计、什么时候重置,以及套餐名称。在控制台创建的 Studio Key 则显示组织的 API 额度,名为 “API · Month”。

按供应商:DeepSeek · Kimi 与 Kimi Code · GLM 编程套餐 · 通义千问 · MiniMax · Gemini · Grok · OpenRouter · GitHub Copilot · Ollama

各个工具的指南:Claude Code 接入其他模型、Codex 接入其他模型、Gemini CLI 接入其他模型、OpenCode 接入其他模型。遇到问题可以在 Discord 提问。