pub struct ModelPrice {
pub input: u64,
pub output: u64,
pub cache_read: u64,
pub cache_write: u64,
}Expand description
One model’s prices: USD per million tokens, in micro-USD (1e-6 USD).
Integers so a price and a derived Cost stay Eq and serde-stable, and
so summary()’s $ is reproducible to the last digit. Default is the
all-zero price — a known free model, which is Some(ModelPrice::default())
and never None.
Fields§
§input: u64Price of one million uncached prompt tokens.
output: u64Price of one million completion tokens.
cache_read: u64Price of one million prompt tokens served from the provider’s cache.
A cached read is a SUBSET of input_tokens on the
chat-completions wire (rig maps usage.prompt_tokens_details .cached_tokens, i.e. tokens already inside prompt_tokens), so a cached
token is billed at THIS rate instead of input — never on top of it.
cache_write: u64Price of one million tokens written to the cache. 0 for most
providers (models.dev omits the field when the provider does not report
it); it is not part of input’s accounting.
Implementations§
Source§impl ModelPrice
impl ModelPrice
Sourcepub fn cost_numerator(&self, usage: &Usage) -> u128
pub fn cost_numerator(&self, usage: &Usage) -> u128
One turn’s cost numerator: Σ tokens × rate, i.e. micro-USD × 1e6.
Contract:
cache_read_tokensis billed atModelPrice::cache_read, the remainder ofinput_tokensatModelPrice::input(the subset rule).cache_read_tokensis clamped toinput_tokensso a provider that over-reports cannot underflow the remainder.cache_write_tokensis billed atModelPrice::cache_writeon top of that; a turn reporting no cache field pays the fullinputrate.- the value is the un-truncated numerator so a caller folding many turns
sums numerators and divides ONCE (
cost_of); one turn’s answer isModelPrice::micro_usd.
Does NOT promise: tier rates, or that the provider reported usage at all
(a Usage::default() turn costs 0 — the caller decides whether a turn
counted).
Trait Implementations§
Source§impl Clone for ModelPrice
impl Clone for ModelPrice
impl Copy for ModelPrice
Source§impl Debug for ModelPrice
impl Debug for ModelPrice
Source§impl Default for ModelPrice
impl Default for ModelPrice
impl Eq for ModelPrice
Source§impl PartialEq for ModelPrice
impl PartialEq for ModelPrice
impl StructuralPartialEq for ModelPrice
Auto Trait Implementations§
impl Freeze for ModelPrice
impl RefUnwindSafe for ModelPrice
impl Send for ModelPrice
impl Sync for ModelPrice
impl Unpin for ModelPrice
impl UnsafeUnpin for ModelPrice
impl UnwindSafe for ModelPrice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.