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
[Bug Fix] /messages endpoint - ensure tool use arguments are returned for non-anthropic models (#13638)
Ishaan Jaff48c89812c474
diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.pyindex 990d613ecf0..d38e7adc231 100644--- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py+++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py@@ -489,7 +489,7 @@ class LiteLLMAnthropicMessagesAdapter:text: str = ""partial_json: Optional[str] = Nonefor choice in choices:- if choice.delta.content is not None:+ if choice.delta.content is not None and len(choice.delta.content) > 0:text += choice.delta.contentelif choice.delta.tool_calls is not None:partial_json = ""@@ -499,7 +499,6 @@ class LiteLLMAnthropicMessagesAdapter:and tool.function.arguments is not None):partial_json += tool.function.arguments-if partial_json is not None:return "input_json_delta", ContentJsonBlockDelta(type="input_json_delta", partial_json=partial_jsondiff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yamlindex 73643fffe82..5e1e3ea28e7 100644--- a/litellm/proxy/proxy_config.yaml+++ b/litellm/proxy/proxy_config.yaml@@ -1,7 +1,4 @@model_list:- - model_name: vertex_ai/*- litellm_params:- model: vertex_ai/*- model_name: bedrock/converse/us.anthropic.claude-sonnet-4-20250514-v1:0litellm_params:model: bedrock/converse/us.anthropic.claude-sonnet-4-20250514-v1:0diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.pyindex b01ab0cfcb0..e5dba275bda 100644--- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py+++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py@@ -11,15 +11,18 @@ from unittest.mock import patchfrom litellm.llms.anthropic.experimental_pass_through.adapters.transformation import (LiteLLMAnthropicMessagesAdapter,)-from litellm.types.llms.anthropic import AnthropicMessagesUserMessageParam, AnthopicMessagesAssistantMessageParam+from litellm.types.llms.anthropic import (+ AnthopicMessagesAssistantMessageParam,+ AnthropicMessagesUserMessageParam,+)from litellm.types.llms.openai import ChatCompletionAssistantToolCallfrom litellm.types.utils import (ChatCompletionDeltaToolCall,+ Choices,Delta,Function,- StreamingChoices,- Choices,Message,+ StreamingChoices,)@@ -148,3 +151,44 @@ def test_translate_openai_content_to_anthropic_empty_function_arguments():assert result[0].id == "call_empty_args"assert result[0].name == "test_function"assert result[0].input == {}, "Empty function arguments should result in empty dict"++++def test_translate_streaming_openai_chunk_to_anthropic_with_partial_json():+ """Test that partial tool arguments are correctly handled as input_json_delta."""+ choices = [+ StreamingChoices(+ finish_reason=None,+ index=1,+ delta=Delta(+ provider_specific_fields=None,+ content='',+ role='assistant',+ function_call=None,+ tool_calls=[+ ChatCompletionDeltaToolCall(+ id=None,+ function=Function(arguments=': "San ', name=None),+ type='function',+ index=0+ )+ ],+ audio=None,+ ),+ logprobs=None,+ )+ ]++ (+ type_of_content,+ content_block_delta,+ ) = LiteLLMAnthropicMessagesAdapter()._translate_streaming_openai_chunk_to_anthropic(+ choices=choices+ )++ print("Type of content:", type_of_content)+ print("Content block delta:", content_block_delta)++ assert type_of_content == "input_json_delta"+ assert content_block_delta["type"] == "input_json_delta"+ assert content_block_delta["partial_json"] == ': "San '