accounting

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package accounting tracks per-sandbox and per-profile token and spend usage, exposes Prometheus counters, and supports budget checks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tracker

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

Tracker accumulates usage per sandbox and per profile. It is safe for concurrent use.

func New

func New() *Tracker

New returns a ready-to-use Tracker.

func (*Tracker) Forget

func (t *Tracker) Forget(sandbox string)

Forget drops a sandbox's per-sandbox entry, typically when the sandbox is killed. Profile totals are cumulative and retained.

func (*Tracker) Over

func (t *Tracker) Over(sandbox string, maxTokens int64, maxCostUSD float64) (bool, string)

Over reports whether a sandbox's usage meets or exceeds a positive limit. A limit that is <= 0 means "no limit" for that dimension. When over, the second return value is a human-readable explanation.

func (*Tracker) ProfileUsage

func (t *Tracker) ProfileUsage(profile string) Usage

ProfileUsage returns the cumulative totals for a profile. Unknown profiles return the zero Usage.

func (*Tracker) Record

func (t *Tracker) Record(profile, sandbox string, tokens int64, costUSD float64)

Record adds tokens and cost to both the sandbox and profile totals and increments the Prometheus counters for the profile. Negative inputs are clamped to zero.

func (*Tracker) Usage

func (t *Tracker) Usage(sandbox string) Usage

Usage returns the current totals for a sandbox. Unknown sandboxes return the zero Usage.

type Usage

type Usage struct {
	Tokens  int64
	CostUSD float64
}

Usage is a running total of tokens and spend.

Jump to

Keyboard shortcuts

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