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): alias retired claude-3-sonnet to Sonnet-tier price, not Haiku (#2095)

Abhay Singh613796708393
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f5f7811f7..177c60446 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -102,6 +102,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Bug Fixes
+* **pricing:** map retired `claude-3-sonnet-20240229` to a Sonnet-tier price instead of Haiku. When LiteLLM's cost DB lacks the retired model, resolution falls through to `MODEL_ALIASES`, which pointed Claude 3 Sonnet (a $3/$15-per-1M model) at `claude-3-haiku-20240307` ($0.25/$1.25) — a different tier that underpriced every cost/savings figure for that model ~12x on both input and output. It now aliases to `claude-sonnet-4-20250514`, the same-price target the other retired-Sonnet aliases already use.
* **cache/semantic:** don't evict an unrelated entry when re-storing a key that is already cached. `SemanticCache.put` ran its at-capacity eviction loop before computing the entry's key, so overwriting a key that was already present (a duplicate or retried store) still evicted the LRU-oldest distinct entry even though an in-place update grows nothing. That silently dropped a live entry and turned a later lookup for it into a false cache miss. The key is now computed first and the eviction loop only runs when the key is genuinely new (mirroring `CompressionCache.store_compressed`, which deletes-then-inserts).
* **tokenizers:** stop `TiktokenCounter.count_messages` from exploding on non-text content blocks. Its multi-part branch handled only `text` and OpenAI `image_url`; every other shape (Anthropic `image`/`tool_result`/`tool_use`, Strands blocks) fell through to `count_text(str(part))`, which json-stringified the base64 payload and tokenized it as text — a 1MB image counted as ~330K phantom tokens (~218x overcount in a standalone repro), corrupting every downstream budgeting/compression decision for multimodal OpenAI-model requests. Unknown block shapes now delegate to the base `_count_content_parts`, which prices images/documents by a bounded estimate (the overcount that helper already exists to prevent).
* **install:** don't let a host env export override the manifest in persistent-docker deployments. `build_runtime_command` emitted the manifest's pinned `--env NAME=VALUE` pairs and then, for every host var matching a passthrough prefix, a bare `--env NAME`. Docker resolves duplicate `--env` last-wins, so a stale host export (e.g. `HEADROOM_BACKEND=anyllm`) that shared a passthrough prefix with a pinned manifest value (`HEADROOM_BACKEND=anthropic`) was appended after it and silently won, diverging the container from its deployment config. The bare passthrough is now skipped for any name the manifest already pins.
diff --git a/headroom/pricing/litellm_model_resolution.py b/headroom/pricing/litellm_model_resolution.py
index dd1870e8a..1d58b7880 100644
--- a/headroom/pricing/litellm_model_resolution.py
+++ b/headroom/pricing/litellm_model_resolution.py
@@ -25,8 +25,11 @@ MODEL_ALIASES: dict[str, str] = {
# Claude 3.5 Sonnet retired Feb 2026, pricing same as claude-sonnet-4-20250514
"claude-3-5-sonnet-20241022": "claude-sonnet-4-20250514",
"claude-3-5-sonnet-20240620": "claude-sonnet-4-20250514",
- # Claude 3 Sonnet retired
- "claude-3-sonnet-20240229": "claude-3-haiku-20240307",
+ # Claude 3 Sonnet retired. It was a Sonnet-tier model ($3/$15 per 1M
+ # in/out) — same price as claude-sonnet-4-20250514 — so alias it there.
+ # The old target, claude-3-haiku-20240307 ($0.25/$1.25), is a different
+ # (Haiku) tier and underpriced every cost/savings figure ~12x.
+ "claude-3-sonnet-20240229": "claude-sonnet-4-20250514",
}
diff --git a/tests/test_pricing_litellm_model_resolution.py b/tests/test_pricing_litellm_model_resolution.py
index 50842b7b3..c2098a89b 100644
--- a/tests/test_pricing_litellm_model_resolution.py
+++ b/tests/test_pricing_litellm_model_resolution.py
@@ -37,6 +37,20 @@ def test_pricing_lookup_candidates_include_provider_prefixes_and_aliases() -> No
assert candidates[-1] == MODEL_ALIASES["claude-3-5-sonnet-20241022"]
+def test_retired_claude_3_sonnet_aliases_to_sonnet_tier_not_haiku() -> None:
+ """Retired claude-3-sonnet must map to a Sonnet-tier price, not Haiku.
+
+ claude-3-sonnet-20240229 was a $3/$15-per-1M model; aliasing it to
+ claude-3-haiku-20240307 ($0.25/$1.25) underpriced its cost/savings ~12x.
+ """
+ alias = MODEL_ALIASES["claude-3-sonnet-20240229"]
+
+ assert "haiku" not in alias
+ # Same-tier target as the other retired-Sonnet aliases.
+ assert alias == MODEL_ALIASES["claude-3-5-sonnet-20241022"]
+ assert alias == "claude-sonnet-4-20250514"
+
+
def test_resolve_litellm_model_name_returns_first_known_candidate() -> None:
known = {"openai/gpt-4o"}