API Error 400 – invalid_request_error for tool_result image media type
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?
When Claude Code reads files (in this case, 3 files were read), it crashes with an HTTP 400 Invalid Request Error from the Anthropic API. The error message is:
messages.9.content.0.tool_result.content.0.image.source.base64.media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'
What's happening:
Claude Code is passing an image inside a tool_result message to the API, but the media_type field contains an unsupported or malformed value. The API only accepts image/jpeg, image/png, image/gif, or image/webp, so the request is rejected.
****
Additional Bug / Core Impact:
After the 400 invalid_request_error is returned, the Claude Code session becomes unrecoverable. The CLI does not handle the error gracefully — it crashes entirely rather than skipping the problematic file or prompting the user to continue. The only way to recover is to start a completely new session, losing all context and conversation history.
Expected behavior:
The session should catch the 400 error, warn the user about the unsupported file type, and allow the session to continue.
Actual behavior:
The session dies permanently after the error. No recovery is possible.
What Should Happen?
even after an error the session should return so not only we are having an error, we are losing the session
Error Messages/Logs
Steps to Reproduce
ask it to open a file
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
-
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
WSL (Windows Subsystem for Linux)
Additional Information
<img width="1833" height="117" alt="Image" src="https://github.com/user-attachments/assets/edb0692a-ea7e-48b2-8874-f6ca60075785" />
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗