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 ¶
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 ¶
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
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
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).
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 ¶
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
AsOf is the packaged table's `as_of` date: when its prices were last checked against the providers' price lists.
func (Table) EstimateCost ¶
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 ¶
Has reports whether the model has a row of its own, as opposed to falling through to `default`.
func (Table) ResolveCost ¶
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.