pricing

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModelPrice

type ModelPrice struct {
	InputPerMTok       float64 // cost per million input tokens
	OutputPerMTok      float64 // cost per million output tokens
	CachedInputPerMTok float64 // cost per million cached input tokens; 0 means same as InputPerMTok
}

ModelPrice holds per-million-token pricing for a model.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maps model names/prefixes to their pricing.

func New

func New() *Registry

New creates a Registry pre-loaded with bundled defaults.

func NewEmpty

func NewEmpty() *Registry

NewEmpty creates a Registry with no bundled defaults.

func (*Registry) Cost

func (r *Registry) Cost(model string, input, output, cachedInput int, providerCost float64) (float64, string)

Cost calculates the USD cost for a given model and token usage. Returns the cost and a source string: "provider" if providerCost > 0, "registry" if the model was found, "fallback" if the default rate was used, or "unknown" if no pricing is available.

func (*Registry) Lookup

func (r *Registry) Lookup(model string) (ModelPrice, bool)

Lookup returns the pricing for a model. Exact match is tried first, then longest prefix match.

func (*Registry) Register

func (r *Registry) Register(model string, price ModelPrice)

Register adds an exact-match model price.

func (*Registry) RegisterPrefix

func (r *Registry) RegisterPrefix(prefix string, price ModelPrice)

RegisterPrefix adds a prefix-match model price. Longer prefixes take priority. Duplicate prefixes are overwritten.

func (*Registry) SetFallbackRate

func (r *Registry) SetFallbackRate(ratePerKTokens float64)

SetFallbackRate sets the default rate per 1K tokens used when no model match is found. Set to 0 to disable the fallback (cost will be 0).

Jump to

Keyboard shortcuts

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