pub struct ModelPricing {
pub input_per_million: u64,
pub output_per_million: u64,
pub cache_read_per_million: Option<u64>,
}Expand description
Pricing information for a specific model.
All prices are in microdollars per million tokens. For example,
a price of $3.00 per million input tokens would be 3_000_000.
§Example
use llm_stack::usage::{ModelPricing, Usage};
// Claude 3.5 Sonnet pricing (as of early 2024)
let pricing = ModelPricing {
input_per_million: 3_000_000, // $3.00 / MTok
output_per_million: 15_000_000, // $15.00 / MTok
cache_read_per_million: Some(300_000), // $0.30 / MTok
};
let usage = Usage {
input_tokens: 1_000_000,
output_tokens: 100_000,
..Default::default()
};
let cost = pricing.compute_cost(&usage).unwrap();
assert_eq!(cost.total_microdollars(), 4_500_000); // $3 input + $1.50 outputFields§
§input_per_million: u64Cost per million input tokens in microdollars.
output_per_million: u64Cost per million output tokens in microdollars.
cache_read_per_million: Option<u64>Cost per million cache-read tokens in microdollars (if applicable).
Implementations§
Source§impl ModelPricing
impl ModelPricing
Sourcepub fn compute_cost(&self, usage: &Usage) -> Option<Cost>
pub fn compute_cost(&self, usage: &Usage) -> Option<Cost>
Computes the cost for the given usage.
Returns None if the calculation would overflow.
Trait Implementations§
Source§impl Clone for ModelPricing
impl Clone for ModelPricing
Source§fn clone(&self) -> ModelPricing
fn clone(&self) -> ModelPricing
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ModelPricing
impl Debug for ModelPricing
Source§impl PartialEq for ModelPricing
impl PartialEq for ModelPricing
impl Eq for ModelPricing
impl StructuralPartialEq for ModelPricing
Auto Trait Implementations§
impl Freeze for ModelPricing
impl RefUnwindSafe for ModelPricing
impl Send for ModelPricing
impl Sync for ModelPricing
impl Unpin for ModelPricing
impl UnwindSafe for ModelPricing
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