pricing

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 11 Imported by: 0

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

func NewTable() (*Table, error)

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

func NewTableFromBytes(embedded, userOverride []byte) (*Table, error)

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

func (t *Table) Cost(model string, ts time.Time, usage contracts.Usage) (float64, error)

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

func (t *Table) LastUpdated() time.Time

LastUpdated returns the most recent effective_from across all loaded rates. It is intended for footer-style "rates as of <date>" UI strings.

Jump to

Keyboard shortcuts

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