pricing

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 6 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 is the fallback price table the dashboard uses to put a number on a dispatch nobody billed for.

Ported from `orchestrator/dashboard/pricing.py`. The contract is the part worth keeping in mind: a recorded `cost_usd` above zero is the truth and is never second-guessed — that is what the provider charged. The table is only consulted when the recorded cost is zero, which is the normal case for opencode and local codex, where there is no billing API to ask.

Index

Constants

View Source
const (
	// SourceNone: no spend row at all — nothing ran.
	SourceNone = "none"
	// SourceReported: at least one row carries a cost the CLI billed.
	SourceReported = "reported"
	// SourceEstimated: nothing was billed, but the rows' tokens were priced
	// from the table.
	SourceEstimated = "estimated"
	// SourceNoData: rows exist with neither a billed cost nor tokens to
	// price — unknown, not free.
	SourceNoData = "no_data"
)

Where a summed cost's dollars come from. The dashboard's budget summary (`cost_source`) and `orch status` (`cost_source`) both use these words.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModelPrice

type ModelPrice struct {
	Input      float64
	Output     float64
	CacheRead  float64
	CacheWrite float64
}

ModelPrice is USD per million tokens. CacheRead and CacheWrite are the prompt-cache rates; zero means the row has none and cached tokens are priced as Input.

func (ModelPrice) Cost

func (p ModelPrice) Cost(t Tokens) float64

Cost is what a dispatch of this size costs. Negative token counts are read as zero rather than as a refund.

type Sum added in v0.31.0

type Sum struct {
	Rows      int
	Reported  float64
	Estimated float64
}

Sum adds spend rows up under ResolveCost's rule, keeping the two kinds of dollar apart: Reported is what the CLIs billed, Estimated what the table priced for the rows that billed nothing. A surface that shows one number shows Total and says when Estimated is part of it; one that sits next to a real bill (a budget) shows Reported and Estimated side by side.

func (*Sum) Add added in v0.31.0

func (s *Sum) Add(t Table, recordedCost float64, model string, tokens Tokens)

Add counts one spend row: its recorded cost when above zero, else its tokens priced from t (ResolveCost; a row with no model is priced as `default`, and one with no tokens adds nothing).

func (Sum) Source added in v0.31.0

func (s Sum) Source() string

Source says what the dollars are; see the Source* constants. A sum with both kinds is "reported": part of it is a bill, and Estimated says how much is not.

func (Sum) Total added in v0.31.0

func (s Sum) Total() float64

Total is billed plus estimated: what the dashboard's Usage page shows.

type Table

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

Table is the layered price list: a project's own `pricing.yaml` on top of the packaged defaults.

A project key REPLACES the default row of the same name rather than merging into it — you cannot tweak `input` and inherit `output`. One row is one complete price, which is the only version of this anybody can hold in their head while reading a YAML file.

func Load

func Load(projectRoot string) Table

Load reads the embedded defaults and layers a project override on top.

Every failure is silent and local: a missing file, unreadable YAML, a row that is not a price. A dashboard that refused to render because somebody hand-edited `pricing.yaml` would be trading a wrong number for no page at all, and this table's whole purpose is being an estimate.

projectRoot may be empty, meaning "defaults only".

func (Table) AsOf added in v0.31.0

func (t Table) AsOf() string

AsOf is the packaged table's `as_of` date: when its prices were last checked against the providers' price lists.

func (Table) EstimateCost

func (t Table) EstimateCost(model string, tokens Tokens) float64

EstimateCost looks up and computes in one call.

func (Table) ForModel

func (t Table) ForModel(model string) ModelPrice

ForModel resolves a price: the exact name, then `default`, then the floor.

func (Table) Has

func (t Table) Has(model string) bool

Has reports whether the model has a row of its own, as opposed to falling through to `default`.

func (Table) Models

func (t Table) Models() []string

Models lists every key, sorted, for a UI that wants to show the table.

func (Table) ResolveCost

func (t Table) ResolveCost(recordedCost float64, model string, tokens Tokens) float64

ResolveCost is the rule the whole package exists for: a recorded cost above zero wins, and anything else — zero, missing, negative — is estimated from tokens.

Note that a recorded cost of exactly zero is treated as "not recorded", not as "free". That is Python's rule and it is the right one here: the backends that genuinely cost nothing to call are the same ones that report no cost at all, so the two are indistinguishable in the row.

type Tokens added in v0.31.0

type Tokens struct {
	In, Out, CacheRead, CacheWrite int
}

Tokens is one dispatch's usage. In counts every input token, cache included; CacheRead and CacheWrite are the parts of In read from and written to the prompt cache (state.Spend's convention).

Jump to

Keyboard shortcuts

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