Documentation
¶
Overview ¶
Package pricing loads the embedded model→USD rate table and computes estimated cost for a given model + usage + timestamp. See docs/superpowers/plans (plan A4) for the implementation plan.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rate ¶
type Rate struct {
Model string `yaml:"model"`
EffectiveFrom time.Time `yaml:"effective_from"`
InputPerMTok float64 `yaml:"input_per_mtok"`
OutputPerMTok float64 `yaml:"output_per_mtok"`
CacheReadPerMTok float64 `yaml:"cache_read_per_mtok"`
CacheCreatePerMTok float64 `yaml:"cache_create_per_mtok"`
}
Rate is a single pricing row for a model that took effect at EffectiveFrom. Rates are denominated in USD per million tokens of the corresponding bucket.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table holds the merged set of rates and answers Cost / LastUpdated queries. Construct with NewTable or NewTableFromBytes. Safe for concurrent use after construction; the rate table is immutable and the warn-once map is guarded.
func NewTable ¶
NewTable constructs a Table by parsing the embedded baseline YAML and, if present, layering the user override at ~/.ccx/pricing.yaml on top.
func NewTableFromBytes ¶
NewTableFromBytes constructs a Table from explicit YAML bytes. Useful for tests. Pass nil for userOverride if no override is desired. When both are provided, userOverride is deep-merged on top of embedded by model name.
func (*Table) Cost ¶
Cost returns the estimated USD cost for usage against model at time ts.
Lookup semantics: the applicable rate is the one whose EffectiveFrom is the latest value <= ts. If no rate is effective at ts, Cost returns 0 and nil.
Formula, per bucket: (tokens / 1e6) * rate_per_mtok. The four buckets are summed. Result is raw float64; the UI is responsible for rounding.
func (*Table) LastUpdated ¶
LastUpdated returns the most recent effective_from across all loaded rates. It is intended for footer-style "rates as of <date>" UI strings.