OpenProgram Docs

Provider quota

One status per connected provider: health, quota, 30-day spend, default model and key health. Quota comes first from the replies OpenProgram already receives; an endpoint is read only on a few events, never on a timer.

A provider is connected when it is enabled or holds a credential: one in OpenProgram's store, its CLI on PATH, the Codex CLI's auth file, or a satisfied cloud chain.

A provider that signs in only through OpenProgram, such as Grok Subscription, counts once its sign-in is stored, so a fresh install lists none: the Providers page shows Connect a model provider and openprogram providers status prints "No connected providers".

PartWhere
Model and storeopenprogram/models/usage/quota.py
Endpoint readersopenprogram/models/usage/quota_fetchers/, one module per source
Statusopenprogram/models/usage/provider_status.py, wire types generated to apps/web/lib/settings/provider-status.generated.ts
RouteGET /api/providers/status, POST /api/providers/status/refresh, WebSocket frame provider_quota
CLIopenprogram providers status [--refresh] [--json]: asks the running Worker for the route's payload (each key's use count and last use live in its memory), and builds it itself when none answers

One model, four kinds

A QuotaLimit is one limit of one account: key, label, unit (percent, usd, tokens, requests), used, limit, remaining, window, reset time, plus its source (headers, frame, endpoint) and fetched_at. A provider's report has one kind:

KindWhenExample
windowedA percent unit, or a window longer than a minuteCodex 5 h and weekly windows
balanceA money limitOpenRouter key limit
rate_limitPer-minute requests or tokensOpenAI and Anthropic API headers
noneNothing observedMistral
Status
Warning at 80 % used, danger at 95 %, exhausted at 100 % or nothing remaining. A windowed limit warns early only when usage runs ahead of the time elapsed in its window.
Stale
A value older than 15 minutes is marked stale; it is still shown, with its age.
Account
The stored credential id, or empty for an environment key. A bearer token is matched to its credential by digest; the token itself is never stored.

Captured from replies

ProviderRead from
OpenAI Codexx-codex-* headers of every answer, a 429 included, every limit family; the codex.rate_limits WebSocket frame
OpenAI-compatible APIsx-ratelimit-* headers (Chat Completions and Responses adapters)
Anthropicanthropic-ratelimit-* headers, only with an API key on api.anthropic.com

Values stay in memory and reach disk at most every 30 s per account. The old Codex parser's only caller looked for headers Codex does not send; it is replaced by one that follows codex-rs.

Reading an endpoint

An endpoint is read whenCondition
The status page opensThe last read of that account is older than 10 minutes, whatever it answered; read after answering, in the background
The user asks for a refresh—
A reply failedWith 402, 429 or a quota message; at most once per account per 10 minutes
A key was just added—

A refused read (401, 5xx, a body that does not parse) counts as a read: otherwise an endpoint that rejects the key would be asked again on every open.

One read per account at a time; a 429 from the quota endpoint holds that account for its Retry-After, or 5 minutes. Reads use the configured safe HTTP client, pinned to the endpoint's origin, and are logged as probe kind quota.

Each read is recorded per provider and account in usage.db (quota_reads), and the Worker and every CLI run decide from that record:

  • kept: when it was sent, its HTTP status, why it failed, the 429 hold, the last read a failed reply asked for;
  • so a refused read is not sent again by the next providers status or after a Worker restart;
  • a failed read leaves the earlier values with their own observed time; the status names the failure once below them (read_error, read_at) until a read answers.
SourceStateShape taken from
OpenRouter /keyOn; keeps the remaining amount, not a yes/noOpenRouter docs, Hermes
Codex usageOn; the weekly and 5h windows and the creditsOh My Pi, codex-rs; a real response
DeepSeek /user/balanceOn; the balance in its own currency, spent when the account cannot pay for a callA real response
MiniMax Token Plan, OpenCode GoOn; the plan's windows. A 401 from a plan's endpoint marks nothing on the keyOh My Pi; a real response
Z.aiOff until verifiedOh My Pi, ZCode
GitHub CopilotOff until verifiedOh My Pi

Spend

From the usage ledger, per provider over 30 days: calls, cost, list price, tokens by part, cache share (cache reads over prompt tokens) and a daily series of 30 points. A subscription provider reports its spend as Included, with the list price kept beside it. The default model is the last one used, else the most used.

A DeepSeek reply could show more cached tokens than total tokens. The cause: the recorder's fallback wrote total_tokens = input + output, leaving cached tokens out. The recorder now keeps the larger of the reported total and the parts summed, and every aggregate sums the parts, so rows written before the fix read correctly.

Table in usage.dbHolds
quota_snapshotsThe latest value per provider, account and limit
quota_samplesOne sample per 15 minutes, kept 90 days
quota_readsThe last endpoint read per provider and account

Health and failure causes

Two records speak about a key: its credential status, written when a call failed (status_at, the credential's updated_at), and the last read of its quota endpoint (read_at). The newer one decides; at the same time a 401 outranks a stored billing stop or throttle.

CaseReads as
A 401 read newer than the statusinvalid_key ("quota endpoint answered 401"), until a read answers or a call with the key succeeds. For a key (not a sign-in) the same status is written on its row, so the provider's list says what its card does
Marking the rowOnly a verified endpoint, never on a CreditsError body
A read that answered after a quota stopOverrules the stop; that read's balance decides
A refresh token the token endpoint refuses (invalid_grant, already used)needs_login, read as signed_out with the Sign in again fix; for a stored sign-in and for one delegated to the Codex CLI's file. The delegated one is not asked again until the file holds another login
HealthStates
The best key's state, overridden by a spent limitready, rate_limited (with the reset time), no_credit, invalid_key, signed_out, unknown
A provider with no keynot_configured
A local server that does not answernot_running

Each state that needs action carries its fix; see Provider management.

A throttle lasts as long as its cooldown. A key keeps its cooling status until its next success but is chosen again once the cooldown has passed, so health reads such a key as ready, not as rate limited until a time already gone.

The CLI table prints only coming times (until 14:05, resets Nov 19 02:22); a time already passed is left out. It fits the terminal width: a bar gives up cells, down to 5, and then its reset time moves to a line of its own. Output to a pipe without COLUMNS is not wrapped.

A failed reply carries a cause beside its error reason, from the provider error to the turn result, the event (cause) and the stored placeholder (error_cause):

CauseFrom
quota_exhausted402, usage_limit_reached, or a billing body under any status (insufficient_quota, 401 CreditsError "Insufficient balance"); names the spent limit, its reset time, the key (account) and that key's other windows (other_limits) when known
invalid_key401 or a rejected key message
not_availableRegion or plan refusal (403 JSON, model not on the plan)
unreachableDNS or connection failure anywhere in the exception chain

An ordinary 429, a 5xx, a timeout and a 403 web page from a network edge carry no cause; the error card is drawn as before.

Decisions

ChoiceFollowsWhy
Limit recordOh My Pi UsageLimitThe most complete of the 21: windows, money and request counts in one record
Labels, "% left", stale markCodexSubscription users already read its 5h / Weekly rows
Time-aware warningClaude CodeUsage against elapsed window time warns earlier and less often than a fixed line
Replies first, no timerCodex, Claude CodeA timer spends requests while nobody looks; replies already refresh busy providers
429 hold on the quota endpointOh My PiNever retries into its own rate limit
OpenRouter remaining amountHermesA yes/no hid how close a key was to its limit
Unverified readers off—Written only from a peer's documented response; switched on after a real check

Implementation status

  • No web UI reads the status route yet; the pages that will are in Provider management.
  • No reader for Kimi Coding (its payload is not settled), Moonshot balances, or OpenRouter /credits (no peer documents their responses). Anthropic, OpenAI, Google, Perplexity and Xiaomi API keys have no balance endpoint; a card shows their 30-day spend.
  • The Z.ai and GitHub Copilot readers are off: no real response has been seen.
  • Not built: a REPL /status. A top-level openprogram status alias is not possible: that name is the background service's.
Last updated · 2026-11-25