pricing

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pricing maps Claude model IDs to per-million-token USD rates and computes cost for a given token mix.

Rates are based on Anthropic's published pricing page. The table is deliberately small and easy to update: when Anthropic changes prices, edit baseRates, update docs/decisions.md with the date and reason, and adjust the arithmetic tests to match.

Cache semantics follow Anthropic's published multipliers applied to the model's input rate:

cache read         = 0.1  × input rate
cache write 5m     = 1.25 × input rate
cache write 1h     = 2.0  × input rate

The multipliers are centralized in one place (below) so a future Anthropic change only needs a single edit.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownModel = errors.New("unknown model")

ErrUnknownModel is returned when RatesFor sees a model identifier not in the pricing table. Callers should log and skip the event rather than halting the watcher.

Functions

func Cost

func Cost(r Rates, u Usage) float64

Cost computes the total USD cost for a given (Rates, Usage) pair. Zero-cost calls are valid and return 0 without error.

func CostForModel

func CostForModel(model string, u Usage) (float64, error)

CostForModel is the convenience one-shot: look up the model, then price the usage. Returns ErrUnknownModel if the model is unknown.

func KnownModels

func KnownModels() []string

KnownModels returns a sorted list of model IDs in the pricing table. Useful for `budgetclaw pricing list` and for fuzzing tests.

Types

type Rates

type Rates struct {
	InputPerMTok        float64
	OutputPerMTok       float64
	CacheReadPerMTok    float64
	CacheWrite5mPerMTok float64
	CacheWrite1hPerMTok float64
}

Rates is the per-million-token cost in USD for one model.

func RatesFor

func RatesFor(model string) (Rates, error)

RatesFor returns the pricing rates for a model, including derived cache rates. Unknown models produce ErrUnknownModel.

type Usage

type Usage struct {
	Input        int
	Output       int
	CacheRead    int
	CacheWrite5m int
	CacheWrite1h int
}

Usage is the token counts we price. All fields are optional; zero counts contribute zero cost.

Jump to

Keyboard shortcuts

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