API Error 400: Missing tool_result blocks when reading multiple PDF files

Resolved 💬 3 comments Opened Oct 1, 2025 by AutoPrimeJa Closed Oct 4, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

# Bug Report: API Error 400 - Tool results not properly formatted in conversation history

## Description
When attempting to read multiple PDF files using the Read tool, Claude Code fails to properly format the conversation history, resulting in API errors about missing tool_result blocks.

## Expected Behavior
Each tool_use block should have a corresponding tool_result block properly inserted into the conversation history before the next API request is sent.

## Actual Behavior
Claude Code sends an API request with tool_use blocks that are missing their corresponding tool_result blocks in the message sequence, causing the API to reject the request with a 400 error.

## Environment

  • Platform: Windows (win32)
  • Working Directory: C:\Users\PRIME Boss
  • Date: 2025-09-30
  • Operation: Reading PDF files from Desktop

## Impact

  • Prevents reading multiple files in succession
  • Breaks conversation flow
  • Requires /clear to start fresh conversation

## Workaround

  • Use /clear to start a new conversation
  • Read files one at a time with separate requests
  • Avoid batching multiple file read operations

What Should Happen?

Expected Behavior

Each tool_use block should have a corresponding tool_result block properly inserted into the conversation history before the next API request is sent.

Error Messages/Logs

## Error Message
  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.6: tool_use ids were found without tool_result blocks immediately after: toolu_01KZjAYeB6jscpgCFXZZm27k,
  toolu_01V6q3jXptkAUzXqS4HyMH17. Each tool_use block must have a corresponding tool_result block in the next message."},"request_id":"req_011CTfZDV3tzwrZLWxjgbGCf"}

Steps to Reproduce

## Steps to Reproduce

  1. Attempt to read multiple PDF files in sequence using the Read tool
  2. Example: Read(~\Desktop\finances_spet30_25\Statement-20250912.pdf) followed by Read(~\Desktop\finances_spet30_25\bremer_business.pdf)
  3. Error occurs on the second or subsequent read operation

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.2 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

## Context
Error occurs when reading multiple PDF files sequentially. The conversation history is malformed - tool_use blocks are sent without their corresponding tool_result blocks.

## Specific Tool Calls That Failed

  • Read(~\Desktop\finances_spet30_25\Statement-20250912.pdf) - 567.4KB PDF
  • Read(~\Desktop\finances_spet30_25\bremer_business.pdf) - 113.6KB PDF (this is where error occurred)

## Tool IDs Referenced in Error

  • toolu_01KZjAYeB6jscpgCFXZZm27k
  • toolu_01V6q3jXptkAUzXqS4HyMH17

## Request ID

  • req_011CTfZDV3tzwrZLWxjgbGCf

## Error Occurred At
Message index 6 in the conversation history

## Reproducibility
Consistently occurs when attempting to read multiple PDF files in sequence

View original on GitHub ↗

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