claude-code - 💡(How to fix) Fix [BUG] API Error 400 "cache_control cannot be set for empty text blocks" — triggered by multi-image upload in single 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 attaching multiple images (screenshots) to a single message in Claude Code on the web (<claude.ai/code>), the session can permanently break with:

API Error: 400 messages.N.content.M.text:
  cache_control cannot be set for empty text blocks

Once it hits, EVERY subsequent message in that session returns the same 400 because the corrupted content block is replayed in the conversation history. Retries do not work — the session is effectively dead.

Error Message

API Error: 400 messages.N.content.M.text: 4. The first error may appear immediately, or on a later turn

  • Hard to diagnose: the error message blames "empty text blocks" but the API Error: 400 messages.N.content.M.text:
  1. The first error may appear immediately, or on a later turn
  • Hard to diagnose: the error message blames "empty text blocks" but the

Error Messages/Logs

API Error: 400 messages.N.content.M.text: 4. The first error may appear immediately, or on a later turn

  • Hard to diagnose: the error message blames "empty text blocks" but the

Root Cause

Once it hits, EVERY subsequent message in that session returns the same 400 because the corrupted content block is replayed in the conversation history. Retries do not work — the session is effectively dead.

Fix Action

Fix / Workaround

Workaround discovered

Workaround discovered

Workaround discovered

RAW_BUFFERClick to expand / collapse

Preflight Checklist

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

What's Wrong?

Summary

When attaching multiple images (screenshots) to a single message in Claude Code on the web (<claude.ai/code>), the session can permanently break with:

API Error: 400 messages.N.content.M.text:
  cache_control cannot be set for empty text blocks

Once it hits, EVERY subsequent message in that session returns the same 400 because the corrupted content block is replayed in the conversation history. Retries do not work — the session is effectively dead.

Reproduction

  1. Open a new session at <claude.ai/code> in a project
  2. Attach 4-5 screenshots to a single message (drag-and-drop or paste)
  3. Type a short prompt with the images and send
  4. The first error may appear immediately, or on a later turn

I reproduced this twice:

  • Once at message #818 in a long-running session (<claude.ai/code/session_01MXfh2WVnGwts7tPjdNCVBg>)
  • Once at message #4 in a fresh session after uploading 5 thumbnails in one turn

Single-image messages do NOT trigger it.

Expected behavior

Multi-image messages should serialize as multiple content blocks, none of which should be empty text blocks with cache_control set. The platform's message-building code should either:

  • Not emit empty text content blocks, OR
  • Not apply cache_control to empty blocks

Actual behavior

One of the generated content blocks is an empty text block with cache_control set, which Anthropic's API rejects with HTTP 400. The bad block becomes permanently part of the conversation history, making the session unrecoverable.

Impact

  • Lost work: sessions with significant in-progress context die unrecoverably
  • Wasted turns: "Try again" and follow-up messages all hit the same 400
  • Hard to diagnose: the error message blames "empty text blocks" but the user attached images, not text

Workaround discovered

  • Send screenshots one per message instead of batching
  • When a session locks up, abandon it (start fresh) — the corruption is baked into that session's history

Environment

  • Platform: <claude.ai/code> (web)
  • Browser: Safari (iPad) and Chrome (Windows desktop) — both affected
  • Model: Claude Opus 4.7 (1M context)
  • First observed: 2026-05-21

What Should Happen?

Summary

When attaching multiple images (screenshots) to a single message in Claude Code on the web (<claude.ai/code>), the session can permanently break with:

API Error: 400 messages.N.content.M.text:
  cache_control cannot be set for empty text blocks

Once it hits, EVERY subsequent message in that session returns the same 400 because the corrupted content block is replayed in the conversation history. Retries do not work — the session is effectively dead.

Reproduction

  1. Open a new session at <claude.ai/code> in a project
  2. Attach 4-5 screenshots to a single message (drag-and-drop or paste)
  3. Type a short prompt with the images and send
  4. The first error may appear immediately, or on a later turn

I reproduced this twice:

  • Once at message #818 in a long-running session (<claude.ai/code/session_01MXfh2WVnGwts7tPjdNCVBg>)
  • Once at message #4 in a fresh session after uploading 5 thumbnails in one turn

Single-image messages do NOT trigger it.

Expected behavior

Multi-image messages should serialize as multiple content blocks, none of which should be empty text blocks with cache_control set. The platform's message-building code should either:

  • Not emit empty text content blocks, OR
  • Not apply cache_control to empty blocks

Actual behavior

One of the generated content blocks is an empty text block with cache_control set, which Anthropic's API rejects with HTTP 400. The bad block becomes permanently part of the conversation history, making the session unrecoverable.

Impact

  • Lost work: sessions with significant in-progress context die unrecoverably
  • Wasted turns: "Try again" and follow-up messages all hit the same 400
  • Hard to diagnose: the error message blames "empty text blocks" but the user attached images, not text

Workaround discovered

  • Send screenshots one per message instead of batching
  • When a session locks up, abandon it (start fresh) — the corruption is baked into that session's history

Environment

  • Platform: <claude.ai/code> (web)
  • Browser: Safari (iPad) and Chrome (Windows desktop) — both affected
  • Model: Claude Opus 4.7 (1M context)
  • First observed: 2026-05-21

Error Messages/Logs

Steps to Reproduce

Summary

When attaching multiple images (screenshots) to a single message in Claude Code on the web (<claude.ai/code>), the session can permanently break with:

API Error: 400 messages.N.content.M.text:
  cache_control cannot be set for empty text blocks

Once it hits, EVERY subsequent message in that session returns the same 400 because the corrupted content block is replayed in the conversation history. Retries do not work — the session is effectively dead.

Reproduction

  1. Open a new session at <claude.ai/code> in a project
  2. Attach 4-5 screenshots to a single message (drag-and-drop or paste)
  3. Type a short prompt with the images and send
  4. The first error may appear immediately, or on a later turn

I reproduced this twice:

  • Once at message #818 in a long-running session (<claude.ai/code/session_01MXfh2WVnGwts7tPjdNCVBg>)
  • Once at message #4 in a fresh session after uploading 5 thumbnails in one turn

Single-image messages do NOT trigger it.

Expected behavior

Multi-image messages should serialize as multiple content blocks, none of which should be empty text blocks with cache_control set. The platform's message-building code should either:

  • Not emit empty text content blocks, OR
  • Not apply cache_control to empty blocks

Actual behavior

One of the generated content blocks is an empty text block with cache_control set, which Anthropic's API rejects with HTTP 400. The bad block becomes permanently part of the conversation history, making the session unrecoverable.

Impact

  • Lost work: sessions with significant in-progress context die unrecoverably
  • Wasted turns: "Try again" and follow-up messages all hit the same 400
  • Hard to diagnose: the error message blames "empty text blocks" but the user attached images, not text

Workaround discovered

  • Send screenshots one per message instead of batching
  • When a session locks up, abandon it (start fresh) — the corruption is baked into that session's history

Environment

  • Platform: <claude.ai/code> (web)
  • Browser: Safari (iPad) and Chrome (Windows desktop) — both affected
  • Model: Claude Opus 4.7 (1M context)
  • First observed: 2026-05-21

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

Web version

Platform

Anthropic API

Operating System

Other

Terminal/Shell

Other

Additional Information

<img width="1376" height="1032" alt="Image" src="https://github.com/user-attachments/assets/d3b9bdc0-7cc4-443d-a426-c6215cfc4840" /> <img width="1376" height="1032" alt="Image" src="https://github.com/user-attachments/assets/cfe63fdd-d696-49f7-8984-94596fb6b728" /> <img width="1376" height="1032" alt="Image" src="https://github.com/user-attachments/assets/cc8503ff-6136-4900-bee6-2450a6acd581" />

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…

FAQ

Expected behavior

Multi-image messages should serialize as multiple content blocks, none of which should be empty text blocks with cache_control set. The platform's message-building code should either:

  • Not emit empty text content blocks, OR
  • Not apply cache_control to empty blocks

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] API Error 400 "cache_control cannot be set for empty text blocks" — triggered by multi-image upload in single message