Skip to main content

OfferingPricing

Struct OfferingPricing 

Source
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: String

Provider id serving the offering.

§wire_model_id: String

Provider-owned wire id the price applies to.

§canonical_model: Option<String>

Canonical model identity, when the offering carries one.

§currency: Currency

Billing 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: PricingProvenance

Where 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

Source

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.

Source

pub fn has_any_price(&self) -> bool

Whether any per-token price is known.

Source

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.

Source

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.

Source

pub fn price_per_million(&self, class: TokenClass) -> Option<f64>

Per-million price for one canonical class, when published.

Source

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.

Source

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

Source

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

Source§

fn clone(&self) -> OfferingPricing

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OfferingPricing

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OfferingPricing

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for OfferingPricing

Source§

fn eq(&self, other: &OfferingPricing) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for OfferingPricing

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for OfferingPricing

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more