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
refactor(bedrock): inline maxTokens clamp and cover inference-profile ARNs in tests
mateo-berri12120fe59bd9
diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.pyindex 801ec571376..176819c0dab 100644--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@ -382,12 +382,6 @@ class AmazonConverseConfig(BaseConfig):def _requires_min_max_tokens(model: str) -> bool:return re.search(r"openai\.gpt-\d|xai\.grok-", model) is not None- @staticmethod- def _enforce_min_max_tokens(max_tokens: object) -> object:- if isinstance(max_tokens, int) and max_tokens < BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS:- return BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS- return max_tokens-def _is_nova_2_model(self, model: str) -> bool:"""Check if the model is a Nova 2 model that supports reasoningConfig.@@ -1011,8 +1005,8 @@ class AmazonConverseConfig(BaseConfig):)if param == "max_tokens" or param == "max_completion_tokens":optional_params["maxTokens"] = (- self._enforce_min_max_tokens(value)- if self._requires_min_max_tokens(model) and isinstance(value, int)+ max(value, BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS)+ if isinstance(value, int) and self._requires_min_max_tokens(model)else value)if param == "stream":diff --git a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.pyindex 9d8bf786829..086a7e59f56 100644--- a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py+++ b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py@@ -467,6 +467,9 @@ def test_reasoning_with_forced_tool_choice_switches_to_auto():("global.xai.grok-4.6", "max_completion_tokens", 1, 16),("us.xai.grok-4.6", "max_tokens", 32, 32),("anthropic.claude-sonnet-4-5-20250929-v1:0", "max_tokens", 1, 1),+ ("arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.openai.gpt-6-astra", "max_tokens", 1, 16),+ ("arn:aws:bedrock:us-east-1:123456789012:inference-profile/global.xai.grok-4.6", "max_tokens", 1, 16),+ ("arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123xyz", "max_tokens", 1, 1),],)def test_map_openai_params_enforces_minimum_max_tokens_for_openai_compat_models(