Expand description
OAuth /api/oauth/usage response + internal usage-data types.
Two shapes live here:
UsageApiResponsemirrors the endpoint’s wire JSON per ADR-0011 §Endpoint contract. Recognized buckets sit in namedOptionfields; codenamed/unreleased buckets land inunknown_bucketsvia#[serde(flatten)]so forward-compat is lossless.UsageDatais the enum segments consume after the fallback cascade lands. Per ADR-0013, the variant IS the provenance tag:Endpoint(EndpointUsage)carries authoritative endpoint data;Jsonl(JsonlUsage)carries raw token counts aggregated from transcripts so segments can render~5h: 420kinstead of synthesizing a percentage against a tier ceiling we don’t know.
The endpoint client converts wire → internal via
UsageApiResponse::into_endpoint_usage; the JSONL-mode cascade
constructs a JsonlUsage directly from the aggregator output in
cascade.rs.
Structs§
- Endpoint
Usage - Data from a successful OAuth
/api/oauth/usageresponse (possibly served from cache).unknown_bucketscarries codenamed buckets forward so plugins can inspect them; core segments don’t read it. - Extra
Usage - Overage-credit tracking for accounts with extra-usage enabled.
is_enabledis the load-bearing flag: whenfalse, every other field is typicallynullin the live endpoint. - Five
Hour Window - Active-block window surfaced to segments under JSONL fallback.
- Jsonl
Usage - Data derived from the JSONL transcript aggregator.
seven_dayis always populated (zero-valued on an empty transcript);five_hourisNonewhen the current 5h block has no recent activity, perdocs/specs/jsonl-aggregation.md. Fields arepub(crate)so the aggregator+cascade own the construction invariants; segments in this crate read them directly. - Seven
DayWindow - Rolling 7-day window under JSONL fallback. No
resets_at: this is a rolling window, not a hard-reset bucket, so therate_limit_7d_resetsegment hides entirely under JSONL perdocs/specs/rate-limit-segments.md§JSONL-fallback display. - Usage
ApiResponse - Shape of the OAuth
/api/oauth/usageendpoint response. Every recognized bucket isOptionbecause the endpoint omits (or emitsnullfor) buckets that don’t apply to the account’s tier, andunknown_bucketscaptures codenamed / unreleased buckets Anthropic may add without notice (omelette_*,iguana_*,cowork, etc. observed live 2026-04-18). Seedocs/research/claude-data-files.md§Raw data for the reference capture. - Usage
Bucket - Utilization plus reset-time for a single rolling window.
Enums§
- Usage
Data - What
DataContext::usagesurfaces after the cascade indocs/specs/data-fetching.md§OAuth fallback cascade finishes. The variant IS the provenance tag per ADR-0013: segments dispatch on it to pick between percent rendering (endpoint) and raw-token rendering (JSONL).#[non_exhaustive]leaves room for a future third source without a SemVer break.
Constants§
- KNOWN_
BUCKETS - Names of every recognized top-level field on
UsageApiResponse. Exported solinesmith doctorcan check “did the endpoint return any forward-compat keys?” without duplicating the field list — the [KNOWN_BUCKETS_PARITY] test below pins this againstUsageApiResponseso the two can’t drift. - RESEARCH_
DOCUMENTED_ BUCKETS - Codenamed forward-compat buckets observed in the live endpoint
during research captures (see
docs/research/claude-data-files.md§Raw data, 2026-04-18 capture). These are unrecognized byUsageApiResponse’s strict struct fields but Anthropic ships them on every response — gating the doctor’s “endpoint.shape_current” WARN on this list keeps the report quiet on healthy accounts while preserving the WARN for new unknown keys (the actual signal a maintainer wants).