[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.

Resolved 💬 2 comments Opened Jun 8, 2025 by ratheh Closed Jun 8, 2025

Environment

  • Platform (select one):
  • [ x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • 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

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗