Documentation
¶
Overview ¶
Package pricing computes estimated costs from recorded token usage and a static price list. Every value it produces is an estimate derived from configured rates, never a billed amount, and an unknown rate is never assumed to be free.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInconsistentUsage = errors.New("inconsistent token usage")
ErrInconsistentUsage is returned when token counters contradict their accounting mode, such as cached input tokens exceeding the input total they are declared to be part of.
Functions ¶
This section is empty.
Types ¶
type Estimate ¶
type Estimate struct {
Currency string
Input float64
CacheRead float64
CacheWrite float64
Output float64
Reasoning float64
Total float64
}
Estimate breaks the estimated cost down by token category, expressed in Currency.
func Calculate ¶
func Calculate(usage runners.TokenUsage, prices *runners.Pricing) (estimate *Estimate, ok bool, err error)
Calculate returns the estimated cost of usage under prices.
A nil estimate is ambiguous on its own: it means either nothing was consumed (ok is true) or usage was reported but its cost could not be determined reliably - no prices were configured, a reported token bucket has no resolved rate, or a required reasoning/cache split is unknown and would change the total (ok is false). Callers that need to tell "nothing to price" apart from "could not price it" should check ok rather than inferring it from usage themselves. An error is returned only for internally inconsistent usage, which is a data defect rather than missing information.