usage

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package usage provides access to the Anthropic quota usage API.

Index

Constants

This section is empty.

Variables

View Source
var CachePath = "/tmp/claude-usage-cache.json"

CachePath is the path to the usage cache file. Replaceable for testing.

View Source
var CacheTTL = 10 * time.Minute

CacheTTL is the cache duration for usage data. Configurable at startup.

HTTPGetFn is the function used for HTTP requests. Replaceable for testing.

View Source
var LastGoodCachePath = "/tmp/claude-usage-last-good.json"

LastGoodCachePath stores the last successful API response. Replaceable for testing.

Functions

func CountCompactions

func CountCompactions(transcriptPath string) int

CountCompactions counts compact_boundary entries in a session transcript JSONL.

func ExhaustedResetMinutes added in v0.2.1

func ExhaustedResetMinutes(data *Data) int

ExhaustedResetMinutes returns the reset time for the most saturated active window.

func FormatQuotaWindow

func FormatQuotaWindow(win *QuotaWindow, label string) string

FormatQuotaWindow formats a single quota window for display.

func FormatRateLimitSegment added in v0.2.1

func FormatRateLimitSegment(minutes int) string

FormatRateLimitSegment formats the explicit exhausted-limit segment.

func FormatStaleQuotaWindow added in v0.2.0

func FormatStaleQuotaWindow(win *QuotaWindow, label string) string

FormatStaleQuotaWindow formats a window with ?% but real time and indicator.

Types

type Data

type Data struct {
	FiveHour  *QuotaWindow
	SevenDay  *QuotaWindow
	Extra     *ExtraUsage
	ErrorType string
}

Data is the parsed response from Anthropic usage API.

func Fetch

func Fetch() (*Data, error)

Fetch retrieves quota usage from Anthropic API (with caching).

func FetchLastGood added in v0.2.0

func FetchLastGood() *Data

FetchLastGood returns the last successful usage data (no TTL).

func ParseBody

func ParseBody(body []byte) (*Data, error)

ParseBody parses the usage API response body.

type ExtraUsage

type ExtraUsage struct {
	MonthlyLimit float64
	UsedCredits  float64
}

ExtraUsage represents monthly extra/overuse budget.

type QuotaWindow

type QuotaWindow struct {
	Utilization      float64
	ResetsAt         time.Time
	TotalMinutes     int
	RemainingMinutes int
}

QuotaWindow represents a single usage quota window (5-hour or 7-day).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL