pub struct ModelPrice {
pub input_per_mtok: f64,
pub output_per_mtok: f64,
}Expand description
Published price of a model, in USD per 1,000,000 tokens.
Fields§
§input_per_mtok: f64USD per 1M input (prompt) tokens.
output_per_mtok: f64USD per 1M output (completion) tokens.
Implementations§
Source§impl ModelPrice
impl ModelPrice
Sourcepub fn cost(&self, input: u64, output: u64) -> f64
pub fn cost(&self, input: u64, output: u64) -> f64
Cost in USD of input/output tokens at this price.
Sourcepub fn cost_with_cache(
&self,
input: u64,
cache_write: u64,
cache_read: u64,
output: u64,
) -> f64
pub fn cost_with_cache( &self, input: u64, cache_write: u64, cache_read: u64, output: u64, ) -> f64
Cost in USD including prompt-cache traffic, which bills at different rates than plain input.
Cached prompt tokens are not free and not priced like ordinary input:
- writing to the cache costs a premium (
CACHE_WRITE_MULTIPLIER), because the provider stores the prefix; - reading from it is heavily discounted (
CACHE_READ_MULTIPLIER).
Ignoring both — which is what counting input_tokens alone does — understates a cached
request by orders of magnitude. A 190k-token cached prefix reports an input_tokens of
about 20, so the receipt reads a fraction of a cent for a call that cost most of a dollar,
and [budget] caps fed by that total never trip.
Trait Implementations§
Source§impl Clone for ModelPrice
impl Clone for ModelPrice
Source§fn clone(&self) -> ModelPrice
fn clone(&self) -> ModelPrice
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ModelPrice
Source§impl Debug for ModelPrice
impl Debug for ModelPrice
Source§impl<'de> Deserialize<'de> for ModelPrice
impl<'de> Deserialize<'de> for ModelPrice
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for ModelPrice
impl PartialEq for ModelPrice
Source§impl Serialize for ModelPrice
impl Serialize 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
Mutably borrows from an owned value. Read more