#6774·openhuman

Usage page and local cost ledger under-report real spend by 67-91% per turn

Author: graycyrusCreated Sep 29, 2026Updated Sep 29, 2026

Summary

The Usage page (and its underlying local cost ledger, costs.jsonl) systematically under-reports real spend. In every real-call test run, actual backend billing came in 67-91% higher than what the local ledger recorded for the same turns, and the entire gap traces to one large, delayed charge per turn that never reaches the local ledger at all.

Problem

What's expected: the Usage page's "7-day total" / "Month to date" / per-turn cost should reflect what the account is actually billed.

What happens: each chat turn writes 1-2 rows to costs.jsonl (one per LLM model call, via the event bridge → record_provider_usage). Real billing (GET /payments/credits/transactions, exposed via openhuman.billing_get_transactions) shows 4-6 charges for the same turn. The local ledger only ever captures the LLM completion cost; a second, larger charge per turn is invisible to it.

Reproduced 3 times, real account, real money, isolated single-turn tests each time (fresh thread, nothing else running):

Test Tools used Ledger cost Billed cost Gap Dominant unmatched charge Delay after last ledger row
1 resolve_time (batch run) $0.001209 $0.003039 +151% $0.0024073 ~3s
2 resolve_time (isolated) $0.001173 $0.002245 +91% $0.0016877 ~16s
3 none (one-word reply, no tools) $0.000570 $0.0017487 +207% $0.0015103 ~10.4s

Test 3 is the key result: a turn with zero tool calls still produces the same class of delayed, ledger-invisible charge, in the same $0.0015-0.0024 range as the tool-using turns. This rules out "tool/integration billing" as the sole explanation (a plausible first theory, since trackIntegrationUsage/trackInference are separate billing paths on the backend) — whatever this charge is, it happens on every turn, not only tool-using ones.

Also found while tracing this (backend repo, src/):

  • CreditTransaction.action is hardcoded to the literal string 'USAGE_DEDUCTION' for every spend transaction (balanceService.ts, createSpendTransaction) — the richer metadata (spendBucket, apiKeyId) that trackUsage.ts builds is attached only to the separate LedgerEntry collection (via recordUsageDeduction), never to the CreditTransaction the client actually reads. So the client has no way to attribute any individual charge to what caused it — this is what blocked narrowing down the delayed charge further from the app/API side.
  • Confirmed finalizeDeduction → createSpendTransaction writes exactly one CreditTransaction per charge event (not split by funding source), so charge-count mismatches are real distinct events, not one event fragmented into multiple rows.

What this needs to close it out: someone with backend DB access pulling the actual LedgerEntry row(s) for one of the reproduced charges above (e.g. amount 0.0015103, one of the timestamps in the table) and reading its metadata.integrationId / spendBucket — that field will say exactly what generated it. From the client side alone this can't go further.

Also affects: the Usage page's own "hosted billing is separate" framing undersells this — it reads as a footnote, not as "this page is missing up to 2x of your real spend."

Solution (optional)

Not proposing a fix here since the root cause (what the delayed charge actually is) isn't confirmed yet — see "what this needs to close it out" above. Once identified, the likely fix is wiring that call site to also emit into OpenHuman's local cost tracker (record_provider_usage / the event bridge), the same class of fix as #6720.

Acceptance criteria

  • Root cause identified — the backend LedgerEntry/charge source for the per-turn delayed charge is confirmed (via metadata.integrationId/spendBucket on a real reproduced charge).
  • Repro gone — once identified, the charge either reaches the local ledger (so the Usage page reflects it) or is confirmed as something that legitimately shouldn't (documented why).
  • Regression safety — a test (or documented manual check) that a turn's local ledger total is within a small tolerance of its real billed total.
  • … — Other verify-before-close items.

Related

  • #6720 (separate, already-fixed bug: the local cost tracker not following the active workspace after sign-in, and a duplicate host: ledger row per call — unrelated to this gap, found while investigating the same Usage page)