Skip to main content

Crate cortexkit_provider_usage

Crate cortexkit_provider_usage 

Source
Expand description

Shared wire types for the ai-provider-quota module’s usage.get payload.

The quota module serves an array of ProviderUsage per request; ALF’s router (codexbar-window-extractors.ts), astrocyte’s capacity axis, and the ck quota renderer all consume that shape. This crate is the single definition those consumers compile against, so the wire shape cannot drift without a shared-crate PR every side reviews.

§Shape, not policy

These are pure data types. Read-time transform semantics are PRODUCER behavior documented on the relevant fields but NOT enforced here:

  • Banked-reset relaxation: the quota module may zero RateWindow::used_percent (the EFFECTIVE number consumers pace on) and carry the provider-reported truth in RateWindow::raw_used_percent. A consumer renders whatever the wire says; a sudden 0 → high transition is an honest disarm (credits spent / auth broke), not a glitch.
  • Cache-only partial arrays: the quota module never blocks on a fetch, so a result may omit providers not yet swept. Missing ≠ zero.
  • Degraded entries ride in-band: a provider fetch failure is a normal ProviderUsage carrying error, not a request-level failure.

§Serialization contract consumers depend on

  • camelCase keys (usedPercent, resetsAt, windowMinutes, extraRateWindows, rawUsedPercent, accountInfo, savedResets, usedCount, totalCount).
  • A healthy entry MUST NOT carry error (consumers skip truthy-error entries), so it is omitted when absent.
  • A window is emitted when it has a usedPercent; resetsAt is OPTIONAL and omitted when the provider reports no reset (never fabricated).

Structs§

AccountInfo
Account labels and subscription information supplied by a provider or vault.
CreditExpiry
One saved reset credit and its expiry time.
ExtraWindow
A per-model window bundled under one account (e.g. Antigravity’s Geminis).
ProviderUsage
One provider/account’s usage entry. The /usage response is an array of these. A fetch failure becomes an entry carrying error (silent-degrade), never a failure of the whole array.
RateWindow
One rate-limit window: how much of a quota pool is spent and when it resets.
SavedResets
Saved reset credits reported by Codex’s read-only credits endpoint.
Usage
The window topology for one account: up to three account-wide pools plus an optional list of per-model pools.