Skip to content

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]

fix(bedrock/): add generic support for tool calling on bedrock models

Krrish Dholakia398fef8391e6
diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py
index 4e76fb24dcc..59b83151f55 100644
--- a/litellm/llms/bedrock/chat/converse_transformation.py
+++ b/litellm/llms/bedrock/chat/converse_transformation.py
@@ -105,6 +105,8 @@ class AmazonConverseConfig(BaseConfig):
}
def get_supported_openai_params(self, model: str) -> List[str]:
+ from litellm.utils import supports_function_calling
+
supported_params = [
"max_tokens",
"max_completion_tokens",
@@ -137,6 +139,9 @@ class AmazonConverseConfig(BaseConfig):
or base_model.startswith("meta.llama3-2")
or base_model.startswith("meta.llama3-3")
or base_model.startswith("amazon.nova")
+ or supports_function_calling(
+ model=model, custom_llm_provider=self.custom_llm_provider
+ )
):
supported_params.append("tools")
diff --git a/tests/llm_translation/test_bedrock_completion.py b/tests/llm_translation/test_bedrock_completion.py
index 2b10514d33a..54cb1fd4ec9 100644
--- a/tests/llm_translation/test_bedrock_completion.py
+++ b/tests/llm_translation/test_bedrock_completion.py
@@ -3141,3 +3141,49 @@ async def test_bedrock_max_completion_tokens(model: str):
}
+
+def test_bedrock_meta_llama_function_calling():
+ """
+ Tests that:
+ - meta llama models support function calling
+ """
+ tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_current_weather",
+ "description": "Get the current weather in a given location",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string",
+ "description": "The city and state, e.g. San Francisco, CA",
+ },
+ "unit": {
+ "type": "string",
+ "enum": ["celsius", "fahrenheit"],
+ },
+ },
+ "required": ["location"],
+ },
+ },
+ }
+ ]
+ messages = [
+ {
+ "role": "user",
+ "content": "What's the weather like in Boston today in fahrenheit?",
+ }
+ ]
+ request_args = {
+ "messages": messages,
+ "tools": tools,
+ "model": "bedrock/us.meta.llama4-scout-17b-instruct-v1:0",
+ }
+
+ response = completion(**request_args)
+
+ print(response)
+
+
\ No newline at end of file