mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
* fix(bedrock-mantle): use /anthropic/v1/messages path for Mantle endpoint (#27943) * docs: add one-line docstring to _disable_debugging (#27894) Squash-merged by litellm-agent from oss-agent-shin's PR. * Add jp. Bedrock cross-region inference profile for claude-sonnet-4-6 (#27831) Squash-merged by litellm-agent from Cyberfilo's PR. * Sanitize empty text content blocks on /v1/messages (#27832) Squash-merged by litellm-agent from Cyberfilo's PR. * fix(bedrock-mantle): use /anthropic/v1/messages path for Mantle endpoint The bedrock-mantle gateway (Claude Mythos Preview) serves the Anthropic Messages API at /anthropic/v1/messages; /v1/messages returns 404 Not Found. Both AmazonMantleConfig (chat/completions caller route) and AmazonMantleMessagesConfig (anthropic-messages caller route) hardcoded the wrong path, so every Mantle request 404'd before reaching the model. Per the Anthropic docs: "[Claude in Amazon Bedrock] uses the Messages API at /anthropic/v1/messages with SSE streaming." https://platform.claude.com/docs/en/api/claude-on-amazon-bedrock Confirmed independently against the live endpoint: /v1/chat/completions -> 200 OK /v1/messages -> 404 Not Found (what litellm used) /anthropic/v1/messages -> 200 OK (Claude only) Adds a regression test asserting both Mantle configs build the /anthropic/v1/messages path, and updates the existing assertions that encoded the wrong path. --------- Co-authored-by: oss-agent-shin <ext-agent-shin@berri.ai> Co-authored-by: Filippo Menghi <113345637+Cyberfilo@users.noreply.github.com> * fix: sanitize empty text blocks in sync anthropic_messages_handler path Co-authored-by: Yassin Kortam <yassin@berri.ai> --------- Co-authored-by: João Costa <13508071+jpv-costa@users.noreply.github.com> Co-authored-by: oss-agent-shin <ext-agent-shin@berri.ai> Co-authored-by: Filippo Menghi <113345637+Cyberfilo@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Yassin Kortam <yassin@berri.ai>
105 lines
3.4 KiB
Python
105 lines
3.4 KiB
Python
"""
|
|
Unit tests for the Bedrock Mantle (Claude Mythos Preview) integration.
|
|
|
|
Tests cover route detection, URL construction, and config dispatch for both
|
|
the /chat/completions and /messages endpoints.
|
|
"""
|
|
|
|
from litellm.llms.bedrock.common_utils import BedrockModelInfo, get_bedrock_chat_config
|
|
from litellm.llms.bedrock.chat.mantle.transformation import AmazonMantleConfig
|
|
from litellm.llms.bedrock.messages.mantle_transformation import (
|
|
AmazonMantleMessagesConfig,
|
|
)
|
|
|
|
|
|
def test_get_bedrock_route_mantle():
|
|
assert (
|
|
BedrockModelInfo.get_bedrock_route("mantle/anthropic.claude-mythos-preview")
|
|
== "mantle"
|
|
)
|
|
|
|
|
|
def test_get_bedrock_route_mantle_does_not_match_other_routes():
|
|
assert (
|
|
BedrockModelInfo.get_bedrock_route("anthropic.claude-3-sonnet-20240229-v1:0")
|
|
!= "mantle"
|
|
)
|
|
assert (
|
|
BedrockModelInfo.get_bedrock_route("converse/anthropic.claude-3-sonnet")
|
|
!= "mantle"
|
|
)
|
|
|
|
|
|
def test_explicit_mantle_route_flag():
|
|
assert (
|
|
BedrockModelInfo._explicit_mantle_route(
|
|
"mantle/anthropic.claude-mythos-preview"
|
|
)
|
|
is True
|
|
)
|
|
assert BedrockModelInfo._explicit_mantle_route("anthropic.claude-3-sonnet") is False
|
|
assert (
|
|
BedrockModelInfo._explicit_mantle_route("converse/anthropic.claude-3-sonnet")
|
|
is False
|
|
)
|
|
|
|
|
|
def test_mantle_url_construction():
|
|
config = AmazonMantleConfig()
|
|
url = config.get_complete_url(
|
|
api_base=None,
|
|
api_key=None,
|
|
model="mantle/anthropic.claude-mythos-preview",
|
|
optional_params={"aws_region_name": "us-east-1"},
|
|
litellm_params={},
|
|
)
|
|
assert url == "https://bedrock-mantle.us-east-1.api.aws/anthropic/v1/messages"
|
|
|
|
|
|
def test_mantle_url_construction_different_region():
|
|
config = AmazonMantleConfig()
|
|
url = config.get_complete_url(
|
|
api_base=None,
|
|
api_key=None,
|
|
model="mantle/anthropic.claude-mythos-preview",
|
|
optional_params={"aws_region_name": "us-west-2"},
|
|
litellm_params={},
|
|
)
|
|
assert url == "https://bedrock-mantle.us-west-2.api.aws/anthropic/v1/messages"
|
|
|
|
|
|
def test_get_bedrock_chat_config_returns_mantle_config():
|
|
config = get_bedrock_chat_config("mantle/anthropic.claude-mythos-preview")
|
|
assert isinstance(config, AmazonMantleConfig)
|
|
|
|
|
|
def test_get_bedrock_provider_config_for_messages_api_mantle():
|
|
config = BedrockModelInfo.get_bedrock_provider_config_for_messages_api(
|
|
"mantle/anthropic.claude-mythos-preview"
|
|
)
|
|
assert isinstance(config, AmazonMantleMessagesConfig)
|
|
|
|
|
|
def test_mantle_messages_url_construction():
|
|
config = AmazonMantleMessagesConfig()
|
|
url = config.get_complete_url(
|
|
api_base=None,
|
|
api_key=None,
|
|
model="mantle/anthropic.claude-mythos-preview",
|
|
optional_params={"aws_region_name": "us-east-1"},
|
|
litellm_params={},
|
|
)
|
|
assert url == "https://bedrock-mantle.us-east-1.api.aws/anthropic/v1/messages"
|
|
|
|
|
|
def test_mantle_transform_request_strips_prefix_and_adds_model():
|
|
config = AmazonMantleConfig()
|
|
request = config.transform_request(
|
|
model="mantle/anthropic.claude-mythos-preview",
|
|
messages=[{"role": "user", "content": "Hello"}],
|
|
optional_params={"max_tokens": 100},
|
|
litellm_params={},
|
|
headers={},
|
|
)
|
|
assert request["model"] == "anthropic.claude-mythos-preview"
|
|
assert "mantle/" not in request["model"]
|