pricing

package
v0.90.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: AGPL-3.0 Imports: 12 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 answers what a model's tokens cost, in US dollars, for the per-session cost readout. It is keyed by model id and knows nothing about who ran the model: a second provider's reader gets its prices from the same table.

The table has two layers. A small baked one (prices.json, the Claude and OpenAI models known at build time) is the floor, so a fresh install prices correctly with no network at all — a machine that never reaches the network still shows a Codex session's cost, at the rate that shipped. A model the floor has never heard of — one released after this build — triggers a single remote refresh, whose result is cached under the config dir and overlays the floor from then on. Nothing here blocks a caller: the refresh runs in the background and the lookup that missed simply reports "unknown", which the readout renders as absent rather than as zero. Pricing a model at nothing is the one answer this package must never give.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rate

type Rate struct {
	Input        float64 `json:"input"`
	Output       float64 `json:"output"`
	CacheRead    float64 `json:"cacheRead"`
	CacheWrite   float64 `json:"cacheWrite"`
	CacheWrite1h float64 `json:"cacheWrite1h"`
}

Rate is one model's price per token, in USD, split the way a provider bills them: fresh input, generated output, a cache hit, and writing the cache — which is two prices, because a cache entry is priced by how long it is kept. CacheWrite is the short-lived entry (five minutes); CacheWrite1h is the hour one, and it is the more expensive of the two.

func (Rate) Cost

func (r Rate) Cost(t Tokens) (float64, bool)

Cost is what these tokens cost at this rate, in USD. ok is false when the tokens include hour-long cache writes and the rate carries no price for them: billing them at the five-minute price is a total that is quietly too small, and this package's whole rule is that a number it cannot stand behind is not reported at all.

A rate can miss that price because the source table never published one for the model. The next refresh any unknown model triggers overlays the whole remote table, so this heals on its own if the price appears there — it is not worth a refresh of its own.

type Table

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

Table resolves model ids to rates. The zero value is not usable — call New.

func New

func New() *Table

New returns a table backed by the baked prices, overlaid with the cached refresh if one was written by an earlier run.

func (*Table) Rate

func (t *Table) Rate(model string) (Rate, bool)

Rate returns the model's price per token. ok is false for a model the table cannot price — the caller must report no cost at all, never a zero one — and schedules the one refresh that may teach it, so the next turn can answer.

type Tokens

type Tokens struct {
	Input        int
	Output       int
	CacheRead    int
	CacheWrite   int
	CacheWrite1h int
}

Tokens is a turn's (or a whole conversation's) token counts, named after the counters a provider transcript reports, with the cache write split by the entry's lifetime the way the bill is.

Jump to

Keyboard shortcuts

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