From 802f7011e260d729410fe152151811b24ff90913 Mon Sep 17 00:00:00 2001 From: Tim Elfrink Date: Mon, 15 Sep 2025 21:11:31 +0200 Subject: [PATCH] Fix tool call index assignment in Delta class - Update tool call index logic to assign sequential indices when missing - Replace default index=0 behavior with proper sequential assignment - Maintain OpenAI API compatibility with correct tool call indexing - Preserve existing behavior for tool calls with explicit indices - Universal fix benefiting all providers using Delta class --- litellm/types/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 289291bde08..228677a17a7 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -754,10 +754,12 @@ class Delta(OpenAIObject): self.function_call = function_call if tool_calls is not None and isinstance(tool_calls, list): self.tool_calls = [] + current_index = 0 for tool_call in tool_calls: if isinstance(tool_call, dict): if tool_call.get("index", None) is None: - tool_call["index"] = 0 + tool_call["index"] = current_index + current_index += 1 self.tool_calls.append(ChatCompletionDeltaToolCall(**tool_call)) elif isinstance(tool_call, ChatCompletionDeltaToolCall): self.tool_calls.append(tool_call)