pricing

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func (t *Table) Cost(model string, promptTokens, completionTokens int) (cost float64, ok bool)

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

func (t *Table) DefaultModelID() string

DefaultModelID is the registry default reported by /api/models ("" if unknown).

func (*Table) Fetch

func (t *Table) Fetch(ctx context.Context, baseURL string) error

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) Has

func (t *Table) Has(model string) bool

Has reports whether a price is known for model.

func (*Table) Len

func (t *Table) Len() int

Len returns the number of priced models.

func (*Table) Merge

func (t *Table) Merge(m map[string]spec.ModelPricing)

Merge adds or replaces prices.

func (*Table) SetToken

func (t *Table) SetToken(token, trustedBaseURL string)

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.

Jump to

Keyboard shortcuts

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