- TypeScript 100%
Two bugs, both of which made the provider look broken.
1. Sending a message did nothing. pi always passes a thinking level (its
default is 'medium'), and reasoningEffortFor mapped that onto every model.
A model with no thinking mode rejects reasoning_effort outright — even as
'none' — with 'reasoning_effort is not enabled for this model', so every
non-reasoning model failed on the first message. Return undefined for
those and let the payload builder omit the field.
The accepted effort set is also per model family and is not in the
catalog: /v1/models only carries a boolean reasoning flag. Large 4 takes
low/medium/high, Medium 3.5 takes none/high, GLM 5.3 takes low/high/max,
GLM 5.2 takes all five. Sending an unlisted value is a 400, which is why
the thinking models failed too. The table is measured against the live API.
2. The model list was incomplete. It was fetched from
/v1/model-catalog?surface=vibe-code, which only advertises the four models
Mistral's own CLI ships with. Use the full /v1/models snapshot instead —
the same one the NixOS mistral provider is generated from — filtered to
models that actually answer: OCR models are served by /v1/ocr, not
/chat/completions ('Invalid model'), and Labs models need org enablement
('labs_not_enabled').
Verified: all 36 models accept every pi thinking level (off/low/medium/high)
against the live API, all stream through pi, and tool calling works across
codestral, ministral and large.
|
||
|---|---|---|
| adapter.ts | ||
| catalog.ts | ||
| index.ts | ||
| login.ts | ||
| open-external.ts | ||
| package.json | ||
| README.md | ||
| spend.ts | ||
| test-live.ts | ||
| wire.ts | ||
pi-mistral-vibe
The dsh-mistral-vibe plugin, ported to pi.
Mistral's own CLI does not speak the OpenAI-compatible protocol most gateways
use. It has its own backend: native chat completions with thinking chunks
(reasoning that replays as structured content on later turns) and
reasoning_effort — plus a browser sign-in against console.mistral.ai
that exchanges a PKCE challenge for an API key. This extension implements both
halves for pi.
Note on "vibe code" vs API usage. The browser sign-in returns an ordinary Mistral API key, and every request still goes to
api.mistral.aiand is billed as API usage. What this port gives you over pi's built-inmistralprovider is the wire format and catalog Mistral's own CLI uses: the full/v1/modelscatalog, native thinking-chunk replay, andprompt_cache_keyprefix caching. It does not route around API billing.
What it does
- Provider route — registers a
mistral-vibeprovider over the full model catalog (GET /v1/models), the same snapshot the NixOSmistralprovider is built from: 36 chat-capable models with their real context windows, vision support, and per-model reasoning efforts. OCR models (served by/v1/ocr, not/chat/completions) and Labs models (rejected until an org admin enables Labs) are excluded, so every listed model answers. - Native wire format —
POST {baseURL}/v1/chat/completionswithAuthorization: Bearer, assistant reasoning replayed asthinkingchunks,reasoning_effortforwarded from pi's thinking level, and a per-sessionprompt_cache_keyso Mistral reuses the shared prompt prefix across turns (cached tokens bill at a fraction of the input price). - Browser sign-in —
/mistral-loginruns the mistral-vibe flow:POST {console}/api/vibe/sign-in→ open the browser → poll → exchange. The returned key is stored as the provider's credential, exactly where/loginwould put it./loginalso works and accepts a pasted API key. - Spend estimate — each request's token usage is priced at published list
rates and surfaced as a status-bar field plus a
/mistral-spendbreakdown.
Install
Copy this directory into pi's user extensions directory:
cp -r pi-mistral-vibe ~/.pi/agent/extensions/
or load it in place while developing:
pi -e ./pi-mistral-vibe
pi uses jiti, so the TypeScript sources load without a build step, and it
resolves @earendil-works/pi-ai and @earendil-works/pi-coding-agent itself.
The standalone tests below run with plain node, which does not: point those
two packages at your pi install (a symlinked node_modules/@earendil-works/)
before running them.
Usage
/mistral-login— a browser window opens at the Mistral console; sign in there. The exchanged key is stored automatically. (Or/login→Mistral (Vibe)and paste a key.)/model→ pick amistral-vibe/*model, e.g.mistral-vibe/mistral-large-4-0./mistral-spendfor the running estimate,/mistral-modelsto list what the extension exposes.
Configuration
Optional, under a "mistral-vibe" key in ~/.pi/agent/settings.json:
{
"mistral-vibe": {
"baseURL": "https://api.mistral.ai",
"consoleURL": "https://console.mistral.ai",
"apiKeyEnv": "MISTRAL_API_KEY",
"pricing": {
"my-model-prefix": { "input": 1.36, "output": 4.18, "cachedInput": 0.14 }
}
}
}
| Key | Default | Meaning |
|---|---|---|
apiKeyEnv |
MISTRAL_API_KEY |
ambient environment variable used when no credential is stored |
baseURL |
https://api.mistral.ai |
chat-completions origin |
consoleURL |
https://console.mistral.ai |
browser sign-in origin |
pricing |
published Mistral rates | per-prefix USD per million tokens, merged over the defaults |
Set PI_MISTRAL_VIBE_DEBUG=1 to print catalog and usage diagnostics to stderr.
Spend
Mistral's API returns token counts only — no money — so the extension prices each request's usage locally at published list rates (USD per million tokens):
- Status bar —
≈$0.0123while amistral-vibemodel is active; hidden until there is usage, and an unpriced model shows its token count instead of a made-up amount. /mistral-spend— per-session and per-model token totals, amounts, and any unpriced tokens.
Cached input is billed at the model's cached rate where Mistral publishes one,
else at the input rate. This is an estimate, not a bill. Models without a
known price are counted but never given a made-up amount; add them under the
pricing setting.
Port notes
The dsh plugin and this port share the wire format, login flow, and spend model, but the harness APIs differ enough that the code is a rewrite rather than a translation:
| dsh | pi |
|---|---|
LlmAdapter subclass emitting harness stream chunks |
streamSimple on a Provider, emitting pi's AssistantMessageEvents |
ctx.llm.registerAdapter / registerConfigurableProviders |
pi.registerProvider(provider) |
credentials.resolve / credentials.set |
pi's ProviderAuth + modelRegistry |
ctx.commands.register → /mistral login |
pi.registerCommand → /mistral-login, /mistral-spend, /mistral-models |
tuiStatus.setField footer field |
ctx.ui.setStatus status-bar field |
z.object config schema |
a "mistral-vibe" settings block |
Details that matter and are easy to get wrong:
- Thinking chunks. Mistral's delta
contentis a chunk list, and it emits an emptythinkingchunk right before the first text chunk. Content blocks are created lazily, so that empty chunk never opens a block of its own. - Disjoint usage. Mistral folds cached reads into
prompt_tokens; pi wantsinputandcacheReaddisjoint, socached_tokensis subtracted frominputand reported ascacheRead. - Tool-call fragments. Ids and names can repeat, arrive split, or come as
Mistral's literal
"null"placeholder; they are stitched per index and the accumulated id/name is re-emitted with every delta. - System messages. Mistral takes one system slot per call, so the transcript is collapsed before translation.
reasoning_effortis omitted, not mapped, for models without thinking. A non-reasoning model rejects the field outright — even as"none":{"message":"reasoning_effort is not enabled for this model"}. pi always passes a thinking level (its default ismedium), so a naive map sendsmediumto every model and every non-thinking model fails on the first message.reasoningEffortForreturnsundefinedfor those, and the payload builder skips the field.- Accepted efforts are per model family and are not in the catalog.
/v1/modelsonly carries a booleanreasoningflag; the accepted values differ (Large 4: low/medium/high, Medium 3.5: none/high, GLM 5.3: low/high/max, GLM 5.2: all five). Sending an unlisted one is a 400, so the table is measured against the live API and lives incatalog.ts. - Unpriced ≠ free.
costForModelreturns zeros for unknown ids, which is what pi's own catalog does; the spend tracker reports those tokens as unpriced instead of pricing them at$0. - Storing the key must not touch the registration.
modelRegistry .registerProvider(id, { apiKey })looks like the obvious credential write, butModelRuntime.registerProviderdeletes the native provider entry when it runs, so the provider then composes with no models at all./mistral-logintherefore writesauth.jsondirectly; the registration is left alone and pi picks the key up at request time. auth.jsonis written by hand. pi'sAuthStorageis not reachable from an extension — the package'sexportsmap only exposes its root entrypoint, so@earendil-works/pi-coding-agent/core/auth-storagedoes not resolve. The command does the same read-modify-write itself: read the file, replace this one provider's entry, write it back atomically with mode0600. Entries for other providers are preserved verbatim, and a file that exists but does not parse is reported rather than overwritten, since that file holds every provider's credentials.
Tests
test-live.ts exercises the adapter against the real API: catalog fetch, plain
text, thinking chunks, tool calls, a multi-turn replay carrying reasoning and a
tool result, prompt-cache reuse, and abort handling.
MISTRAL_API_KEY=... node --experimental-strip-types --experimental-transform-types test-live.ts
Wire-format reference: mistralai/mistral-vibe
harness/runtimes/python/python/mistralai_vibe_local_harness/vibe/adapters/mistral.py
and vibe/setup/auth/http_browser_sign_in_gateway.py. Apache-2.0, like
upstream.