From 15e2f240464d115368eeb01317b4a67ce64e8220 Mon Sep 17 00:00:00 2001 From: Tony Gies Date: Sun, 1 Mar 2026 08:58:51 -0600 Subject: [PATCH] fix: skip system messages in OpenRouter cacheAtDepth calculation (#5230) System messages in the OpenRouter messages array were being counted toward depth and could receive cache_control breakpoints. Since OpenRouter hoists system messages into Claude's separate system parameter, this misplaced breakpoints and could prevent caching entirely if the hoisted content fell below minimum cache size. Closes #5227 --- src/prompt-converters.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/prompt-converters.js b/src/prompt-converters.js index 73fc6a23d..f151a6b30 100644 --- a/src/prompt-converters.js +++ b/src/prompt-converters.js @@ -1026,6 +1026,11 @@ export function cachingAtDepthForOpenRouterClaude(messages, cachingAtDepth, ttl) passedThePrefill = true; + // Skip system messages so they don't affect depth counting or receive cache breakpoints + if (messages[i].role === 'system') { + continue; + } + if (messages[i].role !== previousRoleName) { if (depth === cachingAtDepth || depth === cachingAtDepth + 2) { const content = messages[i].content;