Skip to content

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

fix(agent): represent unknown model call cost as none

Steven Enamakel05e503ba19b1
diff --git a/crates/openhuman-core/src/agent/progress.rs b/crates/openhuman-core/src/agent/progress.rs
index 44692a6d58..a7cf88e76e 100644
--- a/crates/openhuman-core/src/agent/progress.rs
+++ b/crates/openhuman-core/src/agent/progress.rs
@@ -403,9 +403,9 @@ pub enum AgentProgress {
cache_creation_tokens: u64,
/// Reasoning/thinking tokens, when the provider reports them.
reasoning_tokens: u64,
- /// Best-available USD cost for this single call (charged when the
- /// backend reported it, else a catalog estimate).
- cost_usd: f64,
+ /// USD cost of this single call: the backend's reported charge, else
+ /// the catalog's list-price estimate; `None` when neither exists.
+ cost_usd: Option<f64>,
},
/// The turn completed with a final text response.
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 5afcf50a7d..d5ba8f16ce 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
@@ -46,7 +46,7 @@ impl SpanCollector {
cached_input_tokens: u64,
cache_creation_tokens: u64,
reasoning_tokens: u64,
- cost_usd: f64,
+ cost_usd: Option<f64>,
now_unix_ms: u64,
) {
// Resolve the parent + start basis: a child call nests under its
@@ -113,7 +113,10 @@ impl SpanCollector {
json_u64(reasoning_tokens),
);
}
- attrs.insert("gen_ai.usage.cost_usd".to_string(), json_f64(cost_usd));
+ // An unpriced call carries no cost attribute rather than a $0 one.
+ if let Some(cost_usd) = cost_usd {
+ attrs.insert("gen_ai.usage.cost_usd".to_string(), json_f64(cost_usd));
+ }
// Time to first token. Deltas only arrive on streamed calls, so a
// unary call carries neither attribute. Clamped to the span start: the
// iteration span opening is the call's approximate start.
@@ -157,7 +160,7 @@ impl SpanCollector {
"[agent-tracing] generation span model={labeled_model} \
iteration={iteration} child={} in={input_tokens} out={output_tokens} \
cached={cached_input_tokens} ttft_ms={:?} ttft_text_ms={:?} \
- cost_usd={cost_usd:.6} input_captured={} output_captured={}",
+ cost_usd={cost_usd:?} input_captured={} output_captured={}",
subagent_task_id.is_some(),
first_deltas
.any_unix_ms
@@ -215,15 +218,17 @@ impl SpanCollector {
span.attributes
.insert(key.to_string(), json_u64(prior.saturating_add(add)));
}
- let prior_cost = span
- .attributes
- .get("gen_ai.usage.cost_usd")
- .and_then(serde_json::Value::as_f64)
- .unwrap_or(0.0);
- span.attributes.insert(
- "gen_ai.usage.cost_usd".to_string(),
- json_f64(prior_cost + cost_usd),
- );
+ if let Some(cost_usd) = cost_usd {
+ let prior_cost = span
+ .attributes
+ .get("gen_ai.usage.cost_usd")
+ .and_then(serde_json::Value::as_f64)
+ .unwrap_or(0.0);
+ span.attributes.insert(
+ "gen_ai.usage.cost_usd".to_string(),
+ json_f64(prior_cost + cost_usd),
+ );
+ }
}
return;
}
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 5f67a8f5b7..147bd2c09b 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs
@@ -448,7 +448,7 @@ fn observation_to_progress(obs: &AgentObservation, state: &mut ReplayState) -> V
// reported a cache write.
cache_creation_tokens: usage.cache_creation_tokens,
reasoning_tokens: usage.reasoning_tokens,
- cost_usd: 0.0,
+ cost_usd: None,
}];
if scope.is_none() {
let turn_input = input.as_ref().map(json_content_text);
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rs
index 1508664778..b8fb924bed 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs
@@ -1212,7 +1212,7 @@ pub(crate) fn spawn_progress_bridge(
// stay on the cumulative TurnCostUpdated rollup.
log::debug!(
"[web_channel][bridge] model_call_completed model={model} iter={iteration} \
- in={input_tokens} out={output_tokens} cost_usd={cost_usd:.6} request_id={request_id}"
+ in={input_tokens} out={output_tokens} cost_usd={cost_usd:?} request_id={request_id}"
);
}
}