From 13b1c6669971923fbd6dcc4c4e591f9b9f879f8f Mon Sep 17 00:00:00 2001 From: Matthew Charles Busel Date: Sat, 14 Nov 2026 22:38:26 -0500 Subject: [PATCH] feat(telemetry): optional llm-prices feature for current model pricing default_model_pricing() only knows claude-sonnet-4, three Claude 3 models, gpt-4o, gpt-4o-mini and gpt-4-turbo, so cost lookups for Claude 4.5+, GPT-5.x and Gemini come back empty. The new optional `llm-prices` feature fills the registry from the llm-prices table without overwriting the hand-written entries, and lookup_model_pricing() resolves provider prefixes, Bedrock ids and dated/undated Anthropic ids. Default builds are unchanged. --- Cargo.lock | 7 ++++++ core/Cargo.toml | 5 ++++ core/src/telemetry.rs | 57 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3488168b..72ae2fa6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,7 @@ dependencies = [ "htmd", "html2text", "ignore", + "llm-prices", "lopdf", "opentelemetry 0.27.1", "opentelemetry-otlp", @@ -2649,6 +2650,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" +[[package]] +name = "llm-prices" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9606d5d2a074a2de43ae1e9d76ffdb95e5ffb870533b89caccaa4aa2d4abf2d6" + [[package]] name = "lock_api" version = "0.4.14" diff --git a/core/Cargo.toml b/core/Cargo.toml index de7d4005..b8ef54e8 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -104,6 +104,8 @@ uuid = { version = "1.6", features = ["v4", "serde"] } chrono = { version = "0.4", features = ["serde"] } # Cron parsing for the `serve` schedules (gated behind the `serve` feature). cron = { version = "0.12", optional = true } +# Dated, source-cited LLM price table (optional, gated by `llm-prices` feature). +llm-prices = { version = "1.1", optional = true } rquickjs = { version = "0.11.0", features = ["futures"] } # S3-compatible workspace backend (optional, gated by `s3` feature) @@ -128,6 +130,9 @@ telemetry = [ "dep:opentelemetry-otlp", "dep:tracing-opentelemetry", ] +# Extend `default_model_pricing()` with the `llm-prices` table (Claude 4.5+, +# GPT-5.x, Gemini, DeepSeek). Hand-written entries keep their values. +llm-prices = ["dep:llm-prices"] # Enable AHP (Agent Harness Protocol) integration for external supervision ahp = ["dep:a3s-ahp"] # Enable the S3-compatible workspace backend (`S3WorkspaceBackend`). diff --git a/core/src/telemetry.rs b/core/src/telemetry.rs index 24a63992..8b302bd8 100644 --- a/core/src/telemetry.rs +++ b/core/src/telemetry.rs @@ -193,9 +193,41 @@ pub fn default_model_pricing() -> std::collections::HashMap Option { + if let Some(pricing) = default_model_pricing().remove(model) { + return Some(pricing); + } + #[cfg(feature = "llm-prices")] + if let Some(row) = llm_prices::lookup(model) { + if let (Some(input), Some(output)) = (row.input, row.output) { + return Some(ModelPricing::new(input, output)); + } + } + None +} + // ============================================================================ // Tool Metrics // ============================================================================ @@ -706,6 +738,31 @@ mod tests { assert!(debug_str.contains("15.0")); } + #[test] + fn test_lookup_model_pricing_registry_entry() { + let pricing = lookup_model_pricing("claude-sonnet-4-20250514").unwrap(); + assert_eq!(pricing.input_per_million, 3.0); + assert_eq!(pricing.output_per_million, 15.0); + assert!(lookup_model_pricing("not-a-real-model").is_none()); + } + + #[cfg(feature = "llm-prices")] + #[test] + fn test_llm_prices_extends_registry() { + let pricing = default_model_pricing(); + // Hand-written entries keep their values. + let turbo = pricing.get("gpt-4-turbo").unwrap(); + assert_eq!(turbo.input_per_million, 10.0); + assert_eq!(turbo.output_per_million, 30.0); + // Newer models come from the llm-prices table. + assert!(pricing.contains_key("claude-sonnet-4-6")); + assert!(pricing.contains_key("gpt-5")); + assert!(pricing.contains_key("gemini-2.5-pro")); + // Provider prefixes and dated ids resolve through lookup. + assert!(lookup_model_pricing("anthropic/claude-sonnet-4-6").is_some()); + assert!(lookup_model_pricing("claude-haiku-4-5-20251001").is_some()); + } + #[test] fn test_default_model_pricing_all_positive() { let pricing = default_model_pricing();