Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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`).
Expand Down
57 changes: 57 additions & 0 deletions core/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,41 @@ pub fn default_model_pricing() -> std::collections::HashMap<String, ModelPricing
pricing.insert("gpt-4o-mini".to_string(), ModelPricing::new(0.15, 0.6));
pricing.insert("gpt-4-turbo".to_string(), ModelPricing::new(10.0, 30.0));

// Every other model id and alias from the `llm-prices` table. Entries
// above take precedence and are never overwritten.
#[cfg(feature = "llm-prices")]
for row in llm_prices::all() {
if let (Some(input), Some(output)) = (row.input, row.output) {
for id in std::iter::once(row.model).chain(row.aliases.iter().copied()) {
pricing
.entry(id.to_string())
.or_insert_with(|| ModelPricing::new(input, output));
}
}
}

pricing
}

/// Look up pricing for a model id.
///
/// Checks [`default_model_pricing`] first. With the `llm-prices` feature, ids
/// that are not in the registry verbatim (provider prefixes such as
/// `anthropic/`, Bedrock ids, dated or undated Anthropic ids) are resolved
/// through `llm_prices::lookup`.
pub fn lookup_model_pricing(model: &str) -> Option<ModelPricing> {
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
// ============================================================================
Expand Down Expand Up @@ -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();
Expand Down