A pi extension that adds a mistral provider that routes the request through their api to register the usage as "vibe code" usage and no api usage
  • TypeScript 100%
Find a file
polowiper de65c84afc fix: full model catalog, and stop sending reasoning_effort to models without thinking
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.
2026-11-05 23:33:39 +01:00
adapter.ts fix: full model catalog, and stop sending reasoning_effort to models without thinking 2026-11-05 23:33:39 +01:00
catalog.ts fix: full model catalog, and stop sending reasoning_effort to models without thinking 2026-11-05 23:33:39 +01:00
index.ts fix: full model catalog, and stop sending reasoning_effort to models without thinking 2026-11-05 23:33:39 +01:00
login.ts Initial commit 2026-11-05 22:59:14 +01:00
open-external.ts Initial commit 2026-11-05 22:59:14 +01:00
package.json Initial commit 2026-11-05 22:59:14 +01:00
README.md fix: full model catalog, and stop sending reasoning_effort to models without thinking 2026-11-05 23:33:39 +01:00
spend.ts Initial commit 2026-11-05 22:59:14 +01:00
test-live.ts Initial commit 2026-11-05 22:59:14 +01:00
wire.ts Initial commit 2026-11-05 22:59:14 +01:00

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.ai and is billed as API usage. What this port gives you over pi's built-in mistral provider is the wire format and catalog Mistral's own CLI uses: the full /v1/models catalog, native thinking-chunk replay, and prompt_cache_key prefix caching. It does not route around API billing.

What it does

  • Provider route — registers a mistral-vibe provider over the full model catalog (GET /v1/models), the same snapshot the NixOS mistral provider 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/completions with Authorization: Bearer, assistant reasoning replayed as thinking chunks, reasoning_effort forwarded from pi's thinking level, and a per-session prompt_cache_key so Mistral reuses the shared prompt prefix across turns (cached tokens bill at a fraction of the input price).
  • Browser sign-in — /mistral-login runs 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 /login would put it. /login also 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-spend breakdown.

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

  1. /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.)
  2. /model → pick a mistral-vibe/* model, e.g. mistral-vibe/mistral-large-4-0.
  3. /mistral-spend for the running estimate, /mistral-models to 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.0123 while a mistral-vibe model 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 content is a chunk list, and it emits an empty thinking chunk 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 wants input and cacheRead disjoint, so cached_tokens is subtracted from input and reported as cacheRead.
  • 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_effort is 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 is medium), so a naive map sends medium to every model and every non-thinking model fails on the first message. reasoningEffortFor returns undefined for those, and the payload builder skips the field.
  • Accepted efforts are per model family and are not in the catalog. /v1/models only carries a boolean reasoning flag; 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 in catalog.ts.
  • Unpriced ≠ free. costForModel returns 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, but ModelRuntime.registerProvider deletes the native provider entry when it runs, so the provider then composes with no models at all. /mistral-login therefore writes auth.json directly; the registration is left alone and pi picks the key up at request time.
  • auth.json is written by hand. pi's AuthStorage is not reachable from an extension — the package's exports map only exposes its root entrypoint, so @earendil-works/pi-coding-agent/core/auth-storage does 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 mode 0600. 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.