Documentation
¶
Overview ¶
Package pricing turns token usage into an estimated USD cost. Prices come from GET /api/models when the server exposes them, with bench.yaml `pricing:` entries as overrides/fallbacks. Anything unknown yields no cost (the report simply omits the column) rather than an error.
Index ¶
- type Table
- func (t *Table) Cost(model string, promptTokens, completionTokens int) (cost float64, ok bool)
- func (t *Table) DefaultModelID() string
- func (t *Table) Fetch(ctx context.Context, baseURL string) error
- func (t *Table) Has(model string) bool
- func (t *Table) Len() int
- func (t *Table) Merge(m map[string]spec.ModelPricing)
- func (t *Table) SetToken(token, trustedBaseURL string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table maps model ids to prices. It is safe for concurrent use.
func New ¶
func New(overrides map[string]spec.ModelPricing) *Table
New returns an empty table seeded with overrides (may be nil).
func (*Table) Cost ¶
Cost estimates the USD cost of usage on model. ok is false when the model or its price is unknown, or usage is nil.
func (*Table) DefaultModelID ¶
DefaultModelID is the registry default reported by /api/models ("" if unknown).
func (*Table) Fetch ¶
Fetch loads GET {baseURL}/api/models into t (merging with any overrides already present; explicit overrides win). It tolerates every known shape of the pricing fields and returns an error only for transport/HTTP failures — callers treat that as "no server pricing" and continue.
func (*Table) Merge ¶
func (t *Table) Merge(m map[string]spec.ModelPricing)
Merge adds or replaces prices.
func (*Table) SetToken ¶
SetToken makes Fetch authenticate with a personal access token (`Authorization: Bearer …`), for deployments whose model catalog is not public. The token is sent only to trustedBaseURL's origin; a base URL named by a suite file is fetched anonymously. Empty keeps every request anonymous.