claude-code - 💡(How to fix) Fix API Error: cache_control cannot be set for empty text blocks when sending image-only message

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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

Error Message

API Error: 400 messages.20.content.2.text: cache_control cannot be set for empty text blocks

Root Cause

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

Code Example

API Error: 400 messages.20.content.2.text: cache_control cannot be set for empty text blocks
RAW_BUFFERClick to expand / collapse

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

  1. Open a Claude Code session (remote SSH session on Ubuntu VM, desktop app on Windows)
  2. Send a message containing only an image attachment with no text
  3. 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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING