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 ¶
- type Entry
- type Store
- func (s *Store) Add(date, provider, model string, prompt, completion int)
- func (s *Store) ByDay() []Total
- func (s *Store) ByModel() []Total
- func (s *Store) Clear()
- func (s *Store) Purge(cutoff string) int
- func (s *Store) Save() error
- func (s *Store) Total() Total
- func (s *Store) TotalSince(cutoff string) Total
- type Total
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 ¶
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 ¶
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) Clear ¶ added in v0.5.0
func (s *Store) Clear()
Clear drops the entire ledger. The caller persists with Save.
func (*Store) Purge ¶ added in v0.5.0
Purge drops entries older than cutoff (Date < cutoff) and returns how many were removed. The caller persists with Save.
func (*Store) TotalSince ¶ added in v0.5.0
TotalSince sums all entries on or after cutoff (an ISO YYYY-MM-DD date; ISO dates compare correctly as strings). cutoff "" sums everything.