API Error: cache_control cannot be set for empty text blocks when sending image-only message
Resolved 💬 1 comment Opened May 20, 2026 by slug-enjoyer Closed Jun 19, 2026
Description
When sending a message that contains only an image (no accompanying text), Claude Code throws a 400 API error:
API Error: 400 messages.20.content.2.text: cache_control cannot be set for empty text blocks
Steps to Reproduce
- Open a Claude Code session (remote SSH session on Ubuntu VM, desktop app on Windows)
- Send a message containing only an image attachment with no text
- Error appears immediately
Expected Behavior
The image-only message should be sent successfully without an API error.
Actual Behavior
Claude Code constructs a message with an empty text block that has cache_control set, which the API rejects with a 400 error.
Environment
- Claude Code CLI version: 2.1.145
- Setup: Remote SSH session (Ubuntu VM) accessed via Claude Code Windows desktop app
Notes
The issue appears to be in how Claude Code builds the API request when the user's message content is solely an image — an empty text block ends up with a cache_control header attached, which is invalid.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗