pub struct PriceTable { /* private fields */ }Expand description
A lookup from provider/model to ModelPrice.
ponytail: the embedded PriceTable::defaults are a calibration knob, not gospel —
list prices drift and enterprise contracts differ. In prod, load overrides from config
via PriceTable::with_override; the defaults just make the common case work out of the box.
Implementations§
Source§impl PriceTable
impl PriceTable
Sourcepub fn defaults() -> Self
pub fn defaults() -> Self
Built-in prices for the common frontier models (USD / 1M tokens, approximate list prices — a starting point to be overridden per deployment).
Sourcepub fn with_override(self, model: impl Into<String>, price: ModelPrice) -> Self
pub fn with_override(self, model: impl Into<String>, price: ModelPrice) -> Self
Insert or replace a model’s price, returning self for chaining.
Sourcepub fn get(&self, model: &str) -> Option<ModelPrice>
pub fn get(&self, model: &str) -> Option<ModelPrice>
Look up a model’s price by its provider/model key.
Sourcepub fn cost_usd(&self, model: &str, input: u64, output: u64) -> Result<f64>
pub fn cost_usd(&self, model: &str, input: u64, output: u64) -> Result<f64>
Cost in USD of a call to model with the given token counts.
Only correct for a response with no prompt-cache traffic. Any path pricing a real
provider response should call PriceTable::cost_usd_with_cache instead and pass the
cache counters — this one silently prices a cached call at a small fraction of what it
cost, which is how a ~$0.72 request once banked a $0.0001 receipt. Reserved for
counterfactuals and synthetic token counts, where there is no cache traffic by
construction.
§Errors
Returns Error::UnknownModel if the model has no price entry.
Sourcepub fn cost_usd_with_cache(
&self,
model: &str,
input: u64,
cache_write: u64,
cache_read: u64,
output: u64,
) -> Result<f64>
pub fn cost_usd_with_cache( &self, model: &str, input: u64, cache_write: u64, cache_read: u64, output: u64, ) -> Result<f64>
As PriceTable::cost_usd, including prompt-cache traffic at its own rates.
§Errors
Returns Error::UnknownModel if the model has no price entry.
Sourcepub fn baseline_usd(
&self,
top_model: &str,
input: u64,
output: u64,
) -> Result<f64>
pub fn baseline_usd( &self, top_model: &str, input: u64, output: u64, ) -> Result<f64>
The counterfactual baseline: what the request would have cost had it gone straight to
top_model (the ladder’s top rung) with the served token counts.
This is an estimate — the top model might have emitted a different number of tokens — but token counts of served output are the fair, auditable proxy the trace records.
§Errors
Returns Error::UnknownModel if top_model has no price entry.