Docs · Provider
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
- Get a keyMake one on console.mistral.ai. A Le Chat plan’s Vibe key goes in the same provider.
- Add the providerIn magpie’s Providers tab, press + Add provider, pick Mistral, paste the key and save. magpie asks Mistral which models the key can use.
- Pick it for an agentIn 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.
- 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. - Gemini CLI speaks Google’s Gemini API. magpie translates each request to Chat Completions and the reply back. Models in Gemini CLI.
- OpenCode speaks Chat Completions, so its requests go to Mistral as they are, with the fixes below. Models in OpenCode.
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 toreasoning_contentand 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 422extra_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
storeand Kimi Code’s thinking switch got 422extra_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(itsnum_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
noneamong its levels, magpie asks for none. - Thinking across turns. Each agent sees a reasoning model’s thinking in its own shape:
reasoning_contentfor 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-capstops 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.
fallbacknames 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_contentand 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 mistralsends a tiny request through each endpoint, or to each model you name. Add--as codexor--as claude-codeto 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 · Kimi and Kimi Code · GLM Coding Plan · Qwen · MiniMax · Gemini · Grok · OpenRouter · GitHub Copilot · Ollama
Every agent: Models in Claude Code, Models in Codex, Models in Gemini CLI, Models in OpenCode. Ask on Discord if you get stuck.