Repository navigation
feat(bedrock): add support for bedrock-mantle endpoint (Claude Mythos Preview) - #26196
8 commits merged into
Conversation
…g, messages config dispatch
|
Ishaan Jaffer seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Congrats! CodSpeed is installed 🎉
You will start to see performance impacts in the reports once the benchmarks are run from your default branch.
|
Greptile SummaryThis PR adds support for the Two previously-flagged P1 issues remain unresolved in this diff:
Confidence Score: 4/5Safe to merge once the two open P1s from previous review rounds are addressed. Two previously-flagged P1 issues remain unresolved: strip_bedrock_routing_prefix missing "mantle/" breaks cost/capability lookups, and the sync transform_request omits document-URL base64 conversion. These are real present defects on the changed path, not speculative concerns, keeping the score at 4. litellm/llms/bedrock/common_utils.py (strip_bedrock_routing_prefix) and litellm/llms/bedrock/chat/mantle/transformation.py (sync document-URL conversion)
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/mantle/transformation.py | New AmazonMantleConfig for /chat/completions; sync transform_request still missing _convert_document_url_sources_to_base64 (previously flagged P1), and MANTLE_ENDPOINT_TEMPLATE is duplicated with mantle_transformation.py |
| litellm/llms/bedrock/messages/mantle_transformation.py | New AmazonMantleMessagesConfig for /messages; inherits correctly from AmazonAnthropicClaudeMessagesConfig; MANTLE_ENDPOINT_TEMPLATE constant duplicated from transformation.py |
| litellm/llms/bedrock/common_utils.py | Adds mantle route dispatch and _explicit_mantle_route helper; strip_bedrock_routing_prefix still missing "mantle/" (previously flagged P1), causing broken cost/model-info lookups |
| model_prices_and_context_window.json | Adds anthropic.claude-mythos-preview with correct capability flags; 0-cost placeholder is intentional pending pricing |
| tests/llm_translation/test_bedrock_mantle.py | E2E mocked tests verifying URL, model in body, and SigV4 auth; uses proper patch.object mocking, compliant with no-real-network-calls rule |
| tests/test_litellm/llms/bedrock/test_mantle.py | Unit tests for route detection, URL construction, and config dispatch; 9 targeted tests with good coverage of the happy path |
| litellm/init.py | Adds TYPE_CHECKING import for AmazonMantleMessagesConfig, consistent with existing pattern |
| litellm/_lazy_imports_registry.py | Registers AmazonMantleMessagesConfig in lazy import registry, consistent with surrounding entries |
Sequence Diagram
sequenceDiagram
participant User
participant LiteLLM
participant BedrockModelInfo
participant AmazonMantleConfig
participant MantleEndpoint as bedrock-mantle.{region}.api.aws
User->>LiteLLM: completion(model="bedrock/mantle/anthropic.claude-mythos-preview")
LiteLLM->>BedrockModelInfo: get_bedrock_route("mantle/...")
BedrockModelInfo-->>LiteLLM: "mantle"
LiteLLM->>BedrockModelInfo: get_bedrock_chat_config("mantle/...")
BedrockModelInfo-->>LiteLLM: AmazonMantleConfig()
LiteLLM->>AmazonMantleConfig: get_complete_url(region="us-east-1")
AmazonMantleConfig-->>LiteLLM: "https://bedrock-mantle.us-east-1.api.aws/v1/messages"
LiteLLM->>AmazonMantleConfig: transform_request(model="mantle/anthropic.claude-mythos-preview")
Note over AmazonMantleConfig: strips "mantle/" prefix, adds model to body
AmazonMantleConfig-->>LiteLLM: {model: "anthropic.claude-mythos-preview", messages: [...]}
LiteLLM->>MantleEndpoint: POST /v1/messages (SigV4 signed, service=bedrock)
MantleEndpoint-->>LiteLLM: Anthropic Messages API response
LiteLLM-->>User: OpenAI-format ModelResponse
Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile
| # Strip the "mantle/" routing prefix to get the real model ID | ||
| model_id = model.replace("mantle/", "", 1) | ||
|
|
||
| request = self._build_bedrock_anthropic_request_base( | ||
| model=model_id, | ||
| messages=messages, | ||
| optional_params=optional_params, | ||
| litellm_params=litellm_params, | ||
| headers=headers, | ||
| ) | ||
| # The parent strips "model" from the body (Invoke API puts it in URL). | ||
| # The mantle endpoint (Messages API) requires "model" in the body. | ||
| request["model"] = model_id | ||
| return request | ||
|
|
||
| async def async_transform_request( |
There was a problem hiding this comment.
Sync
transform_request skips document-URL conversion that async path performs
async_transform_request calls _async_convert_document_url_sources_to_base64(request) (line 82), but the sync transform_request never calls _convert_document_url_sources_to_base64. This means a synchronous caller passing document/image URL sources will have raw URLs in the request body, while an async caller will get them converted to base64. Because the parent class documents this step as required for any Bedrock-family endpoint ("Bedrock Invoke does not accept document URL sources"), the omission silently corrupts multimodal requests on the sync path.
| else: | ||
| LiteLLMLoggingObj = Any | ||
|
|
||
| MANTLE_ENDPOINT_TEMPLATE = "https://bedrock-mantle.{region}.api.aws/v1/messages" |
There was a problem hiding this comment.
MANTLE_ENDPOINT_TEMPLATE duplicated across two files
The same constant is defined identically in litellm/llms/bedrock/messages/mantle_transformation.py (line 23). If the endpoint URL changes these must be kept in sync manually. Consider moving it to a shared location (e.g. importing from transformation.py into mantle_transformation.py, or into a shared bedrock/constants.py).
…itellm_bedrock_mantle_ant
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 29203053 | Triggered | Generic Password | 7f7fcc3 | .circleci/config.yml | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… Preview) (BerriAI#26196) * add anthropic.claude-mythos-preview to model_prices_and_context_window.json * add mantle route to bedrock common_utils: route detection, chat config, messages config dispatch * add AmazonMantleConfig for bedrock/mantle /chat/completions endpoint * add AmazonMantleMessagesConfig for bedrock/mantle /messages endpoint * register AmazonMantleMessagesConfig in __init__.py and lazy imports registry * add unit tests for bedrock mantle route and config dispatch * add e2e tests for bedrock mantle: URL, body, SigV4 header, region routing
Relevant issues
Adds support for the new AWS Bedrock
bedrock-mantleendpoint, which serves Claude Mythos Preview (anthropic.claude-mythos-preview) using the Anthropic Messages API format.Changes
Usage:
The
bedrock-mantleendpoint differs from standard Bedrock in two ways:https://bedrock-mantle.{region}.api.aws/v1/messagesmodelgoes in the request body rather than the URLRoute pattern:
bedrock/mantle/<model-id>— consistent with existing explicit routes (bedrock/converse/...,bedrock/agentcore/...).Auth: AWS SigV4 with service=
bedrock, same as other Bedrock models.Files:
model_prices_and_context_window.json— addsanthropic.claude-mythos-preview(1M context, 128K output, supports reasoning + vision; pricing TBD)litellm/llms/bedrock/common_utils.py— adds"mantle"route,_explicit_mantle_route()helper, dispatch inget_bedrock_chat_config()andget_bedrock_provider_config_for_messages_api()litellm/llms/bedrock/chat/mantle/transformation.py—AmazonMantleConfigfor/chat/completionslitellm/llms/bedrock/messages/mantle_transformation.py—AmazonMantleMessagesConfigfor/messages(inheritsAmazonAnthropicClaudeMessagesConfig)litellm/__init__.py+litellm/_lazy_imports_registry.py— registrationQA results (fake mantle endpoint)
Intercepted outgoing HTTP calls to verify full request/response pipeline for both endpoints.
/chat/completionsRequest:
Response (OpenAI format):
{ "id": "chatcmpl-...", "object": "chat.completion", "model": "anthropic.claude-mythos-preview", "choices": [{ "finish_reason": "stop", "index": 0, "message": { "role": "assistant", "content": "Hello! I am Claude Mythos Preview running via bedrock-mantle." } }], "usage": {"prompt_tokens": 12, "completion_tokens": 15, "total_tokens": 27} }/messagesRequest:
Response (Anthropic format):
{ "id": "msg_fake456", "type": "message", "role": "assistant", "model": "anthropic.claude-mythos-preview", "content": [{"type": "text", "text": "Hello! I am Claude Mythos Preview running via bedrock-mantle."}], "stop_reason": "end_turn", "usage": {"input_tokens": 12, "output_tokens": 15, "total_tokens": 27} }Test results (12/12 passed):
Pre-Submission checklist
tests/test_litellm/(unit) andtests/llm_translation/(e2e with mocked HTTP)make test-unitpasses for new testsType
CI