Skip to main content

ModelPricing

Struct ModelPricing 

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

Cost per 1M input tokens in USD.

§output_per_1m: f64

Cost per 1M output tokens in USD.

§context_window: usize

Maximum context window in tokens.

§max_output_tokens: usize

Maximum output tokens.

§quality_tier: u8

Quality tier (1-5, 5 = highest). Used by crate::Router::select_by_complexity and ModelPricing::efficiency.

Implementations§

Source§

impl ModelPricing

Source

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

Source

pub fn with_context_window(self, context_window: usize) -> Self

Set the context window (builder style).

Source

pub fn with_max_output_tokens(self, max_output_tokens: usize) -> Self

Set the maximum output tokens (builder style).

Source

pub fn with_quality_tier(self, quality_tier: u8) -> Self

Set the quality tier, 1-5 (builder style).

Source

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.

Source

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.

Source

pub fn updated_at_unix(&self) -> Option<u64>

Unix-seconds timestamp of the last refresh from an external source, if known (None = freshness unknown).

Source

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.

Source

pub fn cost(&self, input_tokens: usize, output_tokens: usize) -> f64

Calculate the cost in USD for a given number of input/output tokens.

Source

pub fn efficiency(&self) -> f64

Cost efficiency: quality tier per average-USD cost.

Higher is better. Free models (both rates zero) return f64::MAX.

Trait Implementations§

Source§

impl Clone for ModelPricing

Source§

fn clone(&self) -> Self

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 ModelPricing

Source§

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

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

impl Default for ModelPricing

Source§

fn default() -> Self

Placeholder pricing used to estimate cost for models that are not in the table ($1.00/1M input, $3.00/1M output, 128k context, 4,096 max output, tier 3, no freshness stamp).

Source§

impl PartialEq for ModelPricing

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ModelPricing

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.