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 ¶
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.