usage

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package usage holds the cost-observability pricing table (design 003).

Cost is computed in micro-USD (µUSD). A convenient identity keeps the table readable: because 1 USD = 1e6 µUSD and prices are quoted per 1e6 tokens, the µUSD cost of one token equals the model's USD-per-1M-tokens price. So a price of $3 / 1M input tokens is exactly 3 µUSD per input token.

The table ships as an editable default. Prices drift; unknown models return (0, false) so the UI shows tokens only, flagged with a tilde, rather than inventing a dollar figure. Overrides are applied via SetOverrides.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CostMicroUSD

func CostMicroUSD(model string, in, out, cacheRead, cacheWrite int) (int64, bool)

CostMicroUSD computes the µUSD cost of a call. The bool is false when the model is unpriced (unknown), in which case cost is 0 and the caller should flag the figure rather than treat 0 as free.

func FormatUSD

func FormatUSD(microUSD int64) string

FormatUSD renders a µUSD amount as a dollar string like "$1.42".

func KnownModels

func KnownModels() []string

KnownModels returns the sorted list of priced model prefixes (for docs/tests).

func SetOverrides

func SetOverrides(m map[string]Price)

SetOverrides installs config-supplied pricing entries (keyed by lowercased model prefix). They take precedence over the default table. Passing nil clears overrides.

Types

type Price

type Price struct {
	In         float64 // uncached input
	Out        float64 // generated output
	CacheRead  float64 // input served from prompt cache
	CacheWrite float64 // input written to prompt cache
}

Price is the per-1M-token price (USD) for each token class, which is also the per-token cost in µUSD (see package doc).

Jump to

Keyboard shortcuts

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