claude-code - 💡(How to fix) Fix [BUG] API Error 400: cache_control cannot be set for empty text blocks [1 comments, 2 participants]

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…
GitHub stats
anthropics/claude-code#52057Fetched 2026-04-23 07:37:41
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

Error Message

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.306.content.2.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011CaKAoZGt1W7zbyMEA3a3E"}

Code Example

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.306.content.2.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011CaKAoZGt1W7zbyMEA3a3E"}
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?

Claude Code throws a 400 API error mid-conversation and fails the turn. Happens repeatedly in long sessions.

What Should Happen?

Conversation continues normally without errors.

Error Messages/Logs

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.306.content.2.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011CaKAoZGt1W7zbyMEA3a3E"}

Steps to Reproduce

  1. Start a long multi-turn conversation in Claude Code web
  2. After many messages (~100+), the turn fails with the error above
  3. Retrying usually works

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

claude-sonnet-4-6

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

The issue can likely be mitigated by modifying the conversation to avoid triggering the cache_control error for empty text blocks.

Guidance

  • Investigate the messages.306.content.2.text field in the API request to understand why it's being set as an empty text block, which is causing the cache_control error.
  • Review the Claude Code documentation to see if there are any settings or configurations that can be adjusted to prevent empty text blocks from being sent in the API request.
  • Consider adding a check in the conversation flow to ensure that text blocks are not empty before sending the API request.
  • Verify that the issue is indeed a regression by testing the same conversation flow in a previous version of Claude Code, if possible.

Example

No code snippet can be provided without more information about the conversation flow and API request implementation.

Notes

The root cause of the issue is likely related to the way the conversation flow is handling empty text blocks, but more information is needed to provide a definitive solution. The fact that retrying usually works suggests that the issue may be intermittent or related to a specific edge case.

Recommendation

Apply workaround: Modify the conversation flow to handle empty text blocks and prevent the cache_control error. This is recommended because the issue is likely related to a specific implementation detail, and a workaround can be implemented without waiting for a fix from the Claude Code team.

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