By the Cuelark Team. Sources: AI SDK release notes, PR and docs, and Anthropic's API docs, checked 29 November 2026. We didn't call Claude: everything ran against a fake Anthropic endpoint on ai@7.0.184 with @ai-sdk/anthropic@4.0.111 (and 4.0.110 for comparison), so it shows the request your app sends, not model output.
Claude can take a role: "system" message in the middle of messages. Prompt caching hashes tools, then system, then messages, and a hit needs that prefix to match byte for byte. Edit the top-level system mid-chat and you lose the cache for everything after it. Append a system message where the new rule applies and the cached prefix stays the same.
The AI SDK supports this with allowSystemInMessages: true, but until this week one common case misbehaved.
What changed in @ai-sdk/anthropic 4.0.111
The patch (November 27 UTC) fixes two cases that silently drop a cache breakpoint:
- No leading system message. With no instructions at the start, the provider promoted the first system message to top-level
system, even after user and assistant turns. That's deliberate for models that reject mid-conversation system messages, but it moves your reminder and itscacheControlto the front, so the breakpoint covers almost nothing. - Tool-change-only system messages. A system message with only
toolChangesand no text lost itscacheControl, though Anthropic accepts it ontool_additionandtool_removalblocks.
The fix adds providerOptions.anthropic.midConversationSystemMessages (default false). When true, a later system message stays where you put it. A tool-changes-only message now puts its cacheControl on its last tool change.
Anthropic lists mid-conversation system messages for Claude Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Fable 5, Mythos 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5 and Haiku 5.5. Claude Sonnet 5 doesn't. Only enable the option for listed models.
Seeing the difference
Same history through both versions: user, assistant, user, then a system reminder with cacheControl.
const history = [ { role: 'user', content: 'Here is our style guide... (long)' }, { role: 'assistant', content: 'Got it.' }, { role: 'user', content: 'Rewrite the intro.' }, { role: 'system', content: 'Reply in US English. Keep it under 120 words.', providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } }, }, ]; await generateText({ model: anthropic('claude-opus-5-5'), allowSystemInMessages: true, messages: history, providerOptions: { anthropic: { midConversationSystemMessages: true } }, }); What the endpoint received:
- 4.0.110, with or without the option: the reminder moved into top-level
system, breakpoint and all;messageswasuser > assistant > user. The unknown option raised no error. - 4.0.111, option off: same as above. The default didn't change.
- 4.0.111, option on: no top-level
system;messageswasuser > assistant > user > system, breakpoint on the reminder, so the whole history precedes it.
For the tool case, a system message containing only toolChanges: [{ type: 'tool_addition', toolName: 'exportPdf' }] plus cacheControl. had no breakpoint on 4.0.110. On 4.0.111 it sent {"type":"tool_addition","tool":{"type":"tool_reference","name":"exportPdf"},"cache_control":{"type":"ephemeral"}}.
Wiring it into a useChat app
A reminder must sit in the same position on every request, or the prefix stops matching. useChat UI messages don't include system messages, so we store the reminder as metadata on its user message and rebuild it on the server each turn.
// app/api/chat/route.ts import { anthropic } from '@ai-sdk/anthropic'; import { streamText, convertToModelMessages, type UIMessage, type ModelMessage } from 'ai'; export type ChatMessage = UIMessage<{ reminder?: string }>; const cache = { anthropic: { cacheControl: { type: 'ephemeral' as const } } }; export async function POST(req: Request) { const { messages }: { messages: ChatMessage[] } = await req.json(); const modelMessages: ModelMessage[] = []; for (const m of messages) { modelMessages.push(...(await convertToModelMessages([m]))); // Put the reminder back right after its user turn on every request. if (m.role === 'user' && m.metadata?.reminder) { modelMessages.push({ role: 'system', content: m.metadata.reminder }); } } // One breakpoint on the newest message covers the whole history. const last = modelMessages.at(-1)!; last.providerOptions = { ...last.providerOptions, ...cache }; const result = streamText({ model: anthropic('claude-opus-5-5'), allowSystemInMessages: true, messages: modelMessages, providerOptions: { anthropic: { midConversationSystemMessages: true } }, }); return result.toUIMessageStreamResponse(); } On the client, a composer checkbox attaches the reminder:
const { messages, sendMessage, status } = useChat<ChatMessage>(); sendMessage({ text: input, metadata: usEnglish ? { reminder: 'Reply in US English from here on.' } : undefined, }); We called this handler twice against a fake streaming endpoint, like two useChat turns. On 4.0.111, turn 1 sent user > system with the breakpoint on the reminder; turn 2 sent user > system > assistant > user with the breakpoint on the newest user message. Ignoring cache_control, turn 1's messages were an exact prefix of turn 2's, and both streamed back through toUIMessageStreamResponse. On 4.0.110 the reminder moved into top-level system, which also changes its meaning: it now applies to the whole chat, earlier turns included.
Honest limits
- No real model, no real cache. We checked request shapes, not
cache_read_input_tokens. Short chats fall under Anthropic's minimum cacheable length anyway. - Use the same setting on every request. The AI SDK docs warn that toggling
midConversationSystemMessagesmid-conversation moves the message betweensystemandmessages, missing the cache and possibly breaking Anthropic's prefix check for earlier thinking blocks. - Placement rules still apply. Anthropic returns a 400 if a system message doesn't directly follow a user turn (or an assistant turn ending in a server tool result), or sits between a
tool_useand itstool_result. - Don't edit sent reminders. Changing or removing one invalidates the cache from that point. Append a new one instead.
- No browser click-through. The code type-checks against
@ai-sdk/react@4.0.189; we called the handler directly.
Sources
- @ai-sdk/anthropic@4.0.111 release notes
- vercel/ai PR #25551: keep cache control on mid-conversation system messages
- AI SDK Anthropic provider docs: Mid-Conversation System Controls
- Anthropic docs: Mid-conversation system messages
- Anthropic docs: Models overview (claude-opus-5-5 ID)
To skip building the chat UI, Cuelark UI has shadcn-style chat components that fit this setup.