pub struct ModelPricing {
pub input_per_1m: f64,
pub output_per_1m: f64,
pub context_window: usize,
pub max_output_tokens: usize,
pub quality_tier: u8,
/* private fields */
}Expand description
Per-model pricing information.
Rates are expressed in USD per 1M tokens, matching the convention used by most provider pricing pages.
Fields§
§input_per_1m: f64Cost per 1M input tokens in USD.
output_per_1m: f64Cost per 1M output tokens in USD.
context_window: usizeMaximum context window in tokens.
max_output_tokens: usizeMaximum output tokens.
quality_tier: u8Quality tier (1-5, 5 = highest). Used by
crate::Router::select_by_complexity and ModelPricing::efficiency.
Implementations§
Source§impl ModelPricing
impl ModelPricing
Sourcepub fn new(input_per_1m: f64, output_per_1m: f64) -> Self
pub fn new(input_per_1m: f64, output_per_1m: f64) -> Self
Create pricing from just the USD rates, filling the remaining fields
with the same defaults as ModelPricing::default (128k context,
4,096 max output, quality tier 3).
Sourcepub fn with_context_window(self, context_window: usize) -> Self
pub fn with_context_window(self, context_window: usize) -> Self
Set the context window (builder style).
Sourcepub fn with_max_output_tokens(self, max_output_tokens: usize) -> Self
pub fn with_max_output_tokens(self, max_output_tokens: usize) -> Self
Set the maximum output tokens (builder style).
Sourcepub fn with_quality_tier(self, quality_tier: u8) -> Self
pub fn with_quality_tier(self, quality_tier: u8) -> Self
Set the quality tier, 1-5 (builder style).
Sourcepub fn with_updated_at_unix(self, updated_at_unix: u64) -> Self
pub fn with_updated_at_unix(self, updated_at_unix: u64) -> Self
Stamp the entry with an explicit refresh time, as Unix seconds
(builder style). See ModelPricing::updated_at_unix.
Sourcepub fn with_updated_at_now(self) -> Self
pub fn with_updated_at_now(self) -> Self
Stamp the entry with the current wall-clock time as Unix seconds (builder style). Convenience for code that builds refresh snapshots.
Sourcepub fn updated_at_unix(&self) -> Option<u64>
pub fn updated_at_unix(&self) -> Option<u64>
Unix-seconds timestamp of the last refresh from an external source,
if known (None = freshness unknown).
Sourcepub fn is_newer_than(&self, other: &Self) -> bool
pub fn is_newer_than(&self, other: &Self) -> bool
Whether self should replace other in a PricingTable::merge:
true when self carries a strictly newer updated_at_unix stamp, or
any stamp at all while other carries none. Two unstamped entries
(or an older stamp) never win.
Sourcepub fn cost(&self, input_tokens: usize, output_tokens: usize) -> f64
pub fn cost(&self, input_tokens: usize, output_tokens: usize) -> f64
Calculate the cost in USD for a given number of input/output tokens.
Sourcepub fn efficiency(&self) -> f64
pub fn efficiency(&self) -> f64
Cost efficiency: quality tier per average-USD cost.
Higher is better. Free models (both rates zero) return f64::MAX.