fix(pricing): add Claude Sonnet 5.5 / Opus 5.5 / Fable 5.1, correct Sonnet 5 rates (#3841)

## Description

Claude Sonnet 5.5 and Opus 5.5 are released, and Anthropic made Claude
Sonnet 5's launch price its standard rate. This PR updates Headroom's
built-in Anthropic fallback price and context tables and the Rust
proxy's vendored LiteLLM snapshot to match current [Anthropic
pricing](https://platform.claude.com/docs/en/about-claude/pricing)
(verified 2026-09-29).

From the pricing page, footnote 3:

> The $2/$10 per million input/output token pricing for Claude Sonnet 5,
announced at launch as introductory pricing through August 31, 2026, is
now the standard price. The previously scheduled increase to $3/$15 per
million input/output tokens on September 1, 2026 will not occur.

This reverses the deliberate $3/$15 pin from #1767, which assumed that
increase would happen.

**Why the missing rows mispriced instead of failing:**
`AnthropicProvider._get_pricing` falls back to substring matching in
dict insertion order, so `claude-sonnet-5-5` silently inherited the
`claude-sonnet-5` row and `claude-fable-5-1` inherited Fable 5's $1
cache read. The Rust `context_window_for` is exact-match, so every
Claude 5-generation id fell through to the 128K default.

Closes #

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

All values in $ / MTok (input / output / cache read).

| Model | Before (fallback) | After | Context |
|---|---|---|---|
| `claude-sonnet-5-5` | *(no row: matched `claude-sonnet-5`)* $3 / $15 /
$0.30 | **$2 / $10 / $0.20** | 1M |
| `claude-sonnet-5` | $3 / $15 / $0.30 | **$2 / $10 / $0.20** | 1M |
| `claude-opus-5-5` | *(no row: opus tier default)* $5 / $25 / $0.50 |
**$4 / $20 / $0.20** | 1M |
| `claude-opus-5` | *(no row: opus tier default)* | $5 / $25 / $0.50 |
1M |
| `claude-fable-5-1` | *(no row: matched `claude-fable-5`)* $10 / $50 /
$1.00 | **$10 / $50 / $0.25** | 1M |

- `headroom/providers/anthropic.py`:
- Adds the four new models to `ANTHROPIC_PRICING` and
`ANTHROPIC_CONTEXT_LIMITS` and corrects `claude-sonnet-5`.
- Newer ids are listed before their prefixes so dated or suffixed ids
(`…-5-5-20261001`, `…-5-5[1m]`) resolve to their own row.
- The `_PATTERN_DEFAULTS` tier rates are unchanged: they also cover
older unlisted models such as Sonnet 3.7.
- `crates/headroom-proxy/data/model_prices_and_context_window.json`:
appends the 113 missing upstream Claude 5-generation keys (first-party,
Bedrock regional/global/Mantle, Vertex, Azure, Databricks, OpenRouter
and similar). No existing entry changes or is removed. The snapshot is
extended rather than re-pulled with `scripts/refresh_model_limits.sh`:
- Upstream has since pruned 258 retired ids the proxy still serves, e.g.
`claude-3-7-sonnet-20250219` and `claude-opus-4-1`. Those would regress
from 200K to the 128K default.
- A full re-pull overwrites the hand-edited DeepSeek rate card from
#3575.
- `crates/headroom-proxy/src/compression/model_limits.rs`: new
`claude_5_generation_models_present` test.
- `tests/test_providers/test_anthropic.py`:
  - The Sonnet 5 expectation moves to $2/$10/$0.20.
- New parametrized pricing and 1M-context tests for the new models,
including the prefix-collision cases.
- `tests/test_provider_model_fallback.py`: the "future opus" probe moves
from `claude-opus-5-20260101` to `claude-opus-6-20270101`. Opus 5 is now
a real 1M entry, so the old id no longer exercised the pattern fallback.
This mirrors the existing `claude-sonnet-6` probe.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] Type checking passes (`mypy headroom`) (run on the changed module,
`headroom/providers/anthropic.py`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
$ cargo test -p headroom-proxy --lib compression::model_limits
test compression::model_limits::tests::claude_5_generation_models_present ... ok
test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 271 filtered out

$ HOME=$(mktemp -d) pytest -q tests/test_providers/test_anthropic.py tests/test_provider_model_fallback.py \
    tests/test_cost_tracker_totals.py tests/test_pricing_from_litellm.py tests/test_pricing.py \
    tests/test_openai_pricing_resolution.py
138 passed, 2 warnings

$ ruff check headroom/providers/anthropic.py tests/test_providers/test_anthropic.py tests/test_provider_model_fallback.py
All checks passed!
$ ruff format --check (same files)
3 files already formatted
$ cargo fmt -p headroom-proxy -- --check
(clean)
$ mypy headroom/providers/anthropic.py
Success: no issues found in 1 source file
```

On the broader pricing, cost and savings subset, 773 pass. The same 12
failures and 3 collection errors occur on unmodified `main` in my
environment, all `ModuleNotFoundError` from optional dev deps (`respx`
and others) that aren't installed locally. `HOME` is isolated because a
developer `~/.headroom/models.json` leaks into
`TestAnthropicConfigLoading`.

## Real Behavior Proof

- Environment: macOS, the repo `.venv` (Python 3.10). `origin/main` and
this PR head were each checked out as a git worktree and run with the
same interpreter and an isolated `HOME`.
- Exact command / steps: priced the same request through the built-in
fallback on `origin/main` and on this PR head (steps below).
- A script built `AnthropicProvider()`, stubbed
`estimate_cost_from_tokens` to return `None` to force the built-in
fallback (the LiteLLM-unavailable or offline path), and priced 1M input
tokens (800K cached) plus 100K output tokens for each model.
- For the Rust side, `context_window_for` semantics (exact key, `mode ==
"chat"`, `max_input_tokens`, 128K default) were applied to each
worktree's vendored JSON.
- Observed result: `origin/main` bills Sonnet 5.5 at $3/$15 and gives
every Claude 5-generation id a 128K Rust window; this PR bills $2/$10
and gives them 1M.
  ```text
  origin/main
claude-sonnet-5-5 rates={'input': 3.0, 'output': 15.0, 'cached_input':
0.3} cost=$2.3400
claude-sonnet-5 rates={'input': 3.0, 'output': 15.0, 'cached_input':
0.3} cost=$2.3400
claude-opus-5-5 rates={'input': 5.0, 'output': 25.0, 'cached_input':
0.5} cost=$3.9000
claude-fable-5-1 rates={'input': 10.0, 'output': 50.0, 'cached_input':
1.0} cost=$7.8000
rust context_window_for: sonnet-5-5 / global.anthropic.claude-sonnet-5-5
/ opus-5-5 / fable-5-1 = 128000

  this PR
claude-sonnet-5-5 rates={'input': 2.0, 'output': 10.0, 'cached_input':
0.2} cost=$1.5600
claude-sonnet-5 rates={'input': 2.0, 'output': 10.0, 'cached_input':
0.2} cost=$1.5600
claude-opus-5-5 rates={'input': 4.0, 'output': 20.0, 'cached_input':
0.2} cost=$2.9600
claude-fable-5-1 rates={'input': 10.0, 'output': 50.0, 'cached_input':
0.25} cost=$7.2000
    rust context_window_for: all four = 1000000
  ```
The live LiteLLM `model_cost` already reports the "after" rates for all
of these, so the primary pricing path is unchanged. This fixes the
fallback path and the Rust proxy.
- Not tested: no live upstream Sonnet 5.5 request, no dashboard browser
check (details below).
  - No live upstream requests were sent against Claude Sonnet 5.5.
- The dashboard savings tile was not exercised in a browser. It consumes
the same `estimate_cost` path shown above.

## Runtime Rollout Safety

- Rollout-managed feature(s): none. This is static pricing and context
metadata.
- Minimum rollout channel: n/a
- Stable/default behavior changed: yes, fallback cost estimates and the
Rust compression budget for Claude 5-generation ids only (details
below).
- Fallback cost estimates for the listed models drop to Anthropic's
published rates.
- The Rust proxy's compression budget for Claude 5-generation ids rises
from 128K to their real 1M window. The proxy now compresses those
requests later instead of over-trimming them.
- Kill switch / disable path: `HEADROOM_MODEL_LIMITS` or
`~/.headroom/models.json` can override any model's context limit or
pricing.
- Unsafe override required: no
- Qualification impact: none expected. Existing models' rows and
vendored entries are byte-identical.
- Rollback path: revert this commit.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation (n/a: no
user-facing docs list model prices)
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this) (my original commit did; @JerrettDavis removed it in 2cfd4f64,
thanks)

## Screenshots (if applicable)

n/a

## Additional Notes

Not in scope: the static `_build_bedrock_fallback_map` and
`_VERTEX_MODEL_MAP` in `headroom/backends/litellm.py` stop at Claude
4.6. They are routing maps, not pricing, and are only used when
inference-profile discovery fails. They need verified per-model Bedrock
and Vertex ids, so they should be a separate PR.

https://claude.ai/code/session_01E5Hryq8EfuB4LAnu81TtJz

---------

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
Kenneth Wong
2026-09-29 11:15:38 -05:00
committed by GitHub
co-authored by JerrettDavis
parent 2f076687b0
commit 0d99c56dc5
5 changed files with 3933 additions and 8 deletions
File diff suppressed because it is too large Load Diff
@@ -174,6 +174,23 @@ mod tests {
assert_eq!(n, 200_000, "claude-sonnet-4-5 should be 200K input window");
}
#[test]
fn claude_5_generation_models_present() {
// Missing entries fall through to the 128K default, so the
// compressor would trim these 1M-window models far too early.
for model in [
"claude-sonnet-5-5",
"claude-sonnet-5",
"claude-opus-5-5",
"claude-opus-5",
"claude-fable-5-1",
"global.anthropic.claude-sonnet-5-5",
"vertex_ai/claude-sonnet-5-5",
] {
assert_eq!(context_window_for(model), 1_000_000, "{model}");
}
}
#[test]
fn current_gpt_models_present() {
assert_eq!(context_window_for("gpt-4o-mini"), 128_000);
+24 -5
View File
@@ -108,8 +108,12 @@ def sanitize_anthropic_model_metadata(value: Any) -> Any:
# Anthropic model context limits
# All Claude 3+ models have 200K context
ANTHROPIC_CONTEXT_LIMITS: dict[str, int] = {
# Claude Fable 5 - 1M context
# Claude Fable 5.1 / Fable 5 - 1M context
"claude-fable-5-1": 1000000,
"claude-fable-5": 1000000,
# Claude Opus 5.5 / Opus 5 - 1M context
"claude-opus-5-5": 1000000,
"claude-opus-5": 1000000,
# Claude Opus 4.8 - 1M context
"claude-opus-4-8": 1000000,
# Claude 4.7 (Opus 4.7) - 1M context
@@ -118,7 +122,8 @@ ANTHROPIC_CONTEXT_LIMITS: dict[str, int] = {
"claude-opus-4-6": 1000000,
# Claude 4.5 (Opus 4.5)
"claude-opus-4-5-20251101": 200000,
# Claude Sonnet 5 - 1M context
# Claude Sonnet 5.5 / Sonnet 5 - 1M context
"claude-sonnet-5-5": 1000000,
"claude-sonnet-5": 1000000,
# Claude Sonnet 4.6 - 1M context window
"claude-sonnet-4-6": 1000000,
@@ -145,10 +150,20 @@ ANTHROPIC_CONTEXT_LIMITS: dict[str, int] = {
# Fallback pricing - LiteLLM is preferred source
# NOTE: These are ESTIMATES. Always verify against actual Anthropic billing.
# Last updated: 2026-07-04
# Last updated: 2026-09-29 (platform.claude.com/docs/en/about-claude/pricing)
#
# Newer ids come before their prefixes: `_get_pricing` falls back to substring
# matching in insertion order, so a dated or suffixed "claude-sonnet-5-5-..."
# must hit the Sonnet 5.5 row before it can hit "claude-sonnet-5".
ANTHROPIC_PRICING: dict[str, dict[str, float]] = {
# Claude Fable 5.1: $10 in / $50 out, cache read $0.25 (0.025x input).
"claude-fable-5-1": {"input": 10.00, "output": 50.00, "cached_input": 0.25},
# Claude Fable 5 (anthropic.com/pricing): $10 in / $50 out, cache read $1.
"claude-fable-5": {"input": 10.00, "output": 50.00, "cached_input": 1.00},
# Claude Opus 5.5: $4 in / $20 out, cache read $0.20 (0.05x input).
"claude-opus-5-5": {"input": 4.00, "output": 20.00, "cached_input": 0.20},
# Claude Opus 5: $5 in / $25 out, cache read $0.50.
"claude-opus-5": {"input": 5.00, "output": 25.00, "cached_input": 0.50},
# Claude Opus 4.8 — current Opus tier: $5 in / $25 out, cache read $0.50.
"claude-opus-4-8": {"input": 5.00, "output": 25.00, "cached_input": 0.50},
# Claude 4.7 (current Opus tier)
@@ -157,8 +172,12 @@ ANTHROPIC_PRICING: dict[str, dict[str, float]] = {
"claude-opus-4-6": {"input": 5.00, "output": 25.00, "cached_input": 0.50},
# Claude 4.5 (current Opus tier — same rates as 4.6–4.8)
"claude-opus-4-5-20251101": {"input": 5.00, "output": 25.00, "cached_input": 0.50},
# Claude Sonnet 5 / 4.6 / 4.5 (current Sonnet tier): $3 in / $15 out, cache read $0.30
"claude-sonnet-5": {"input": 3.00, "output": 15.00, "cached_input": 0.30},
# Claude Sonnet 5.5 / 5: $2 in / $10 out, cache read $0.20. Sonnet 5's
# launch rate became its standard price; the scheduled 2026-09-01 rise to
# $3/$15 was cancelled.
"claude-sonnet-5-5": {"input": 2.00, "output": 10.00, "cached_input": 0.20},
"claude-sonnet-5": {"input": 2.00, "output": 10.00, "cached_input": 0.20},
# Claude Sonnet 4.6 / 4.5: $3 in / $15 out, cache read $0.30
"claude-sonnet-4-6": {"input": 3.00, "output": 15.00, "cached_input": 0.30},
"claude-sonnet-4-5": {"input": 3.00, "output": 15.00, "cached_input": 0.30},
# Claude 4 (Sonnet/Haiku tier pricing)
+2 -2
View File
@@ -91,10 +91,10 @@ class TestAnthropicModelFallback:
provider = AnthropicProvider()
# Future opus model should infer 200K and opus pricing
limit = provider.get_context_limit("claude-opus-5-20260101")
limit = provider.get_context_limit("claude-opus-6-20270101")
assert limit == 200000
pricing = provider._get_pricing("claude-opus-5-20260101")
pricing = provider._get_pricing("claude-opus-6-20270101")
assert pricing["input"] == 5.00
assert pricing["output"] == 25.00
+24 -1
View File
@@ -287,5 +287,28 @@ class TestAnthropicCostEstimation:
opus = anthropic_provider._get_pricing("claude-opus-4-8")
assert opus == {"input": 5.00, "output": 25.00, "cached_input": 0.50}
# The scheduled rise to $3/$15 on 2026-09-01 was cancelled; $2/$10 is standard.
sonnet = anthropic_provider._get_pricing("claude-sonnet-5")
assert sonnet == {"input": 3.00, "output": 15.00, "cached_input": 0.30}
assert sonnet == {"input": 2.00, "output": 10.00, "cached_input": 0.20}
@pytest.mark.parametrize(
("model", "expected"),
[
("claude-fable-5-1", {"input": 10.00, "output": 50.00, "cached_input": 0.25}),
("claude-opus-5-5", {"input": 4.00, "output": 20.00, "cached_input": 0.20}),
("claude-opus-5", {"input": 5.00, "output": 25.00, "cached_input": 0.50}),
("claude-sonnet-5-5", {"input": 2.00, "output": 10.00, "cached_input": 0.20}),
# Suffixed ids must resolve to their own row, not a shorter prefix's.
("claude-sonnet-5-5[1m]", {"input": 2.00, "output": 10.00, "cached_input": 0.20}),
("claude-fable-5-1-20261001", {"input": 10.00, "output": 50.00, "cached_input": 0.25}),
("claude-opus-5-5-20261001", {"input": 4.00, "output": 20.00, "cached_input": 0.20}),
],
)
def test_pricing_claude_5_point_releases(self, anthropic_provider, model, expected):
assert anthropic_provider._get_pricing(model) == expected
@pytest.mark.parametrize(
"model", ["claude-fable-5-1", "claude-opus-5-5", "claude-opus-5", "claude-sonnet-5-5"]
)
def test_context_limit_claude_5_point_releases(self, anthropic_provider, model):
assert anthropic_provider.get_context_limit(model) == 1_000_000