Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(pricing): suppress litellm's Provider List banner that corrupts perf JSON (#4197)

M Barrye01ad350dc71
diff --git a/headroom/pricing/litellm_pricing.py b/headroom/pricing/litellm_pricing.py
index 22d83984b..2a325330c 100644
--- a/headroom/pricing/litellm_pricing.py
+++ b/headroom/pricing/litellm_pricing.py
@@ -44,6 +44,10 @@ try:
del _os.environ[_leaked_key]
del _env_snapshot, _os
+ # Probing an unknown model makes litellm print() its "Provider List"
+ # banner to stdout, which corrupts `headroom perf --format json`.
+ litellm.suppress_debug_info = True
+
LITELLM_AVAILABLE = True
except ImportError:
litellm = None # type: ignore[assignment]
diff --git a/tests/test_cli_perf_format.py b/tests/test_cli_perf_format.py
index b2dcaf934..70de765c3 100644
--- a/tests/test_cli_perf_format.py
+++ b/tests/test_cli_perf_format.py
@@ -230,6 +230,39 @@ def test_perf_json_format(runner, monkeypatch):
assert data["overhead"]["optimization_ms"]["p95_ms"] == 11.8
+def test_perf_json_survives_litellm_provider_banner(tmp_path):
+ """Pricing an unknown model makes litellm print() its "Provider List"
+ banner to stdout unless suppressed. The perf CLI imports no module that
+ suppresses it, so the pricing module has to.
+
+ Runs in a fresh interpreter: the flag is set at import time, and
+ reloading the module in-process would leave stale class references
+ behind for later tests.
+ """
+ import subprocess
+ import sys
+
+ pytest.importorskip("litellm")
+ script = (
+ "import json, litellm\n"
+ "assert not litellm.suppress_debug_info\n"
+ "from headroom.perf.analyzer import build_perf_summary, PerfReport, PerfRecord\n"
+ "rec = PerfRecord(timestamp='2026-06-05 10:00:00,000', request_id='hr_1',\n"
+ " model='no-such-model-banner-probe', num_messages=1, tokens_before=10,\n"
+ " tokens_after=5, tokens_saved=5, cache_read=0, cache_write=0,\n"
+ " cache_hit_pct=0, optimization_ms=1.0, transforms=[])\n"
+ "print(json.dumps(build_perf_summary(PerfReport(perf_records=[rec]))))\n"
+ )
+ env = {k: v for k, v in os.environ.items() if k != "LITELLM_SUPPRESS_DEBUG_INFO"}
+ env["HOME"] = str(tmp_path)
+ result = subprocess.run(
+ [sys.executable, "-c", script], capture_output=True, text=True, env=env, timeout=120
+ )
+ assert result.returncode == 0, result.stderr
+ assert "Provider List" not in result.stdout
+ assert json.loads(result.stdout)["total_requests"] == 1
+
+
def test_perf_json_raw_is_array(runner, monkeypatch):
_patch_report(monkeypatch, _sample_report())
result = runner.invoke(main, ["perf", "--format", "json", "--raw"])