if (policy.cacheControl) {
applyAnthropicCacheControlToSystem(payloadObj.system, policy.cacheControl);
} else {
stripAnthropicSystemPromptBoundary(payloadObj.system);
}
if (!policy.cacheControl) { return;
}
// Preserve Anthropic cache-write scope by only tagging the trailing user turn.
applyAnthropicCacheControlToMessages(payloadObj.messages, policy.cacheControl);
}
export function applyAnthropicEphemeralCacheControlMarkers(
payloadObj: Record<string, unknown>,
): void { const messages = payloadObj.messages; if (!Array.isArray(messages)) { return;
}
for (const message of messages as Array<{ role?: string; content?: unknown }>) { if (message.role === "system" || message.role === "developer") { if (typeof message.content === "string") {
message.content = [
{ type: "text", text: message.content, cache_control: { type: "ephemeral" } },
]; continue;
} if (Array.isArray(message.content) && message.content.length > 0) { const last = message.content[message.content.length - 1]; if (last && typeof last === "object") { const record = last as Record<string, unknown>; if (record.type !== "thinking" && record.type !== "redacted_thinking") {
record.cache_control = { type: "ephemeral" };
}
}
} continue;
}
if (message.role === "assistant" && Array.isArray(message.content)) { for (const block of message.content) { if (!block || typeof block !== "object") { continue;
} const record = block as Record<string, unknown>; if (record.type === "thinking" || record.type === "redacted_thinking") { delete record.cache_control;
}
}
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.