Skip to content

[Bug]: tool_calls index starts from 1 #11580

@langpingxue

Description

@langpingxue

What happened?

When I use Amazon Bedrock as LLM provider, claude-3-7-sonnet as LLM model.

I got an error: TypeError: Cannot read properties of undefined (reading 'id') when using litellm OpenAI-Compatible Endpoints, the root cause is tool_calls start from 1, it lead to an incorrect array [undefined, {tool_call_object}], then raise the error then (array[0].id)
tool_calls index should always starts from 0 rather than 1

Relevant log output

{
    "id": "chatcmpl-8cff77bc-ccea-4b88-a61a-e89d750fe236",
    "created": 1749546275,
    "model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
    "object": "chat.completion.chunk",
    "choices": [
        {
            "index": 0,
            "delta": {
                "content": "",
                "role": "assistant",
                "tool_calls": [
                    {
                        "id": "tooluse_9116K8c5Q8ivMmdx3VdS7g",
                        "function": {
                            "arguments": "",
                            "name": "jira_get_issue"
                        },
                        "type": "function",
                        "index": 1
                    }
                ]
            }
        }
    ],
    "provider_specific_fields": {}
}

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.71.1-stable

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions