pub struct PricingCatalog { /* private fields */ }Expand description
In-memory pricing catalog: per (provider, model), a price history sorted
ascending by effective_at. Built once from the embedded TOML.
Implementations§
Source§impl PricingCatalog
impl PricingCatalog
Sourcepub fn parse(toml_text: &str) -> Result<Self, Error>
pub fn parse(toml_text: &str) -> Result<Self, Error>
Parse a catalog from TOML text. Used by catalog over the embedded
file; exposed for tests that want to parse a synthetic catalog.
Sourcepub fn latest(&self, provider: &str, model: &str) -> Option<ModelPricing>
pub fn latest(&self, provider: &str, model: &str) -> Option<ModelPricing>
The current (most recently effective) rate for (provider, model),
or None if the model is not in the catalog.
Sourcepub fn at(
&self,
provider: &str,
model: &str,
at: DateTime<Utc>,
) -> Option<ModelPricing>
pub fn at( &self, provider: &str, model: &str, at: DateTime<Utc>, ) -> Option<ModelPricing>
The rate that was in effect at at for (provider, model) — the most
recent entry whose effective_at <= at. If at predates every known
entry, falls back to the earliest entry (best-effort historical replay
rather than reporting no price). None only when the model is unknown.
Sourcepub fn latest_for_provider(&self, provider: &str) -> Vec<(String, ModelPricing)>
pub fn latest_for_provider(&self, provider: &str) -> Vec<(String, ModelPricing)>
Every model’s current rate for provider, as (model, pricing) pairs.
Order is unspecified. Used by adapters that build a model→rate map at
construction time (the OpenAI-compatible providers).
Sourcepub fn catalog_max_effective_at(&self) -> Option<DateTime<Utc>>
pub fn catalog_max_effective_at(&self) -> Option<DateTime<Utc>>
The newest effective_at across every entry in the catalog — i.e. the
date of the most recent manual rate snapshot. Returns None only when
the catalog is empty (a build-time error in practice, because the
embedded file is non-empty and the parse is guarded by a unit test).
Use this as a freshness signal: if the returned date is far in the past it means pricing.toml has not been updated in a while.