Documentation
¶
Overview ¶
Package usage fetches Claude subscription plan usage from Anthropic's OAuth usage endpoint — the same data the Claude Code CLI shows via /usage (5-hour session window, weekly window, and pay-as-you-go "extra usage").
This endpoint is NOT part of Anthropic's documented public API; it is the undocumented endpoint the Claude Code CLI uses, reconstructed from community reverse-engineering. Treat its shape as best-effort and degrade gracefully if it changes or disappears.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Extra ¶
type Extra struct {
IsEnabled bool `json:"is_enabled"`
MonthlyLimit *float64 `json:"monthly_limit"`
UsedCredits *float64 `json:"used_credits"`
Utilization *float64 `json:"utilization"`
Currency string `json:"currency"`
DecimalPlaces *int `json:"decimal_places"`
}
Extra describes the pay-as-you-go ("extra usage") state. Pointer fields are null when extra usage is disabled or the value is not reported.
MonthlyLimit and UsedCredits are reported in the currency's MINOR units (e.g. cents), with DecimalPlaces giving the scale — so 2219 credits at 2 decimal places is 22.19. Use UsedAmount / MonthlyLimitAmount to get major units.
func (Extra) CurrencySymbol ¶
CurrencySymbol maps the ISO currency code to a display symbol, falling back to the code itself (or "$" when unreported).
func (Extra) MonthlyLimitAmount ¶
MonthlyLimitAmount returns the extra-usage cap in major currency units. ok is false when the value is not reported.
func (Extra) UsedAmount ¶
UsedAmount returns the extra-usage spend in major currency units. ok is false when the value is not reported.
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller caches usage snapshots and refreshes them from the network at most once per minInterval. Concurrent callers single-flight through one fetch. Safe for concurrent use.
func (*Poller) Get ¶
Get returns the latest usage snapshot, hitting the network only when the cached value is older than minInterval. It returns (nil, nil) when usage tracking is unavailable (no OAuth token). On a transient fetch error it serves the last good snapshot when one exists; otherwise it returns the error.
type Snapshot ¶
type Snapshot struct {
FiveHour *Window `json:"five_hour"`
SevenDay *Window `json:"seven_day"`
SevenDayOpus *Window `json:"seven_day_opus"`
SevenDaySonnet *Window `json:"seven_day_sonnet"`
Extra Extra `json:"extra_usage"`
FetchedAt time.Time `json:"fetched_at"`
}
Snapshot is a point-in-time view of plan usage. Window pointers are nil when the corresponding window is not reported (e.g. per-model weekly windows with no usage yet).