usage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 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 = 60 * time.Second

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

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

Functions

func CountCompactions

func CountCompactions(transcriptPath string) int

CountCompactions counts compact_boundary entries in a session transcript JSONL.

func FormatQuotaWindow

func FormatQuotaWindow(win *QuotaWindow, label string) string

FormatQuotaWindow formats a single quota window for display.

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 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