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): resolve MiniMax-M3 (provider prefix + pre-registration) (#1186)

Shreyas S K46dede36f9fb
diff --git a/headroom/pricing/litellm_pricing.py b/headroom/pricing/litellm_pricing.py
index 96d79e575..dff7c429a 100644
--- a/headroom/pricing/litellm_pricing.py
+++ b/headroom/pricing/litellm_pricing.py
@@ -76,10 +76,15 @@ def _resolve_litellm_model_uncached(model: str) -> str:
"o3-": "openai/",
"o4-": "openai/",
"gemini-": "google/",
+ "minimax-": "minimax/",
"deepseek-": "deepseek/",
}
+ # Case-insensitive prefix match: MiniMax uses mixed-case model
+ # names like "MiniMax-M3" (capital M's); we shouldn't require the
+ # user to lower-case their config to match.
+ model_lower = model.lower()
for pattern, prefix in prefixes.items():
- if model.startswith(pattern):
+ if model_lower.startswith(pattern):
prefixed = f"{prefix}{model}"
try:
litellm.cost_per_token(model=prefixed, prompt_tokens=1, completion_tokens=0)
@@ -89,6 +94,30 @@ def _resolve_litellm_model_uncached(model: str) -> str:
return model
+def _register_minimax_pricing() -> None:
+ """Pre-register MiniMax-M3 in litellm.model_cost from `minimax/MiniMax-M3`.
+
+ The proxy receives the bare model name `MiniMax-M3` from Claude Code.
+ LiteLLM's community pricing database only stores it under the
+ `minimax/MiniMax-M3` key. The resolver's `minimax-` prefix rule
+ handles the lookup; this pre-registration is a safety net so
+ `estimate_cost()` succeeds even if (a) the resolver cache is cold,
+ or (b) LiteLLM drops the prefixed entry in a future release.
+ Pricing mirrors the upstream DB (input $0.60/M, output $2.40/M,
+ cache read $0.12/M as of 2026-06). Re-check after LiteLLM updates.
+ """
+ if not LITELLM_AVAILABLE:
+ return
+ source_key = "minimax/MiniMax-M3"
+ if source_key not in litellm.model_cost:
+ return
+ if "MiniMax-M3" not in litellm.model_cost:
+ litellm.model_cost["MiniMax-M3"] = dict(litellm.model_cost[source_key])
+
+
+_register_minimax_pricing()
+
+
@dataclass
class LiteLLMModelPricing:
"""Pricing information from LiteLLM's database.
diff --git a/tests/test_pricing_litellm.py b/tests/test_pricing_litellm.py
index 19b0646f7..c088f06ac 100644
--- a/tests/test_pricing_litellm.py
+++ b/tests/test_pricing_litellm.py
@@ -95,3 +95,73 @@ def test_litellm_model_pricing_returns_none_for_unknown_models(monkeypatch) -> N
monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
monkeypatch.setattr(litellm_pricing, "litellm", SimpleNamespace(model_cost={}))
assert litellm_pricing.get_model_pricing("missing") is None
+
+
+def test_litellm_minimax_mixed_case_with_provider_prefix(monkeypatch) -> None:
+ """MiniMax-M3 must resolve via the `minimax/` prefix even though its
+ model name uses mixed case.
+
+ `resolve_litellm_model()` is what callers in `proxy/cost.py`,
+ `proxy/savings_tracker.py`, and `perf/analyzer.py` use to get a
+ key LiteLLM's own cost DB recognises. The upstream DB only stores
+ the entry under `minimax/MiniMax-M3`, so bare `MiniMax-M3` would
+ otherwise miss and the resolver would return the input unchanged.
+ """
+
+ def fake_cost_per_token(
+ model: str, prompt_tokens: int = 0, completion_tokens: int = 0
+ ) -> tuple[float, float]:
+ if model in fake_litellm.model_cost:
+ entry = fake_litellm.model_cost[model]
+ return (
+ entry["input_cost_per_token"] * prompt_tokens,
+ entry["output_cost_per_token"] * completion_tokens,
+ )
+ raise KeyError(f"unknown model: {model}")
+
+ fake_litellm = SimpleNamespace(
+ model_cost={
+ "minimax/MiniMax-M3": {
+ "input_cost_per_token": 0.0000006,
+ "output_cost_per_token": 0.0000024,
+ }
+ },
+ cost_per_token=fake_cost_per_token,
+ )
+ monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
+ monkeypatch.setattr(litellm_pricing, "litellm", fake_litellm)
+
+ # Bare mixed-case name resolves via the case-insensitive `minimax-` prefix.
+ assert litellm_pricing.resolve_litellm_model("MiniMax-M3") == "minimax/MiniMax-M3"
+
+
+def test_litellm_minimax_preregistration_safety_net(monkeypatch) -> None:
+ """When LiteLLM only ships the prefixed `minimax/MiniMax-M3` entry, the
+ module-load pre-registration should also expose the bare `MiniMax-M3`
+ key so `estimate_cost()` works on a cold resolver cache (since
+ `get_model_pricing` does not know about the `minimax/` prefix).
+ """
+ fake_litellm = SimpleNamespace(
+ model_cost={
+ "minimax/MiniMax-M3": {
+ "input_cost_per_token": 0.0000006,
+ "output_cost_per_token": 0.0000024,
+ }
+ }
+ )
+ monkeypatch.setattr(litellm_pricing, "LITELLM_AVAILABLE", True)
+ monkeypatch.setattr(litellm_pricing, "litellm", fake_litellm)
+
+ litellm_pricing._register_minimax_pricing()
+
+ assert "MiniMax-M3" in fake_litellm.model_cost
+ assert fake_litellm.model_cost["MiniMax-M3"]["input_cost_per_token"] == 0.0000006
+ # After pre-registration, bare-name estimate_cost works end-to-end.
+ assert (
+ litellm_pricing.estimate_cost("MiniMax-M3", input_tokens=1_000_000, output_tokens=100_000)
+ == 0.84
+ )
+ # Pre-registration must not clobber a user-customised bare entry.
+ fake_litellm.model_cost["MiniMax-M3"] = {"customised": True}
+ litellm_pricing._register_minimax_pricing()
+ assert fake_litellm.model_cost["MiniMax-M3"] == {"customised": True}