diff --git a/litellm-rust/crates/cost/src/openai_cost.rs b/litellm-rust/crates/cost/src/openai_cost.rs index 829b595120a..6d2b77a51b2 100644 --- a/litellm-rust/crates/cost/src/openai_cost.rs +++ b/litellm-rust/crates/cost/src/openai_cost.rs @@ -1,13 +1,17 @@ use crate::error::CostError; use serde_json::Value; +use crate::call_type::CallTypes; use crate::non_token::{Charge, Unit, calculate}; use crate::wire::py_float; pub use crate::non_token::video_resolution_to_cost_field_suffix; pub fn cost_router(call_type: &str) -> &'static str { - if matches!(call_type, "transcription" | "atranscription") { + if matches!( + call_type.parse::(), + Ok(CallTypes::transcription | CallTypes::atranscription) + ) { "cost_per_second" } else { "cost_per_token" diff --git a/litellm-rust/crates/cost/src/together_cost.rs b/litellm-rust/crates/cost/src/together_cost.rs index 029b80ed5c0..efe23b5af36 100644 --- a/litellm-rust/crates/cost/src/together_cost.rs +++ b/litellm-rust/crates/cost/src/together_cost.rs @@ -5,6 +5,7 @@ use std::sync::LazyLock; use regex::Regex; use serde_json::Value; +use crate::call_type::CallTypes; use crate::catalog::ModelInfoCatalog; use crate::provider::LlmProviders; @@ -39,7 +40,10 @@ pub fn get_model_params_and_category( call_type: &str, thresholds: TogetherThresholds, ) -> String { - if matches!(call_type, "embedding" | "aembedding") { + if matches!( + call_type.parse::(), + Ok(CallTypes::embedding | CallTypes::aembedding) + ) { return get_model_params_and_category_embeddings(model_name, thresholds); } let name = model_name.to_ascii_lowercase(); diff --git a/litellm-rust/crates/cost/src/vertex_cost.rs b/litellm-rust/crates/cost/src/vertex_cost.rs index dfbfcdf2ebd..149f579884c 100644 --- a/litellm-rust/crates/cost/src/vertex_cost.rs +++ b/litellm-rust/crates/cost/src/vertex_cost.rs @@ -1,11 +1,13 @@ use jiff::Timestamp; use serde_json::Value; +use crate::call_type::CallTypes; use crate::catalog::{ModelCostRequest, ModelInfoCatalog}; use crate::cost_calculator::cost_per_token as catalog_cost_per_token; use crate::error::CostError; use crate::generic_cost::calculate_generic_cost_from_model_info_with_region; use crate::per_second::per_second_pricing_cost; +use crate::provider::LlmProviders; use crate::regional_uplift::get_vertex_regional_endpoint_uplift; use crate::responses_usage::ChatUsage; @@ -27,7 +29,11 @@ pub fn cost_router(model: &str, provider: &str, call_type: &str) -> CostRoute { ] .iter() .any(|name| model.contains(name)); - if provider == "vertex_ai" && (token_model || matches!(call_type, "embedding" | "aembedding")) { + let embedding = matches!( + call_type.parse::(), + Ok(CallTypes::embedding | CallTypes::aembedding) + ); + if LlmProviders::VERTEX_AI.matches(Some(provider)) && (token_model || embedding) { CostRoute::PerToken } else { CostRoute::PerCharacter