Repository navigation
feat(bedrock_mantle): add Claude Opus 5, Sonnet 5, and Haiku 4.5 support - #34625
bharatlakhiyani wants to merge 3 commits into
Conversation
The Mantle endpoint serves Claude models under dateless IDs (anthropic.claude-opus-5, anthropic.claude-sonnet-5, anthropic.claude-haiku-4-5 per the AWS model cards). Two gaps prevented correct handling: 1. anthropic.claude-haiku-4-5 had no cost-map entry (only the dated bedrock-runtime ID anthropic.claude-haiku-4-5-20251001-v1:0 exists), so Mantle Haiku responses were cost-tracked at $0. Add the dateless entry (200K in / 64K out, $1/$5 per 1M tokens, prompt caching). 2. strip_bedrock_routing_prefix did not strip the mantle/ routing prefix, so get_model_info on bedrock/mantle/anthropic.claude-* resolved generalization fallbacks (generic 200K/64K limits, no cache pricing, no output_config capability flags) instead of the exact bare-model entries. Add mantle/ to the prefix list; route detection is unaffected because explicit route prefixes are matched before base-model resolution, and the bedrock_mantle/ provider prefix is still left intact (segment- boundary matching).
get_model_info.cache_clear() alone leaves _cached_get_model_info_helper (used by completion_cost) holding entries from whichever cost map was active first, making the cost-tracking test order-dependent. Use _invalidate_model_cost_lowercase_map, which clears both caches and the lowercase lookup map.
|
|
Greptile SummaryThe PR adds accurate Bedrock Mantle metadata and model resolution for dateless Claude model IDs.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/common_utils.py | Adds mantle/ to iterative Bedrock routing-prefix normalization while preserving the distinct bedrock_mantle/ provider prefix. |
| model_prices_and_context_window.json | Adds the dateless Claude Haiku 4.5 Bedrock metadata required for Mantle model information and cost calculation. |
| litellm/model_prices_and_context_window_backup.json | Mirrors the new dateless Claude Haiku 4.5 metadata in the packaged local cost map. |
| tests/test_litellm/llms/bedrock/test_mantle.py | Adds isolated regression tests covering exact model resolution, Mantle routing, prefix handling, and completion cost. |
Reviews (2): Last reviewed commit: "test(bedrock): clear all model-cost LRU ..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
The failing OSV scan is unrelated to this change; it flags gitpython 3.1.52 in uv.lock and postcss/brace-expansion in the dashboard lockfile, none of which this PR touches, and it fails the same way on the base branch. Opened #34626 with the dependency bumps; once that merges I'll rebase this branch to rerun the scan |
b2776ed to
b256753
Compare
|
Dropped the dependency-bump commit from this branch: the lockfile-guard check rejects any fork PR that modifies uv.lock, so the OSV fix has to come from a branch in the canonical repository. For a maintainer picking it up: bump gitpython to 3.1.55 (needs a [tool.uv.exclude-newer-package] gitpython override in pyproject.toml since the release is inside the 3-day exclude-newer window; lock regenerated with uv 0.10.9), and in ui/litellm-dashboard bump postcss to 8.5.18 and brace-expansion to 5.0.8 in both the devDependency pins and the overrides block. Verified locally that with those bumps osv-scanner v2.3.8 reports "No issues found" using the exact invocation from .github/workflows/osv-scan.yml. Until that lands on litellm_internal_staging, the OSV failure on this PR is pre-existing on the base branch and unrelated to this change |
… into litellm_bedrock_mantle_claude_5_models
|
@ryan-crabbe-berri this is ready for your review can you please help? |
TLDR
Problem this solves:
How it solves it:
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Reproduction before the fix, at base commit 7b019cf (checked out in a separate worktree, local cost map):
After the fix, at b256753, same script:
Live proxy proof at b256753, hitting the real bedrock-mantle.us-east-1.api.aws endpoint (SigV4, real $). Proxy started with a config containing three deployments (claude-opus-5-mantle, claude-sonnet-5-mantle, claude-haiku-4-5-mantle mapping to bedrock/mantle/anthropic.claude-{opus-5,sonnet-5,haiku-4-5}), then:
All three answered "4" and the costs match the per-token rates exactly (e.g. haiku: 23 in x 1e-06 + 4 out x 5e-06 = 4.3e-05; before this PR the haiku header read 0.0)
The native /v1/messages surface works on the same deployments, non-streaming and streaming:
Streaming (claude-sonnet-5-mantle, "stream": true) returned the raw Anthropic SSE pass-through starting with
event: message_startand"model":"claude-sonnet-5"from the wireType
🆕 New Feature
Changes
The Mantle endpoint (bedrock-mantle.{region}.api.aws/anthropic/v1/messages) serves Claude models under dateless IDs per the AWS model cards: anthropic.claude-opus-5, anthropic.claude-sonnet-5, and anthropic.claude-haiku-4-5. The bedrock/mantle/ route itself is model-agnostic, but two data/resolution gaps kept these models from working correctly
First, anthropic.claude-haiku-4-5 had no cost-map entry; only the dated bedrock-runtime ID anthropic.claude-haiku-4-5-20251001-v1:0 exists. Since the Mantle wire response reports the dateless ID, Haiku responses were cost-tracked at $0. This PR adds the dateless entry (200K in / 64K out, $1/$5 per 1M tokens, cache write $1.25 / read $0.10, 1h TTL pricing, prompt_cache_min_tokens 4096) to model_prices_and_context_window.json and litellm/model_prices_and_context_window_backup.json. It uses litellm_provider "bedrock", matching the anthropic.claude-mythos-preview Mantle precedent, and deliberately stays out of BEDROCK_CONVERSE_MODELS because the dateless ID does not exist on bedrock-runtime Converse
Second, strip_bedrock_routing_prefix did not strip the mantle/ routing prefix, so get_model_info("bedrock/mantle/anthropic.claude-opus-5") fell through to generalization fallbacks: generic 200K/64K limits, zero cache pricing, and no output_config capability flags, instead of the exact 1M/128K bare-model entries. Adding "mantle/" to the prefix list fixes resolution for all mantle-routed models (it also makes is_claude_4_5_on_bedrock detect 1h cache TTL support correctly for them). Route detection is unaffected: explicit route prefixes are matched before base-model resolution, and the bedrock_mantle/ provider prefix is still left intact by segment-boundary matching, covered by a regression test
Tests added in tests/test_litellm/llms/bedrock/test_mantle.py: exact model-info resolution for all three models (limits and per-token costs, so a deleted JSON entry or a reverted prefix fix both fail), mantle route detection for the new IDs, prefix-strip behavior including the bedrock_mantle/ non-collision, and Haiku cost tracking through completion_cost. The local_cost_map fixture clears all model-cost LRU caches via _invalidate_model_cost_lowercase_map so the cost test cannot become order-dependent
Why the diff looks smaller for Opus 5 and Sonnet 5: their dateless entries (anthropic.claude-opus-5, anthropic.claude-sonnet-5) already exist upstream from the general Bedrock launch commits, so those two only needed the prefix-strip fix to resolve correctly through the mantle route. Haiku 4.5 is the only one whose dateless ID was missing from the cost map. All three ride the same bedrock/mantle/ route and the same fix; the tests are parametrized over all three model IDs
Note for CI: the OSV scan currently fails on the base branch itself (gitpython 3.1.52 in uv.lock plus postcss/brace-expansion in the dashboard lockfile). This PR cannot carry the fix because fork PRs must not modify uv.lock; the bumps need a branch in the canonical repository (gitpython to 3.1.55 needs an exclude-newer-package override in pyproject.toml since the release is inside the 3-day exclude-newer window; postcss to 8.5.18 and brace-expansion to 5.0.8 in the dashboard pins and overrides). Verified locally that those bumps make osv-scanner v2.3.8 report "No issues found" with the exact workflow invocation
Final Attestation