Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(cost): stop pricing calls for models missing from the catalog

Steven Enamakel5cc338de93e2
diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs
index d698765a73..5afcf50a7d 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs
@@ -136,18 +136,22 @@ impl SpanCollector {
}
// Pricing basis so Langfuse cost figures are auditable against the
// client-side estimator (USD per million tokens).
- attrs.insert(
- "gen_ai.pricing.input_per_mtok_usd".to_string(),
- json_f64(pricing.input_per_mtok_usd),
- );
- attrs.insert(
- "gen_ai.pricing.cached_input_per_mtok_usd".to_string(),
- json_f64(pricing.cached_input_per_mtok_usd),
- );
- attrs.insert(
- "gen_ai.pricing.output_per_mtok_usd".to_string(),
- json_f64(pricing.output_per_mtok_usd),
- );
+ // Omitted for a model the catalog does not price: a made-up basis
+ // would make the trace's cost look audited when it is not.
+ if let Some(pricing) = pricing {
+ attrs.insert(
+ "gen_ai.pricing.input_per_mtok_usd".to_string(),
+ json_f64(pricing.input_per_mtok_usd),
+ );
+ attrs.insert(
+ "gen_ai.pricing.cached_input_per_mtok_usd".to_string(),
+ json_f64(pricing.cached_input_per_mtok_usd),
+ );
+ attrs.insert(
+ "gen_ai.pricing.output_per_mtok_usd".to_string(),
+ json_f64(pricing.output_per_mtok_usd),
+ );
+ }
log::debug!(
"[agent-tracing] generation span model={labeled_model} \
diff --git a/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs b/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs
index 7286485c12..5f67a8f5b7 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs
@@ -489,11 +489,13 @@ fn observation_to_progress(obs: &AgentObservation, state: &mut ReplayState) -> V
// `usage_carry` side-channel, which is not an `AgentEvent` and is not
// journalled (§2a of the C4 parity plan), so the projection prices
// the call with the same estimator the live path uses as its floor.
- // The token counts are exact; `cost_usd` is an estimate.
+ // The token counts are exact; `cost_usd` is a catalog estimate, and
+ // adds nothing for a model the catalog does not price.
state.cost_usd += crate::agent::cost::estimate_call_cost_usd(
&state.model,
&crate::inference::provider::BilledUsage::from_counts(usage.input_tokens, usage.output_tokens).with_cached_input_tokens(usage.cache_read_tokens).with_cache_creation_tokens(usage.cache_creation_tokens).with_reasoning_tokens(usage.reasoning_tokens),
- );
+ )
+ .unwrap_or(0.0);
state.input_tokens += usage.input_tokens;
state.output_tokens += usage.output_tokens;
state.cached_input_tokens += usage.cache_read_tokens;
diff --git a/crates/openhuman-core/src/agent/stop_hooks.rs b/crates/openhuman-core/src/agent/stop_hooks.rs
index d98adde600..69a1480d1f 100644
--- a/crates/openhuman-core/src/agent/stop_hooks.rs
+++ b/crates/openhuman-core/src/agent/stop_hooks.rs
@@ -99,7 +99,9 @@ impl StopHook for BudgetStopHook {
reason: format!("invalid budget cap configured: max_usd={}", self.max_usd),
};
}
- let spent = ctx.cost.total_usd();
+ // A cap can only bite on spend it can see: calls of unknown cost add
+ // nothing here rather than a made-up rate.
+ let spent = ctx.cost.cost.known_usd;
if spent >= self.max_usd {
StopDecision::Stop {
reason: format!("turn cost ${spent:.4} reached cap ${:.4}", self.max_usd),
diff --git a/crates/openhuman-core/src/inference/tokenjuice/savings.rs b/crates/openhuman-core/src/inference/tokenjuice/savings.rs
index 4fd2ea0294..8bacba83a4 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/savings.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/savings.rs
@@ -149,10 +149,12 @@ pub fn record(
/// Cost (USD) of sending `tokens_saved` as input to `model`, using the per-model
/// input price. Tool results enter the next turn's context as input tokens, so
-/// the input price is the relevant rate.
+/// the input price is the relevant rate. `0.0` for a model the catalog does
+/// not price: the saving is then counted in tokens only, not guessed in USD.
fn cost_saved_usd(model: &str, tokens_saved: u64) -> f64 {
- let pricing = crate::agent::cost::lookup_pricing(model);
- (tokens_saved as f64) / 1_000_000.0 * pricing.input_per_mtok_usd
+ crate::agent::cost::lookup_pricing(model).map_or(0.0, |pricing| {
+ (tokens_saved as f64) / 1_000_000.0 * pricing.input_per_mtok_usd
+ })
}
fn persist(st: &State) {