diff --git a/src/cortex-cli/src/stats_cmd.rs b/src/cortex-cli/src/stats_cmd.rs index 1e407503..549e8c90 100644 --- a/src/cortex-cli/src/stats_cmd.rs +++ b/src/cortex-cli/src/stats_cmd.rs @@ -202,23 +202,23 @@ fn get_cortex_home() -> PathBuf { fn get_model_pricing(model: &str) -> ModelPricing { // First check for custom pricing from environment let custom_pricing = load_custom_pricing(); - let model_lower = model.to_lowercase(); + let model_key = normalize_model_key(model); // Check for exact match in custom pricing - if let Some(pricing) = custom_pricing.get(&model_lower) { + if let Some(pricing) = custom_pricing.get(&model_key) { return pricing.clone(); } // Check for partial match in custom pricing (e.g., "gpt-4o" matches "gpt-4o-mini") for (key, pricing) in &custom_pricing { - if model_lower.contains(key) { + if model_key.contains(key) { return pricing.clone(); } } // Fall back to default pricing (may be outdated - users can override via CORTEX_PRICING_*) // Pricing per 1M tokens (as of late 2024/early 2025 - may change) - match model { + match model_key.as_str() { // Anthropic m if m.contains("claude-opus-4") || m.contains("opus-4") => ModelPricing { input_per_million: 15.0, @@ -294,6 +294,10 @@ fn get_model_pricing(model: &str) -> ModelPricing { } } +fn normalize_model_key(model: &str) -> String { + model.to_lowercase() +} + /// Calculate cost for token usage. fn calculate_cost(model: &str, input_tokens: u64, output_tokens: u64) -> f64 { let pricing = get_model_pricing(model); @@ -406,14 +410,13 @@ async fn collect_stats(sessions_dir: &PathBuf, cli: &StatsCli) -> Result