pub struct OfferingPricing {
pub provider: String,
pub wire_model_id: String,
pub canonical_model: Option<String>,
pub currency: Currency,
pub input_per_million: Option<f64>,
pub output_per_million: Option<f64>,
pub cache_read_per_million: Option<f64>,
pub cache_write_per_million: Option<f64>,
pub provenance: PricingProvenance,
pub effective_at: Option<u64>,
pub endpoint_fingerprint: Option<String>,
}Expand description
A provider/offering-scoped pricing row.
Prices are per million tokens in Currency. Any field may be unknown
(None); OfferingPricing::estimate_cost refuses to invent a number for a
used class whose price is unknown.
Fields§
§provider: StringProvider id serving the offering.
wire_model_id: StringProvider-owned wire id the price applies to.
canonical_model: Option<String>Canonical model identity, when the offering carries one.
currency: CurrencyBilling currency.
input_per_million: Option<f64>Input price per million tokens.
output_per_million: Option<f64>Output price per million tokens.
cache_read_per_million: Option<f64>Cache-read price per million tokens.
cache_write_per_million: Option<f64>Cache-write price per million tokens.
provenance: PricingProvenanceWhere the price came from.
effective_at: Option<u64>Unix seconds the price was fetched / became effective, when known.
endpoint_fingerprint: Option<String>Fingerprint of the base URL this price was fetched from, for
PricingProvenance::ProviderLive rows.
This is the same non-secret SHA-256 digest the catalog cache scopes on
(see crate::catalog::base_url_fingerprint) — never the URL itself.
It exists so a live row can be proven to price the endpoint a turn was
actually served on; a row whose fingerprint does not match the route
is a different billing surface, not a fresher price for this one.
Implementations§
Source§impl OfferingPricing
impl OfferingPricing
Sourcepub fn from_catalog_offering(offering: &CatalogOffering) -> Option<Self>
pub fn from_catalog_offering(offering: &CatalogOffering) -> Option<Self>
Derive a pricing row from a catalog offering’s cost, when priced.
Returns None when the offering carries no cost, or a cost object with
no concrete price field — those routes are unknown, not free, and the
caller should render them as such (see route_pricing_sku).
Models.dev cost values are USD per million tokens, so the currency is
Currency::Usd; provenance and effective_at follow the offering’s
CatalogSource.
Sourcepub fn has_any_price(&self) -> bool
pub fn has_any_price(&self) -> bool
Whether any per-token price is known.
Sourcepub fn is_stale(&self, now_unix: u64, max_age_secs: u64) -> bool
pub fn is_stale(&self, now_unix: u64, max_age_secs: u64) -> bool
Whether this price is older than max_age_secs at now_unix.
Rows without an effective_at (bundled snapshot / user override) carry
no fetch clock and are not considered age-stale here; live rows are.
Sourcepub fn live_pricing_defect(
&self,
route_endpoint_fingerprint: Option<&str>,
now_unix: Option<u64>,
max_age_secs: u64,
) -> Option<LivePricingDefect>
pub fn live_pricing_defect( &self, route_endpoint_fingerprint: Option<&str>, now_unix: Option<u64>, max_age_secs: u64, ) -> Option<LivePricingDefect>
Why this row cannot be trusted as an authoritative live price, if so.
Returns None for rows that are not PricingProvenance::ProviderLive
(a bundled snapshot, a documented hand price, or a user override carries
no fetch clock to go stale against) and for live rows that are both
fresh and fingerprint-matched to route_endpoint_fingerprint.
A live row with any defect must not be labelled provider_live nor used
as complete pricing: it is either older than max_age_secs or priced for
a different endpoint. Callers fail closed and receipt the returned
defect. route_endpoint_fingerprint of None means the caller could not
determine the endpoint at all, which is itself a defect — a live row can
never be confirmed to price an unknown route.
Sourcepub fn price_per_million(&self, class: TokenClass) -> Option<f64>
pub fn price_per_million(&self, class: TokenClass) -> Option<f64>
Per-million price for one canonical class, when published.
Sourcepub fn unpriced_used_classes(&self, usage: &TokenUsage) -> Vec<TokenClass>
pub fn unpriced_used_classes(&self, usage: &TokenUsage) -> Vec<TokenClass>
Classes this turn actually used that carry no published price.
Non-empty means Self::estimate_cost fails closed for this usage; the
returned classes are exactly the reason why, so callers can report the
gap instead of presenting a silently under-counted total.
Sourcepub fn estimate_cost(&self, usage: &TokenUsage) -> Option<f64>
pub fn estimate_cost(&self, usage: &TokenUsage) -> Option<f64>
Estimate the cost of usage in this row’s Currency.
Returns None if any usage class with a non-zero token count has an
unknown price — the estimate would otherwise silently under-report. With
all-zero usage the cost is Some(0.0).
Sourcepub fn to_route_sku(&self) -> PricingSku
pub fn to_route_sku(&self) -> PricingSku
Project to the coarse route-facing meter shape.
Returns PricingSku::Token only when an input or output rate is known.
The route-layer Token shape carries only input/output rates, so a row
priced only on cache classes would become a Token with no visible
rates — misleading at the route layer. Such rows degrade to
PricingSku::UnknownOrStale here while their cache rates remain usable
through OfferingPricing::estimate_cost.
Trait Implementations§
Source§impl Clone for OfferingPricing
impl Clone for OfferingPricing
Source§fn clone(&self) -> OfferingPricing
fn clone(&self) -> OfferingPricing
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more