[BUG] generate_report() always prints "$0.0000" Est. Cost Savings — estimate_cost() is called with no provider and the None is coerced to 0.0
Summary
headroom.generate_report() renders the Est. Cost Savings tile as $0.0000 for every user, no matter how many tokens were saved. The number is not missing data — it is a fabricated zero produced by a call that cannot return a price.
The report calls headroom.utils.estimate_cost() without a provider, and that function returns None before it does anything else (headroom/utils.py:238-239):
if provider is None:
return NoneThe call site then swallows the None:
# Estimate cost savings (using gpt-4o pricing)
cost_before = estimate_cost(stats["total_tokens_before"], 0, "gpt-4o") or 0.0
cost_after = estimate_cost(stats["total_tokens_after"], 0, "gpt-4o") or 0.0
estimated_savings = format_cost(cost_before - cost_after)headroom/reporting/generator.py:339-342 (measured on main at d13e196, which is the chore: release 0.39.1 (#3807) commit, so this is the code that shipped as 0.39.1).
None from estimate_cost() means "I cannot price this", not "this cost $0". Coercing it to 0.0 turns an unavailable price into a claim, and the claim is the headline tile of the report. This is the same failure mode #3744 just fixed for negative savings ("report negative savings instead of flooring them at zero") — a derived money figure being silently replaced by a nicer-looking constant.
Every other caller of this function passes a provider (headroom/client.py:793 passes provider=self._provider); the report is the only caller that doesn't, which is why nothing else in the product shows this.
Reproduction
No network, no API keys, no Claude/Codex needed — it writes two rows into a SQLite metrics DB and renders the documented report:
from datetime import datetime
from headroom.config import RequestMetrics
from headroom.reporting import generate_report
from headroom.storage import create_storage
import re
storage = create_storage("sqlite:///tmp/r.db")
for i, (before, after) in enumerate([(200_000, 60_000), (150_000, 45_000)]):
storage.save(RequestMetrics(
request_id=f"req-{i}", timestamp=datetime(2026, 9, 27, 10, i),
model="gpt-4o", stream=False, mode="optimize",
tokens_input_before=before, tokens_input_after=after, tokens_output=1000))
html = open(generate_report("sqlite:///tmp/r.db", "/tmp/report.html")).read()
for label in ("Tokens Saved", "Est. Cost Savings"):
m = re.search(rf"<h3>{label}</h3>\s*<div class=\"value[^\"]*\">([^<]*)</div>", html)
print(f"{label:18s} -> {m.group(1).strip()}")Actual output:
Tokens Saved -> 245,000
Est. Cost Savings -> $0.0000What the tile should say — the same gpt-4o rate card the report already names, priced through the repo's own credential-free pricer:
ModelRegistry.estimate_cost('gpt-4o', 350000, 0) -> 0.8750
ModelRegistry.estimate_cost('gpt-4o', 105000, 0) -> 0.2625
savings -> $0.6125And the two primitives, called exactly as the report calls them:
utils.estimate_cost(100000, 0, "gpt-4o") -> None # no provider
ModelRegistry.estimate_cost("gpt-4o", 100000, 0) -> 0.25 # LiteLLM's bundled price databaseWhy the test suite doesn't catch it
tests/test_reporting.py:258-262 replaces estimate_cost with a stub that has the behavior the real function lacks:
monkeypatch.setattr(
generator,
"estimate_cost",
lambda tokens, output_tokens, model: {100: 2.0, 0: None}[tokens],
)The stub takes three positional args and returns a price for the first one, so the test asserts estimated_savings == "$2.00" (:277) against a function that in production returns None on every input. tests/test_reporting.py:305 does the same with lambda *args: 0.0. Both are green; the tile is always $0.0000.
Suggested fix
headroom/models/registry.py:815-834 already exposes ModelRegistry.estimate_cost(model, input_tokens, output_tokens), which prices from LiteLLM's bundled database — no provider instance, no credentials, no network. Route the report's two price lookups through it, and when pricing is genuinely unavailable render unavailable rather than $0.0000, so the tile never asserts something it did not compute.
I'd keep the reference rate card as-is ("gpt-4o") and not widen the change — the hardcoded model is a separate question about what a model-agnostic report should price against.
Then replace the two self-confirming stubs with assertions against the real pricing path, so the regression cannot come back.
Environment
headroom-aisource atmain=d13e196(chore: release 0.39.1 (#3807)),_versionreports0.39.2-dev- Python 3.14.4, macOS 27 arm64
uv sync --extra dev --no-install-project, package imported from the source tree- Not tested: Windows, the
headroom-ai[proxy]wheel's Rust path (this module is pure Python and has no Rust mirror), and the rendered report in a browser — the tile text is read out of the generated HTML, not screenshotted.
I'm going to open the PR for this.
Source: headroomlabs-ai/headroom