The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(inference): preserve explicitly reported zero charges in native usage
Steven Enamakel4ef2f326a715
diff --git a/crates/openhuman-core/src/inference/provider/model.rs b/crates/openhuman-core/src/inference/provider/model.rsindex c02b3b9500..d13f6f67e6 100644--- a/crates/openhuman-core/src/inference/provider/model.rs+++ b/crates/openhuman-core/src/inference/provider/model.rs@@ -119,7 +119,21 @@ fn response_to_model_response(content.push(block);}let report = response.usage.as_ref().map(billed_usage_report);- let usage = report.as_ref().map(ProviderUsageReport::to_usage);+ let usage = report.as_ref().map(|report| {+ let mut usage = report.to_usage();+ // Preserve the difference between an explicitly reported free call and+ // an unknown charge in TinyAgents' durable native Usage. The generic+ // ProviderUsageReport conversion intentionally only records positive+ // amounts; OpenHuman's provider DTO also carries an explicit-zero fact.+ if report.charge_reported+ && !report.cost_is_estimate+ && report.charged_amount_usd.is_finite()+ && report.charged_amount_usd == 0.0+ {+ usage.charged_amount = Some(tinyinference_llm::usage::ChargedAmount::usd_micros(0));+ }+ usage+ });let finish_reason = if tool_calls.is_empty() {"stop"} else {diff --git a/crates/openhuman-core/src/inference/provider/model_g1_usage_tests_tests.rs b/crates/openhuman-core/src/inference/provider/model_g1_usage_tests_tests.rsindex a631e0400c..7adc06f991 100644--- a/crates/openhuman-core/src/inference/provider/model_g1_usage_tests_tests.rs+++ b/crates/openhuman-core/src/inference/provider/model_g1_usage_tests_tests.rs@@ -69,6 +69,25 @@ fn no_billing_metadata_leaves_raw_clean() {assert_eq!(recovered.input_tokens, 5);}+#[test]+fn explicitly_reported_zero_charge_survives_in_native_usage() {+ let chat = ChatResponse {+ text: Some("free route".to_string()),+ usage: Some(BilledUsage::from_counts(5, 3).with_charged_usd(0.0)),+ ..Default::default()+ };++ let response = response_to_model_response(&chat, &empty_registry(), false);+ assert_eq!(+ response+ .usage+ .and_then(|usage| usage.charged_amount)+ .map(|charge| charge.micros),+ Some(0),+ "native journal usage must retain known-free versus unknown"+ );+}+#[test]fn provider_neutral_total_cost_metadata_is_recovered() {let model_response = ModelResponse {