Skip to content

feat: show Mistral subscription budget in /usage and the footer - #3

Open
postpersonality wants to merge 1 commit into
specode:mainfrom
postpersonality:fix/mistral-subscription-usage
Open

postpersonality wants to merge 1 commit into
specode:mainfrom
postpersonality:fix/mistral-subscription-usage

Conversation

@postpersonality

Copy link
Copy Markdown

Fixes #2.

/usage answered Unsupported: mistral is not supported yet. for a configured Mistral subscription, because no adapter answered to the mistral provider id. The quota is reachable: Mistral serves the same billing endpoints Vibe Code reads, GET /v1/billing/subscription and GET /v1/billing/budget on api.mistral.ai, and a subscription key can read them.

Mistral
  Vibe Code:
    1m Window      ████████████  100% left · $299.70/$300.00 · resets 12/01 03:00

  API:
    1m Window      ████████████  100% left · $30.00/$30.00 · resets 12/01 03:00

  Account:
    Plan           Individual
    Pay-as-you-go  off

Footer: 1m 100% ↻14d2h.

What changed

  • src/providers/mistral.ts: normalizes the two monthly budgets into UsageBuckets. A plan is a budget, not a window of requests, so the buckets carry dollars (unit: "usd") with the reset date, and the plan and pay-as-you-go state become account metrics. A currency other than USD keeps the exact percentage and shows the allowance in its own currency instead of mislabelling it as dollars.
  • src/query.ts: a mistral adapter for the provider ids mistral (pi-mistral-subscription 0.2.0 and later) and the deprecated mistral-subscription (earlier releases). The footer tracks the Vibe Code budget, where subscription sign-in requests are counted; an account with only an API budget falls back to it. A budget endpoint answering 403 (no see_org_inference_usage permission) or 404 (platform without billing) reports Unsupported with the reason, and any other failure stays an error rather than a silent zero. A failing plan read only drops the plan line; its handler is attached immediately, as the Antigravity adapter does.
  • src/format.ts: a bucket with unit: "usd" printed 0.22/300 without a currency. It now formats through formatValue, so it reads $0.22/$300.00; other units are unchanged.
  • test/mistral.test.ts: 12 tests covering normalization, the footer group, the legacy top-level budget, the deprecated provider id, a non-USD budget, a missing permission, a failing plan read and a failing budget endpoint.
  • README.md, README.zh-CN.md, package.json: Mistral in the provider table, a provider note with the permission caveat, and the package description and keywords.

Verification

  • node --test test/*.test.ts: 128 pass, 1 fail. The failure is test/claude-bridge.test.ts "extension shows observed Claude usage without any request", which also fails on main at cff2bdd (its fixture resets are in the past, so the windows read 100%); this branch does not touch it.
  • The adapter was run against the live billing endpoints with a real subscription credential; the output above is that run.
  • pi --no-extensions --offline -e ./index.ts --list-models loads the extension.

Notes for review

  • A subscription key is an API key, so the adapter does not set requiresOAuth: an API key without the usage permission gets the Unsupported message above instead of an auth error.
  • The plan name maps INDIVIDUAL, TEAM and ENTERPRISE to their display names and passes anything else through.

A Mistral plan is a monthly budget shared by Studio, the API and Vibe
Code, not a window of requests, so the provider needs its own adapter.
Usage comes from the billing endpoints Vibe Code reads,
`GET /v1/billing/subscription` and `GET /v1/billing/budget` on
api.mistral.ai.

`/usage` lists the Vibe Code and API budgets in dollars with the reset
date, the plan and whether pay-as-you-go is on. The footer tracks the
Vibe Code budget, where subscription sign-in requests are counted; an
account with only an API budget falls back to that one.

The adapter answers to `mistral`, which pi-mistral-subscription 0.2.0
registers, and to the deprecated `mistral-subscription` id of earlier
releases. A key without the `see_org_inference_usage` permission, or a
platform that does not serve billing, reports `Unsupported` with the
reason instead of a generic "not supported yet" message. A failing plan
read only drops the plan line.

Budget amounts in a currency other than USD stay percentages with the
allowance in their own currency, and USD amounts now print with a dollar
sign in /usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/usage shows only "Unsupported: mistral is not supported yet." with a configured Mistral subscription

1 participant