Skip to content

[BUG] ⎿ API Error: 400 invalid_request_error tool_use ids were found without tool_result` #3632

@David-Spokes

Description

@David-Spokes

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.8: tool_use ids were found without tool_result blocks immediately after:
toolu_01JJLWxfcBw93tw2yUcSaro4. Each tool_use block must have a corresponding tool_result block in the next message."}}

Steps to Reproduce

Send a request to the API that includes a tool_use block in the messages array.
Do not include a corresponding tool_result block immediately after the tool_use block.
Observe the API response.

Expected Behavior

The API should process the request successfully if all required message blocks are present and correctly ordered.

Actual Behavior

The API returns a 400 Bad Request error, indicating that a tool_use block was found without a corresponding tool_result block immediately after it.

Additional Context

The error message specifically points to messages.8, suggesting the issue is with the 9th message in the array.
The error occurs when the message sequence includes a tool_use block that is not immediately followed by a tool_result block, which is required by the API protocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiarea:corebugSomething isn't workingduplicateThis issue or pull request already exists

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions