usage

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 6 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

Overview

Package usage is a small persistent token-usage ledger: prompt/completion tokens spent, bucketed by day, provider, and model. It lets /usage show a history beyond the current session.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Date       string `json:"date"` // YYYY-MM-DD
	Provider   string `json:"provider"`
	Model      string `json:"model"`
	Prompt     int    `json:"prompt"`
	Completion int    `json:"completion"`
}

Entry is one (day, provider, model) bucket of token counts.

type Store

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

Store is the ledger, persisted to a JSON file (in-memory if path is "").

func Open

func Open(path string) (*Store, error)

Open loads the ledger, or starts empty if the file is absent. A blank path yields an in-memory store that never persists.

func (*Store) Add

func (s *Store) Add(date, provider, model string, prompt, completion int)

Add folds tokens into the (date, provider, model) bucket. A no-op for a non-positive delta so a turn that reported no usage doesn't create a row.

func (*Store) ByDay

func (s *Store) ByDay() []Total

ByDay returns per-day totals, most recent day first.

func (*Store) ByModel

func (s *Store) ByModel() []Total

ByModel returns per provider/model totals, largest first.

func (*Store) Save

func (s *Store) Save() error

Save writes the ledger (no-op for an in-memory store).

type Total

type Total struct {
	Key        string // a date, or "provider/model"
	Prompt     int
	Completion int
}

Total is an aggregated row for display.

func (Total) Tokens

func (t Total) Tokens() int

Tokens is the combined prompt+completion count.

Jump to

Keyboard shortcuts

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