API Error 400: cache_control TTL ordering violation in long conversations

Resolved 💬 3 comments Opened Mar 23, 2026 by gulliversgames Closed Mar 23, 2026

Bug Description

After a long conversation, Claude Code produces an API error due to incorrect cache_control TTL block ordering:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.156.content.2.cache_control.ttl: a ttl='1h' cache_control block must not come after a ttl='5m' cache_control block. Note that blocks are processed in the following order: `tools`, `system`, `messages`."}}

Steps to Reproduce

  1. Have a long conversation (156+ message content blocks in this case)
  2. At some point the request fails with the above 400 error
  3. Starting a new conversation resolves the issue

Expected Behavior

Claude Code should ensure cache_control TTL blocks are ordered correctly (shorter TTLs should not precede longer TTLs, or the ordering should follow API requirements) regardless of conversation length.

Environment

  • Claude Code version: stable channel
  • Model: claude-opus-4-6 (1M context)
  • OS: macOS (Darwin 25.3.0)
  • Multiple plugins enabled (document-skills, gg-team, LSP plugins, etc.)
  • Agent teams enabled (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1)
  • Auto-compact set to 97% (CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=97)

Notes

  • The error references messages.156.content.2, suggesting it occurs deep into conversations
  • No user-configurable settings affect cache_control TTL — this is internal to Claude Code's request construction
  • Workaround: start a new conversation

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗