Skip to content

[BUG] API Error: 400 messages.51: tool_use ids were found without tool_result blocks immediately after: toolu_018gFuML9Ktbwk6HZrTeK7K1. Each tool_use block must have a corresponding tool_result block in the next message. #1782

@ratheh

Description

@ratheh

Environment

  • Platform (select one):
    • [ x] Anthropic API
    • AWS Bedrock
    • Google Vertex AI
    • Other:
  • Claude CLI version: Claude Code v1.0.17
  • Operating System: macOS 15.5 (24F74)
  • Terminal: standard macOS terminal

Bug Description

Latest version of claude code is giving a lot of API errors during normal development specifically around analysing log files or analysing existing code base or running python code.

Steps to Reproduce

  1. Give claude a tasks that includes reading log files (containing images) big log files 20MB ish
  2. As part of analysing logs and comming up with tha plan of action claude will give API errors

Expected Behavior

The API errors I am getting are obviously issues with resiliancy of the API / tools used by Claude, Claude should be able to automatically recover from failures, better still in some of these failure they should not be happening at all as it looks like some aspect of claude tooling has failed.

Actual Behavior

Error message given in claude code:
⏺ Search(pattern: "_perform_physical_card_detection", path:
"app/services/image_analysis/analyse_captured_image.py")
⎿  Found 1 file (ctrl+r to expand)
⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.51: tool_use ids
were found without tool_result blocks immediately after: toolu_018gFuML9Ktbwk6HZrTeK7K1. Each tool_use
block must have a corresponding tool_result block in the next message."}}
⎿  Found 1 file (ctrl+r to expand)
⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.51: tool_use ids
were found without tool_result blocks immediately after: toolu_018gFuML9Ktbwk6HZrTeK7K1. Each tool_use
block must have a corresponding tool_result block in the next message."}}

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

These errors appear to not be recoverable and I will need to restart the session.

Additional Context

The errors are more likely with long log files, large code case including images linked to from the log files. In this specific case

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiarea:corebugSomething isn't workingduplicateThis issue or pull request already existsplatform:macosIssue specifically occurs on macOS

    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