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
This commit is contained in:
Tony Gies
2026-03-01 08:58:51 -06:00
committed by GitHub
parent c138bbd3d7
commit 15e2f24046
+5
View File
@@ -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;