diff --git a/Cargo.lock b/Cargo.lock index a5c5a1f3e..7d300320c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1023,6 +1023,7 @@ dependencies = [ "flate2", "futures", "libc", + "llm-prices", "notify", "regex", "reqwest 0.13.1", @@ -3928,6 +3929,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" +[[package]] +name = "llm-prices" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8687beff4d5ceb2b1a5fc5f242df4f2c107ca92609f47d30fab584591157d9dd" + [[package]] name = "lock_api" version = "0.4.14" diff --git a/src/cortex-cli/Cargo.toml b/src/cortex-cli/Cargo.toml index d00660a33..d58f9514d 100644 --- a/src/cortex-cli/Cargo.toml +++ b/src/cortex-cli/Cargo.toml @@ -59,6 +59,7 @@ uuid = { workspace = true } toml = { workspace = true } toml_edit = { workspace = true } serde_yaml = "0.9" +llm-prices = "1.8.0" serde = { workspace = true } ctor = "0.5" base64 = { workspace = true } diff --git a/src/cortex-cli/src/stats_cmd.rs b/src/cortex-cli/src/stats_cmd.rs index 1e407503e..44945a91a 100644 --- a/src/cortex-cli/src/stats_cmd.rs +++ b/src/cortex-cli/src/stats_cmd.rs @@ -216,6 +216,16 @@ fn get_model_pricing(model: &str) -> ModelPricing { } } + // Dated, source-cited list prices for known model ids. + if let Some(p) = llm_prices::lookup(model) { + if let (Some(input), Some(output)) = (p.input, p.output) { + return ModelPricing { + input_per_million: input, + output_per_million: output, + }; + } + } + // 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 { @@ -724,6 +734,16 @@ mod tests { assert_eq!(infer_provider("deepseek-chat"), "deepseek"); } + #[test] + fn test_current_model_list_prices() { + // Opus 4.5 is $5/$25, not the Opus 4 rate of $15/$75. + let cost = calculate_cost("claude-opus-4-5", 1_000_000, 1_000_000); + assert!((cost - 30.0).abs() < 0.001); + // o3 is $2/$8. + let cost = calculate_cost("o3", 1_000_000, 1_000_000); + assert!((cost - 10.0).abs() < 0.001); + } + #[test] fn test_calculate_cost() { // Claude Sonnet 4: $3/$15 per 1M