Connect Mistral to CLIProxyAPI (CPA). Clients keep using CPA's address and key.
- Accepts OpenAI Chat Completions, Responses, Claude, and Gemini requests and converts them to Mistral chat completions (the
/openai/v1compatibility facade by default). - Rewrites Mistral thinking blocks into the field each protocol expects, so clients do not have to parse arrays inside
delta.content. - Manages multiple Mistral API keys. Each key can have a priority, be disabled, or be tested on its own.
- Fails over to the next credential when the upstream rejects the current one, and keeps recently failed keys out of the first attempt.
- Fetches the upstream model list and creates mappings from selected models, so model IDs do not have to be typed by hand.
- Sends a small request for a single mapping to check the key, model ID, and reasoning setting together.
- Records request logs and statistics: first-byte time, total time, output speed, cache hits, and failover attempts.
- Maintains a stable
prompt_cache_keyand mirrors it in thex-affinityheader so Mistral's load balancer keeps one conversation on the cache node that already holds its prefix. The key comes from the client when present, otherwise from the conversation root (instructions plus first user message), so turns and compaction replays of the same history keep hitting the same node. - Cancels streaming requests that stop producing bytes for too long.
- Optionally ignores CPA's global proxy when the host transport cannot reach the upstream directly.
- Reads the included monthly allowance per credential from Mistral's billing API (
/billing/subscriptionand/billing/budget), shows API and Vibe Code usage in the console, routes around a credential when its API allowance is spent, and brings it back automatically at the reset date. - Runs the console in English or Chinese, follows the CPA language on first load, and keeps a manual language switch.
The plugin id is mistral. It needs a CPA build with dynamic library plugins and JSON ABI v1.
- Install Mistral from the CPA plugin marketplace, or download the archive for your platform from Releases.
- Put the library in CPA's
plugins/<os>/<arch>/directory and keep the archive's filename:- Linux amd64 / arm64:
mistral.so - macOS arm64 / amd64:
mistral.dylib - Windows amd64:
mistral.dll
- Linux amd64 / arm64:
- Restart CPA. Replacing the file without a restart leaves the old library loaded.
- Add
auths/mistral.json:
{"type":"mistral"}Without this auth file, routing returns auth_not_found. The file does not need an API key. The plugin manages keys itself.
Open the Mistral menu in the CPA management page, or go to:
http://<cpa>/v0/resource/plugins/mistral/console
The console tries to reuse the CPA management session. It reads cli-proxy-auth from the browser when CPA is opened directly, and also reads the same-origin parent page when opened from the plugin menu. If neither source is available, the page asks you to open it from the Mistral menu. It does not prompt for a key.
First-run order:
- Add a Mistral API key under Credentials, then click Check to confirm
GET /modelssucceeds. If you do not have a key, click Create Vibe API key to openhttps://chat.mistral.ai/code/extensions. - Under Models, choose a credential, click Fetch upstream models, select what you need, and add them.
- Point your client at CPA's address and CPA client key. Use the client-side model name from the mapping table.
Saving in the console writes the whole plugins.configs.mistral block back to CPA's config file. The old format with one api-key and a models list still loads. The first console save rewrites it into the structure below.
plugins:
configs:
mistral:
enabled: true
priority: 100
base-url: "https://api.mistral.ai/v1"
console-url: "https://console.mistral.ai"
endpoint: "auto"
log-retention: 200
stream-idle-seconds: 0
failover: true
ignore-proxy: false
cooldown-seconds: 60
quota-monitoring: true
quota-refresh-seconds: 60
vibe-billing: true
credentials:
- id: "primary"
label: "Primary"
api-key: "mstrl_..."
disabled: false
priority: 10
- id: "backup"
label: "Backup"
api-key: "mstrl_..."
disabled: false
priority: 5
models:
- id: "deepseek-v4.1-flash"
upstream-id: "deepseek-v4-1-flash-1017"
reasoning: ""
- id: "glm-5.3"
upstream-id: "zai-glm-5-3"
reasoning: "max"| Field | Meaning |
|---|---|
base-url |
Mistral API base URL, including /v1. Defaults to https://api.mistral.ai/v1. Model listing and billing always use this address. |
endpoint |
auto (default), openai, or native. auto uses https://api.mistral.ai/openai/v1/chat/completions on the official host and keeps the native /chat/completions path on a custom host; openai forces the compatibility facade; native forces the old route. The facade accepts store=false, developer, reasoning_content, seed, user, metadata, max_completion_tokens and similar fields the native route rejects with 422, and returns thinking as reasoning_content directly. |
console-url |
Console origin used to show the key scope and plan from /api/vibe/whoami. Defaults to https://console.mistral.ai. Empty hides the scope; auto-pause only uses api_budget and is unaffected. |
log-retention |
Number of request log entries to keep, from 10 to 5000. |
stream-idle-seconds |
Stream idle cutoff. 0 disables it. Above 0, an upstream stream is cancelled after this many seconds without model output, and the client is told it timed out. |
failover |
When enabled, a failed upstream attempt moves to the next credential by priority. When disabled, only the first credential in the current order is used. |
ignore-proxy |
When enabled, the plugin connects to Mistral directly and bypasses CPA's global proxy. Off by default. |
cooldown-seconds |
Base cooldown after a failure, from 0 to 3600. 0 disables cool BFFA down, but failover still moves through the list. |
quota-monitoring |
When enabled (default), the plugin reads the plan allowance per credential and routes around a key whose allowance is spent. |
quota-refresh-seconds |
Background allowance check interval, from 10 to 3600. Defaults to 60. |
vibe-billing |
On by default. Every request gets metadata.call_type, which makes the gateway book the call against the Vibe Code allowance instead of the API one, and auto-pause follows vibe_budget. Mistral documents third-party tools as API usage, so this works around that rule: experimental, and the account risk is the operator's. Set false to bill the API allowance. |
credentials[].priority |
Higher numbers are tried first. |
credentials[].disabled |
When true, the credential is not scheduled. |
models[].id |
Model name exposed to clients. |
models[].upstream-id |
Model ID sent to Mistral. |
models[].reasoning |
Empty passes through the client's reasoning_effort. A value such as low, medium, high, xhigh, or max forces an override. |
If a gateway only implements the native /v1 route, set endpoint to native; the same applies if /openai/v1 answers 404 on the official host.
With the mapping deepseek-v4.1-flash → deepseek-v4-1-flash-1017, send the client-side name as model:
{
"model": "deepseek-v4.1-flash",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}The plugin replaces model with the upstream ID and keeps reasoning_effort. The default endpoint: auto uses the OpenAI-compatible facade on the official host, so store=false, developer, reasoning_content and similar fields pass through. Only native removes what the old route rejects (store, plus reasoning_content, reasoning, and refusal on assistant messages) and folds old thinking content back into the content array Mistral understands.
The compatibility endpoint returns thinking as reasoning_content, and streaming deltas as delta.reasoning_content. The native endpoint returns thinking content as elements in a delta.content array, such as {"type":"thinking", ...}; the plugin splits those into reasoning_content. Both paths hand CPA the same output format, which CPA then converts into the field the client protocol uses:
| Client protocol | Thinking field |
|---|---|
| OpenAI Chat Completions | reasoning_content |
| Claude | thinking |
| Responses | reasoning |
| Gemini | thought: true |
Thinking is triggered by preserving reasoning_effort. OpenAI Chat requests prefer OriginalRequest because CPA's Payload can drop the field during preprocessing. When a mapping has a non-empty reasoning, the plugin overrides the client's setting.
Credentials are ordered by priority from high to low. Healthy credentials come first, cooling credentials come after them, and disabled or keyless credentials are skipped. A request that follows a failure therefore tries the other keys first. If every key is cooling, the highest-priority one is still attempted, so a short outage does not block all traffic.
These responses move to the next credential:
401,403: invalid key or missing permission408,425,429: timeout, too early, rate limit5xx: upstream error- Transport errors, including connection failures and interrupted connections
400, 404, and 422 are not retried because another key would receive the same error. A request tries at most three credentials.
After a failure the cooldown is cooldown-seconds × 2^(consecutive failures - 1), capped at 15 minutes. Any success clears that key's failure count and cooldown. The console also has a Reset cooldown action.
Failover for streaming requests happens while opening the upstream connection. Once the upstream returns 200 and starts streaming, a later disconnect is logged and the stream ends. The plugin does not replay a partial response.
Check under Credentials calls GET /models, confirms the key works, and reports the model count and latency.
Fetch upstream models under Models uses the same endpoint and lists the upstream catalog. Select models and add them in one batch. Upstream IDs that already have a mapping are marked as added. The client name defaults to the upstream ID and can be changed later.
Test sends a non-streaming request for one mapping with max_tokens: 64 and the mapping's reasoning setting. It checks the key, model ID, and parameters together and counts toward your Mistral bill. Test requests are logged with a probe flag and excluded from statistics.
The plugin reads the same billing endpoints the official Vibe client uses:
GET {base-url}/billing/subscription
GET {base-url}/billing/budget
GET {console-url}/api/vibe/whoami
/billing/subscription names the plan (EDU, INDIVIDUAL, TEAM, ...) and whether pay-as-you-go is on. /billing/budget returns the two included monthly allowances:
api_budget: ordinary API and Studio spend.vibe_budget: Vibe Code spend.
The two allowances are separate: vibe_budget funds the official Vibe surfaces (web, CLI, editor extensions), and api_budget funds the API. Mistral's subscription docs state that usage made through non-Mistral products, such as third-party tools and harnesses, counts toward the API monthly allowance. This plugin is a third-party tool, so by default, whether the key scope is CHAT, MISTRAL_CODE, or API, forwarded requests spend only api_budget. /api/vibe/whoami is still read to show the key scope and plan in the console, but it does not drive auto-pause.
The gateway splits the bill on the request's metadata: a completion that carries metadata.call_type — the field the official Vibe client sends on every call — is booked against vibe_budget, and one without it against api_budget. Measured on 2026-12-01 against an EDU account's s1, one field at a time: {"x":"y"} and {"user_plan":"EDU"} moved the API allowance only; {"call_type":"main_call"}, {"call_type":"secondary_call"}, and even {"call_type":"bogus"} moved the Vibe allowance only. Changing only the User-Agent (mistral-client-python/Mistral-Vibe/3.2.0) or the model (mistral-vibe-cli-latest) did nothing, and the native /v1 and compatible /openai/v1 routes behaved the same. With vibe-billing: true the plugin therefore adds metadata.call_type: main_call to every request (a value the client already sent wins), traffic is booked against the Vibe allowance, and auto-pause follows vibe_budget.
The switch is on by default because this plugin targets Vibe-plan accounts, where the Vibe allowance is the large one. The documented rule is the opposite, though: adding call_type works around the billing split, and Mistral may fix it or treat it as abuse. Set vibe-billing: false to follow the documented behavior; the account risk is the operator's to take.
Both allowances are stored per credential and shown under Credentials (used / included, a progress bar, the plan name, the key scope, and the reset time) and as a compact summary on Overview. The API allowance the plugin actually spends is marked. The page repaints from the cached figures every 30 seconds, the background check refreshes billing on quota-refresh-seconds, and the Refresh allowance buttons read billing immediately.
A credential is taken out of rotation when the allowance the plugin bills (vibe_budget by default, api_budget with vibe-billing: false) reaches 100% and pay-as-you-go is off. This pauses the whole key, not one model category. Nothing is written to the CPA config: a manual disable stays manual, and the automatic pause is derived from the last billing read. Once reset_at passes, the credential is eligible again and the next background check confirms the new allowance. When no API allowance was read, the destination is unknown and the plugin never auto-disables; the same holds for a billing read failure or a key without permission to see billing.
The working state and the last read per credential are cached in:
<config dir>/plugin-data/mistral/quota.json
so a CPA restart starts from the previous figures. Background checks do not use the management session, so they connect directly; the console refresh uses the host bridge and follows ignore-proxy like every other plugin call. If the deployment cannot reach Mistral without CPA's proxy, the automatic part still runs whenever a client request or the console triggers a refresh.
The plugin also registers CPA's quota_provider capability, so the Mistral credential shows up in the Management Center's Quota Management page: plan name, both allowances (used amount, remaining fraction, reset time) and a marker on the allowance this plugin currently bills. The page shows the credential the scheduler would pick; with several keys every group is prefixed with the key label, and the per-key view stays in the Mistral console.
Saving from the console edits the CPA config file. The plugin finds it the same way the host does:
CLIPROXY_CONFIG_PATH, when set;- the
-config/--configargument the host was started with (-config=/pathworks too); /CLIProxyAPI/config.yaml, the published image layout;config.yamlin the working directory, which is the host's own default.
The request log and the quota cache live under plugin-data/mistral/ next to that file. A systemd or package install therefore keeps its data in its own app directory (for example /var/lib/cliproxyapi/app/plugin-data/mistral/) and does not need a /CLIProxyAPI symlink.
Logs are written inside the container to:
/CLIProxyAPI/plugin-data/mistral/requests.jsonl
Each entry contains time, client model, upstream model, credential actually used, status, attempt count, first-byte time, total time, input tokens, output tokens, cached tokens, output speed, and error. Older entries without the newer fields read as zero.
The Logs tab shows the latest 50, 100, or 200 entries, filters by status, and lists input, output, and cached tokens for each request. Times are shown in seconds with one decimal. Statistics cover real client traffic only and exclude management tests. Output speed is completion tokens divided by generation time. Cache hit rate is cached tokens divided by input tokens. Both are left empty when Mistral does not return usage on a stream.
When stream-idle-seconds is above 0, the plugin arms a watchdog on the upstream
stream and checks the time of the last real model output. If the threshold passes
with no output, it cancels the upstream request and closes the downstream stream.
The cutoff covers silence between frames, not the wait for the first byte: headers
only arrive when the model starts answering, and a max-effort turn legitimately
stays quiet for minutes before its first token (the upstream Vibe client allows
720s for the same wait). A direct attempt that produces no byte at all is bounded
by a separate 600s first-token budget instead, and it is retried.
A stream the cutoff stops is reported as a timeout: the request log records 504
with upstream timed out after Ns without model output, and the client receives
the same reason in the SSE error event followed by [DONE]. Clients retry a
timeout, so a stalled stream recovers instead of failing the turn. Do not set this
value too low: 60s cuts turns whose tool call is being generated whole, because
Mistral only sends the call at the end. 0 disables the cutoff, which is the
default.
The wait for the first byte is bounded by 300s and it is cancellable. While a
direct attempt waits for headers, the plugin asks the host every two seconds
whether the request is still wanted; when the client disconnects or abandons the
attempt, the upstream connection is dropped immediately and the request is logged
as 499 downstream stream closed before the response was delivered instead of
holding a dead connection for the full budget. A first-byte timeout of our own is
logged as upstream first byte timeout after 5m0s without response headers — the
budget, not the transport's http2: timeout awaiting response headers wording,
which reads like an HTTP/2 fault and is not one.
You need Go 1.26 and a C compiler. Linux amd64 can use the repository's Dockerfile:
docker build --platform linux/amd64 -f Dockerfile.build --output type=local,dest=dist .The result is dist/mistral.so. Other platforms are built by the release workflow.
The version in marketplace/registry.json under plugins[0].version is authoritative, and it must equal pluginVersion in cmd/mistral/version.go.
Push a tag named v plus that version, for example v0.3.0. Actions will:
- Run tests and build the shared library on each platform.
- Package linux amd64, linux arm64, darwin arm64, darwin amd64, and windows amd64.
- Write
checksums.txt, create or update the GitHub release, and mark it latest.
A tag that does not match the version fails the workflow before anything is published.