feat(coding-agent): add prompt cache warming (#9668)

This commit is contained in:
Armin Ronacher 2026-09-19 21:18:15 +02:00 • committed by GitHub
parent 7d5eb0ee3b
commit c596d09d9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 1380 additions and 69 deletions

View file

@ -20,6 +20,7 @@ import type {
KnownProvider,
Model,
ModelCost,
ModelPromptCache,
OpenAICompletionsCompat,
OpenAIResponsesCompat,
} from "../src/types.ts";
@ -931,6 +932,21 @@ function applyOpenAIExplicitPromptCacheMetadata(model: Model<Api>): void {
};
}
// Anthropic ephemeral entries have a hard five-minute lifetime; `ttl: "1h"`
// extends it to one hour. Only direct Anthropic is annotated so cache warming
// does not assume equivalent behavior through proxies.
// https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
const ANTHROPIC_PROMPT_CACHE: ModelPromptCache = { short: 300, long: 3600 };
function applyPromptCacheMetadata(model: Model<Api>): void {
if (model.provider === "anthropic" && model.api === "anthropic-messages") {
model.promptCache = ANTHROPIC_PROMPT_CACHE;
}
// Do not add OpenAI lifetimes yet. Before enabling warming for explicit
// OpenAI caches, re-evaluate it using observed expiry, replay, and billing
// behavior; a documented TTL alone does not establish full cache loss.
}
function isGemma4Model(modelId: string): boolean {
return /gemma-?4/.test(modelId.toLowerCase());
}
@ -3055,6 +3071,7 @@ async function generateModels() {
applyOpenAICompletionsTranscriptMetadata(model);
applyOpenAIResponsesTranscriptMetadata(model);
applyOpenAIExplicitPromptCacheMetadata(model);
applyPromptCacheMetadata(model);
}
applyAnthropicAllowedFallbackModelMetadata(allModels.filter(isAnthropicFallbackMetadataModel));