usage

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("usage compaction locked")

ErrLocked is returned by Compact when another compaction holds a fresh lock.

Ranges lists the reporting windows in display order.

Functions

This section is empty.

Types

type ModelUsage

type ModelUsage struct {
	Provider, Model                                 string
	Input, Output, CacheRead, CacheWrite, Reasoning int
}

type Range

type Range int
const (
	RangeAllTime Range = iota
	RangeLast1Day
	RangeLast7Days
	RangeLast30Days
	RangeLast6Months
	RangeLast1Year
)

func (Range) Since

func (r Range) Since(now time.Time) time.Time

func (Range) String

func (r Range) String() string

type Record

type Record struct {
	TS                                              time.Time
	Date                                            string
	Provider, Model                                 string
	Input, Output, CacheRead, CacheWrite, Reasoning int
	Rollup                                          bool
}

Record is one ledger entry: either a raw per-response entry (TS set) or a rolled-up per-day entry (Date set, Rollup true).

func NewRecord

func NewRecord(provider, model string, input, output, cacheRead, cacheWrite, reasoning int) (Record, bool)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func DefaultStore

func DefaultStore() (*Store, error)

func NewStore

func NewStore(path string) *Store

func (*Store) Append

func (s *Store) Append(rec Record) error

func (*Store) Compact

func (s *Store) Compact(now time.Time) error

Compact collapses every record into one rollup per (UTC day, provider, model) and drops rollups older than a year, rewriting the ledger atomically. Records without a usable timestamp are left untouched.

func (*Store) Load

func (s *Store) Load() ([]Record, error)

Load reads all records, skipping blank and corrupt lines.

func (*Store) MaybeCompact

func (s *Store) MaybeCompact(now time.Time) error

MaybeCompact runs Compact at most once per UTC calendar day, tracking the last run in a marker file next to the ledger. It is a no-op when the ledger does not exist yet, so callers can invoke it on every startup cheaply.

func (*Store) Path

func (s *Store) Path() string

type Summary

type Summary struct {
	Rows  []ModelUsage
	Total ModelUsage
}

func Summarize

func Summarize(records []Record, since time.Time) Summary

Summarize groups records by provider/model, filters by since (zero means all time), sorts rows by input descending, and totals them.

Jump to

Keyboard shortcuts

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