Skip to main content

Module pricing

Module pricing 

Source
Expand description

Per-model prices for recognized providers, so /usage can report a $ cost instead of a bare token count.

Twin of crate::limits, from the same source and the same gate: the authoritative catalog is models.dev, whose opencode-go entry (api = https://opencode.ai/zen/go/v1) carries cost { input, output, cache_read, cache_write } in USD per million tokens. [OPENCODE_GO] is a snapshot of that table, and model_price is gated by the existing crate::limits::is_opencode_go — so the two tables can never disagree about which provider they describe.

Units are micro-USD per Mtok, integers, never floats: a price stays Eq/serde-stable, a cost is byte-identical across a round-trip, and the arithmetic is one integer division away from the dollars summary() prints.

Who calls it: the actor’s Request::Usage reply (see crate::protocol::Request::Usage) folds the transcript with crate::stats::session_stats and then prices it with cost_of; the front-ends only render the Cost it produced.

NOT in v1 (named, deliberate — brief Q5):

  • tiers / context_over_200k — a request past the tier size bills up to ~5× the base rate, so a tiered model’s number is an undercount; [OPENCODE_GO] stores the base rate only.
  • a per-model base_url from crate::streamfn::LlmOpts::model_profiles — pricing uses the session’s launch base_url for every turn.
  • a config file. A const table mirrors limits.rs; behaviour is not configured (AGENTS.md §Conventions).

Structs§

ModelPrice
One model’s prices: USD per million tokens, in micro-USD (1e-6 USD).

Functions§

cost_of
The session’s $ cost: fold every Assistant { usage: Some(u), model } at the price of model — the message’s own id when set, else fallback_model — under base_url, summing micro-USD.
model_price
Prices for model served from base_url, when we recognize the provider.