The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(bedrock): stop the Moonshot invoke transform from resolving AWS credentials
mateo-berrifa5a90e08e86
diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_moonshot_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_moonshot_transformation.pyindex 91c3a363c31..04c6ec86a13 100644--- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_moonshot_transformation.py+++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_moonshot_transformation.py@@ -149,19 +149,15 @@ class AmazonMoonshotConfig(AmazonInvokeConfig, MoonshotChatConfig):- Temperature and parameter validation"""- # Filter out AWS credentials using the existing method from BaseAWSLLM- self._get_boto_credentials_from_optional_params(optional_params, model)+ inference_params: Final = {k: v for k, v in optional_params.items() if k not in self.aws_authentication_params}- # Strip routing prefixes to get the actual model IDclean_model_id: Final = self._get_model_id(model)- # Use Moonshot's transform_request which handles message transformation- # and tool_choice="required" workaroundreturn MoonshotChatConfig.transform_request(self,model=clean_model_id,messages=messages,- optional_params=optional_params,+ optional_params=inference_params,litellm_params=litellm_params,headers=headers,)diff --git a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_amazon_moonshot_transformation.py b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_amazon_moonshot_transformation.pynew file mode 100644index 00000000000..531f334e460--- /dev/null+++ b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_amazon_moonshot_transformation.py@@ -0,0 +1,66 @@+import pytest++from litellm.llms.bedrock.chat.invoke_transformations.amazon_moonshot_transformation import (+ AmazonMoonshotConfig,+)++AWS_AUTH_PARAMS = {+ "aws_access_key_id": "AKIAEXAMPLE",+ "aws_secret_access_key": "secret",+ "aws_session_token": "token",+ "aws_region_name": "us-west-2",+ "aws_session_name": "session",+ "aws_role_name": "arn:aws:iam::000000000000:role/example",+ "aws_web_identity_token": "web-identity",+ "aws_sts_endpoint": "https://sts.us-west-2.amazonaws.com",+ "aws_bedrock_runtime_endpoint": "https://bedrock-runtime.us-west-2.amazonaws.com",+ "aws_external_id": "external",+}+++def test_transform_request_never_resolves_aws_credentials():+ """A broken credential chain must not stop the request body from being built."""+ config = AmazonMoonshotConfig()++ transformed = config.transform_request(+ model="bedrock/invoke/moonshot.kimi-k2-thinking",+ messages=[{"role": "user", "content": "Hello"}],+ optional_params={"aws_profile_name": "litellm-profile-that-does-not-exist", "max_tokens": 16},+ litellm_params={},+ headers={},+ )++ assert transformed["model"] == "moonshot.kimi-k2-thinking"+ assert transformed["max_tokens"] == 16+ assert "aws_profile_name" not in transformed++[email protected]("aws_param", sorted(AWS_AUTH_PARAMS))+def test_transform_request_keeps_aws_params_out_of_the_body(aws_param: str):+ config = AmazonMoonshotConfig()++ transformed = config.transform_request(+ model="bedrock/invoke/moonshot.kimi-k2-thinking",+ messages=[{"role": "user", "content": "Hello"}],+ optional_params={aws_param: AWS_AUTH_PARAMS[aws_param]},+ litellm_params={},+ headers={},+ )++ assert aws_param not in transformed+++def test_transform_request_leaves_the_caller_aws_params_in_place_for_signing():+ """sign_request reads the aws_* keys off optional_params after transform_request runs."""+ config = AmazonMoonshotConfig()+ optional_params = dict(AWS_AUTH_PARAMS)++ config.transform_request(+ model="bedrock/invoke/moonshot.kimi-k2-thinking",+ messages=[{"role": "user", "content": "Hello"}],+ optional_params=optional_params,+ litellm_params={},+ headers={},+ )++ assert optional_params == AWS_AUTH_PARAMS