Skip to content

feat(usage): track the DeepInfra credit balance in the status bar - #270

Merged
nplez1 merged 6 commits into
nplez1/mainfrom
nplez1/DeepInfra-Provider
Nov 1, 2026
Merged

nplez1 merged 6 commits into
nplez1/mainfrom
nplez1/DeepInfra-Provider

Conversation

@nplez1

@nplez1 nplez1 commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

What this does

Adds DeepInfra as a first-class usage provider in the fork, matching the shape DeepSeek and Fireworks.ai already have: a row in Settings → AI Provider Accounts (API key in the encrypted credential store, usage switch, console link, Forget-key) and a status-bar meter showing dollars remaining.

The readout is the remaining balance in USD — the account credit minus the usage incurred since the last invoice, which is the figure DeepInfra's own dashboard shows. Unbilled usage is broken out beneath it, and an exhausted or suspended account stays visible (available: false) so it can be topped up rather than vanishing from the bar.

Balance source: GET https://api.deepinfra.com/payment/checklist with the API key as a bearer token — the billing route the dashboard itself reads, and notably not under /v1. Route, auth and field names were confirmed against DeepInfra's public OpenAPI spec and a live response; the remaining figure mirrors the dashboard's own -(stripe_balance + recent).

Reviewed by Opus 5.5, high: R1 (2 SHOULD-FIX fixed, no blocking), delta re-check clean on R2

R3 and R4 (3feda4a, a53487b) apply the delta round's two one-hunk MINORs and move the rationale out of upstream-owned files so the fork-comment ratchet reads its baseline again. The reviewer's verdict on the delta was that neither needed a further round. The branch was then rebased onto nplez1/main (bc4afd9), and nplez1/main was merged in again at 2c6b888 — both clean, and git show --remerge-diff on the merge shows no resolver-chosen hunks, so the reviewed content is byte-identical to what is pushed.

Verification

Run in this worktree on the pushed head eb9ddbe:

  • Unit gate: PASS — Unit gate @eb9ddbeb0f (clean): PASS — 142468 passed; 0 failed (0 allowlisted, 0 unexpected); 0 flaky re-run passed; 0 unhandled error headline(s); 588 s.
  • CI: all 8 checks green (Mobile verify, Mobile native fingerprint, changes, fork-pr-gates: changed lines, fork-pr-gates: typecheck, persistence on ubuntu-22.04 / windows-2022 / windows-11-arm).
  • pnpm tc — clean (node, cli, web).
  • pnpm run check:code-quality:changed — 0 new findings.
  • Targeted tests, all green: deepinfra-fetcher.test.ts (16), service-deepinfra-usage.test.ts (7), provider-credits-format.test.ts (14), status-bar-provider-visibility.test.ts (43), status-bar-usage-projection.test.ts (2), provider-accounts-sections.test.ts (5), register-fork-handlers.test.ts (3), the harness's unmocked-module guard (1), ui-hydration-workspace-preferences.test.ts (53), plus the fourteen rate-limit service suites, AccountsPane*, AppearancePane, UsageRosterPanel, tooltip, usage-error-copy, provider-segment-balance, host-settings-api-key-port/replication-*, wsl-move-renderer-store-keys, web-preload-api-* and fork-catalog-overlay.
  • verify:localization-catalog and verify:localization-coverage — pass.
  • Live check: the real /payment/checklist payload parsed to USD 19.18 available with USD 0.82 unbilled, matching the dashboard.

One foreign red fixed on the way

Mobile verify was red before this branch's first push, and red on nplez1/main itself: upstream's c827ed5324e turned on the strict mobile typecheck, which rejects indexing Record<TuiAgent, …> with the string that Object.entries widens to — and the fork's own src/shared/tui-agent-config-np.ts had relied on noImplicitAny being off there. eb9ddbe merges through a string-keyed working copy, which needs no type assertion, so Mobile verify and the mobile tests typecheck ratchet are green. Reproduced and verified locally against mobile/tsconfig.json (3,510 files) at both origin/nplez1/main and this head.

Lint gate: 42/44 green, 2 foreign reds still on main

orca-queue node local/gate-lint.mjs reports 42 green, 2 failing, and neither is in this diff:

  • check-upstream-file-comments — 6180 vs baseline 6051, every file under src/renderer/src/components/right-sidebar/**.
  • check:focus-read-ratchet — three files under src/renderer/src/components/right-sidebar/**.

Both reproduce at bc4afd97030 and at 2c6b8882eef with none of this work present, and came in with #267. This branch touches no right-sidebar file, and I did not raise the baselines or add lint-known-red entries: raising a comment baseline would permanently accept 129 foreign comment lines, which is that feature's debt to pay.

Review findings not fixed, listed per the gate

  • NIT — an exhausted balance renders through the shared describeCredits copy as "-$1.25 available". That wording is pre-existing and shared with DeepSeek/Fireworks, so changing it here would change three providers' copy.
  • NIT — no deepinfra-api-key-store.test.ts or deepinfra-credentials.test.ts. DeepSeek has neither, so this is parity rather than a gap this branch introduces; the fetcher, the service lane and the IPC shape are covered.
  • NIT — mobile/src/components/accounts-snapshot.ts gains 'deepinfra' in its provider enum; the mobile lanes that cover it now pass in CI.

Assumption

"AI Provider (in the settings list)" is read as the AI Provider Accounts section plus the status-bar meter — the surface DeepSeek and Fireworks occupy — rather than DeepInfra as a model backend for agents.

DeepInfra publishes no percentage quota, so the status bar gains a money
readout for it, alongside DeepSeek and Fireworks.ai:

- Settings -> AI Provider Accounts gains a DeepInfra row: an API key in the
  existing encrypted credential store (never GlobalSettings), with the usage
  switch, console link and Forget-key control every fork provider has.
- The readout is the remaining balance in USD: the account credit minus the
  usage incurred since the last invoice, which is the figure DeepInfra's own
  dashboard shows. That unbilled usage is broken out beneath it, and an
  exhausted or suspended account stays visible (available: false) so it can
  be topped up instead of vanishing.

The balance comes from GET /payment/checklist, the billing route the dashboard
itself reads; it is not under /v1. Route, bearer auth and field names were
confirmed against DeepInfra's public OpenAPI spec and a live response.

Adds 'deepinfra' to the provider union, RateLimitState (slot plus
deepinfraApiKeyConfigured), the status-bar item set and its one-shot default-on
migration, and a single-key host-settings replication port. The service lane
mirrors DeepSeek's: generation stamping so a pasted key cannot be overwritten
by an in-flight result, stale policy so a transient failure keeps the last
balance on screen, and disabled-provider gating.

Adds an 'unbilled' credits item key for the usage-since-invoice breakdown, and
folds the four fork API-key config resolvers onto one helper, which is what
keeps service-fetch-targets.ts under its line cap.
…lling_type

Review findings on the DeepInfra provider (R1):

- getState() reads the DeepInfra key store, so every rate-limit service suite
  now reached the user's real credential file (a chmod, and the adoption marker)
  unless it mocked that store. Adds the store to the harness's unmocked-module
  guard and the mock to the fourteen suites, matching what DeepSeek already had.
- `available` now depends on `billing_type`: only a prepaid ('balance') account
  stops working at zero credit, so an invoice-billed account running at about
  zero no longer gets a "cannot fund further calls" warning. `suspended` still
  wins in both cases.
- Money is summed in integer nanos and rounded once at display time, so the
  readout cannot sit a cent away from the dashboard's own figure (rounding
  -20.004 and 0.005 to cents separately answered $19.99 for $20.00).
- A payload carrying neither amount is now a parse error rather than a confident
  $0.00: this API answers plain JSON, which writes a zero as 0 rather than
  omitting it, so neither field means the shape changed.
- Coverage: the 'unbilled' label, an `ok` DeepInfra snapshot reaching the bar,
  an invoice-billed account at about zero, and the sub-unit negative branch.
- Drops the Accounts-description rekey, which had orphaned its ten existing
  translations and left an empty object in the catalog.
… in the pane blurb

Round-2 delta re-check MINORs:

- `isPrepaid` now means what its comment says: only an explicit `'balance'`
  billing type is prepaid, so an unrecognized type claims nothing about
  exhaustion instead of guessing in either direction. Test covers it.
- The Accounts-pane description names DeepInfra again, but through the existing
  `b1c2f8b0ac` key rather than a new one, so the ten locale files that tombstone
  that key keep working and nothing is orphaned.
- An unbilled amount under half a cent no longer renders as a "Unbilled usage
  $0.00" line.
…iles

The fork-comment ratchet refuses new comment lines above upstream's code, and
this branch had added eleven: the rationale for the shared API-key config
resolver, the DeepInfra credential type, the prepaid rule, and the new provider
flags. The rationale belongs in this commit and the PR body, not in a file
upstream edits, so it is removed and the ratchet reads 6051/6051 again.

No behaviour change.
Upstream's c827ed5 ("run full native mobile typechecks without compiler
caches") turned on the strict mobile typecheck, which rejects indexing
Record<TuiAgent, …> with the `string` that Object.entries widens to. The fork's
own override table relied on noImplicitAny being off there, so `Mobile verify`
has been red on nplez1/main since that landed.

Merges through a string-keyed working copy instead: a string index signature is
assignable back to the narrow record, so no type assertion is needed and the
repo's consistent-type-assertions rule stays satisfied.

Verified: mobile/tsconfig.json typecheck clean (3,510 files), mobile tests
typecheck ratchet OK, pnpm tc:node clean, changed-code-quality pass.
@nplez1
nplez1 merged commit 9f8e248 into nplez1/main Nov 1, 2026
14 checks passed
@nplez1
nplez1 deleted the nplez1/DeepInfra-Provider branch November 1, 2026 18:09
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.

1 participant