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(proxy): skip pricing lookup for passthrough:* models (#2585)

AxelRayf87848cf78db
diff --git a/headroom/proxy/cost.py b/headroom/proxy/cost.py
index 81025ebca..3bf0e4979 100644
--- a/headroom/proxy/cost.py
+++ b/headroom/proxy/cost.py
@@ -965,6 +965,9 @@ class CostTracker:
cache_read_tokens: Tokens served from cache (~10% of input rate)
cache_write_tokens: Tokens written to cache (~125% of input rate)
"""
+ if model.startswith("passthrough:"):
+ return None
+
litellm = _get_litellm_module()
if litellm is None:
_warn_pricing_once(
@@ -1479,6 +1482,8 @@ class CostTracker:
# ``_tokens_saved_by_model`` alone would drop such a model from the table
# entirely rather than merely under-report it.
for model in sorted(set(self._tokens_saved_by_model) | set(self._tool_saved_by_model)):
+ if model.startswith("passthrough:"):
+ continue
compression_saved = self._tokens_saved_by_model.get(model, 0)
tool_saved = self._tool_saved_by_model.get(model, 0)
# What the "Tokens Saved" column means: everything Headroom kept off
@@ -1513,6 +1518,8 @@ class CostTracker:
total_billed_input_tokens = 0
total_input_tokens = 0
for model in self._tokens_saved_by_model:
+ if model.startswith("passthrough:"):
+ continue
saved = self._tokens_saved_by_model[model]
sent = self._tokens_sent_by_model.get(model, 0)
cr = self._api_cache_read_by_model.get(model, 0)
@@ -1546,6 +1553,8 @@ class CostTracker:
# cache-aware valuation below is reported alongside it.
savings_usd = 0.0
for model in self._tokens_saved_by_model:
+ if model.startswith("passthrough:"):
+ continue
saved = self._tokens_saved_by_model[model]
if saved <= 0:
continue
@@ -1635,8 +1644,16 @@ class CostTracker:
"total_tool_tokens_saved": total_tool_saved,
"total_input_tokens": total_input_tokens,
"total_input_cost_usd": round(cost_with_headroom, 4),
- "cache_write_5m_tokens": sum(self._api_cache_write_5m_by_model.values()),
- "cache_write_1h_tokens": sum(self._api_cache_write_1h_by_model.values()),
+ "cache_write_5m_tokens": sum(
+ tokens
+ for model, tokens in self._api_cache_write_5m_by_model.items()
+ if not model.startswith("passthrough:")
+ ),
+ "cache_write_1h_tokens": sum(
+ tokens
+ for model, tokens in self._api_cache_write_1h_by_model.items()
+ if not model.startswith("passthrough:")
+ ),
"per_model": per_model,
# Input-only, unchanged: budgets, the per-model table and the
# persistent savings tracker all read it as input spend.
diff --git a/tests/test_cost_pricing_warning_dedup.py b/tests/test_cost_pricing_warning_dedup.py
index 520bef07a..91c885ad1 100644
--- a/tests/test_cost_pricing_warning_dedup.py
+++ b/tests/test_cost_pricing_warning_dedup.py
@@ -63,3 +63,31 @@ def test_litellm_unavailable_warns_once_per_model(monkeypatch, caplog):
unavailable = [r for r in caplog.records if "LiteLLM not available" in r.getMessage()]
assert len(unavailable) == 1
+
+
+def test_passthrough_model_skips_pricing_without_warning(monkeypatch, caplog):
+ import headroom.proxy.cost as cost_mod
+
+ class _FakeLiteLLM:
+ @staticmethod
+ def cost_per_token(**_kwargs):
+ raise AssertionError("cost_per_token must not be called")
+
+ monkeypatch.setattr(cost_mod, "_get_litellm_module", lambda: _FakeLiteLLM())
+ tracker = cost_mod.CostTracker()
+
+ with caplog.at_level(logging.WARNING, logger="headroom.proxy"):
+ assert tracker.estimate_cost("passthrough:count_tokens", 100, 50) is None
+
+ assert not caplog.records
+
+
+def test_stats_omit_passthrough_models(cost_tracker):
+ cost_tracker.record_tokens("passthrough:count_tokens", 10, 90)
+ cost_tracker.record_tokens("glm-5.2", 20, 80)
+
+ stats = cost_tracker.stats()
+
+ assert set(stats["per_model"]) == {"glm-5.2"}
+ assert stats["total_tokens_saved"] == 20
+ assert stats["total_input_tokens"] == 80