cost

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendUsage added in v0.14.0

func AppendUsage(path string, u Usage) error

AppendUsage adds u as one JSON line to path (created 0600, folders 0700). A zero At becomes now. A nil CostUSD is filled from the pricing table, or, for a model the table does not price, left out with CostUnknown set: an unknown cost is never recorded as 0.

func Calculate

func Calculate(model string, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens int64) float64

Calculate returns the estimated cost in USD for the given token usage. Returns 0 if the model is unknown.

func DefaultUsagePath added in v0.14.0

func DefaultUsagePath() string

DefaultUsagePath is where aimux's own model usage is recorded.

func Priced added in v0.14.0

func Priced(model string) bool

Priced reports whether the pricing table knows model (after aliases).

Types

type ModelPricing

type ModelPricing struct {
	Input      float64
	Output     float64
	CacheRead  float64
	CacheWrite float64
}

ModelPricing holds per-million-token pricing in USD.

type Usage added in v0.14.0

type Usage struct {
	At           time.Time `json:"at"`
	Label        string    `json:"label"`
	Model        string    `json:"model"`
	InputTokens  int64     `json:"input_tokens"`
	OutputTokens int64     `json:"output_tokens"`
	CostUSD      *float64  `json:"cost_usd,omitempty"`     // nil when the price is unknown
	CostUnknown  bool      `json:"cost_unknown,omitempty"` // the model is not in the pricing table: only tokens are known
	Estimated    bool      `json:"estimated,omitempty"`    // token counts guessed from text length
}

Usage is one model call aimux itself made (not an agent session's), kept so its cost is visible. Label names the feature, e.g. "naming".

Jump to

Keyboard shortcuts

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