pub struct ModelPricing {
pub model_pattern: String,
pub input_cost_per_million: f64,
pub output_cost_per_million: f64,
pub currency: Option<String>,
}Expand description
Per-model pricing configuration.
The model_pattern supports glob-style matching:
gpt-4*matchesgpt-4,gpt-4-turbo,gpt-4o, etc.claude-3-*matches all Claude 3 variants
Fields§
§model_pattern: StringModel name or pattern (glob-style matching with *)
input_cost_per_million: f64Cost per million input tokens
output_cost_per_million: f64Cost per million output tokens
currency: Option<String>Optional currency override (defaults to parent config currency)
Implementations§
Source§impl ModelPricing
impl ModelPricing
Sourcepub fn new(
pattern: impl Into<String>,
input_cost: f64,
output_cost: f64,
) -> Self
pub fn new( pattern: impl Into<String>, input_cost: f64, output_cost: f64, ) -> Self
Create new model pricing with the given pattern and costs.
Sourcepub fn matches(&self, model: &str) -> bool
pub fn matches(&self, model: &str) -> bool
Check if this pricing rule matches the given model name.
Sourcepub fn calculate_cost(&self, input_tokens: u64, output_tokens: u64) -> f64
pub fn calculate_cost(&self, input_tokens: u64, output_tokens: u64) -> f64
Calculate cost for the given token counts.
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<'de> Deserialize<'de> for ModelPricing
impl<'de> Deserialize<'de> for ModelPricing
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
Auto Trait Implementations§
impl Freeze for ModelPricing
impl RefUnwindSafe for ModelPricing
impl Send for ModelPricing
impl Sync for ModelPricing
impl Unpin for ModelPricing
impl UnsafeUnpin 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