From 3726e3254d256076b72e8635a103f056431cb371 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Tue, 25 Aug 2026 17:44:32 -0500 Subject: [PATCH] fix(ai): enable Vertex Anthropic prompt caching (#45088) --- packages/ai/src/cache-policy.ts | 2 +- packages/ai/test/cache-policy.test.ts | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/ai/src/cache-policy.ts b/packages/ai/src/cache-policy.ts index 551b557ac29..0149435458e 100644 --- a/packages/ai/src/cache-policy.ts +++ b/packages/ai/src/cache-policy.ts @@ -36,7 +36,7 @@ const resolve = (policy: CachePolicy | undefined): CachePolicyObject => { // Protocols whose wire format ignores inline cache markers (OpenAI's implicit // prefix caching, Gemini's implicit + out-of-band CachedContent). Skip the // whole policy pass for these — emitting hints would be harmless but pointless. -const RESPECTS_INLINE_HINTS = new Set(["anthropic-messages", "bedrock-converse", "openrouter"]) +const RESPECTS_INLINE_HINTS = new Set(["anthropic-messages", "google-vertex-messages", "bedrock-converse", "openrouter"]) const makeHint = (ttlSeconds: number | undefined): CacheHint => ttlSeconds !== undefined ? new CacheHint({ type: "ephemeral", ttlSeconds }) : new CacheHint({ type: "ephemeral" }) diff --git a/packages/ai/test/cache-policy.test.ts b/packages/ai/test/cache-policy.test.ts index 378fa901ed5..aa4b7aeb229 100644 --- a/packages/ai/test/cache-policy.test.ts +++ b/packages/ai/test/cache-policy.test.ts @@ -3,7 +3,7 @@ import { Effect } from "effect" import { CacheHint, LLM, Message } from "../src/index.js" import { Auth } from "../src/route.js" import { compileRequest } from "../src/route/client.js" -import { AmazonBedrock } from "../src/providers.js" +import { AmazonBedrock, GoogleVertexMessages } from "../src/providers.js" import * as AnthropicMessages from "../src/protocols/anthropic-messages.js" import * as Gemini from "../src/protocols/gemini.js" import * as OpenAIChat from "../src/protocols/openai-chat.js" @@ -86,6 +86,27 @@ describe("applyCachePolicy", () => { }), ) + it.effect("'auto' emits Anthropic cache markers on Vertex", () => + Effect.gen(function* () { + const prepared = yield* compileRequest( + LLM.request({ + model: GoogleVertexMessages.configure({ accessToken: "test", location: "global", project: "test" }).model( + "claude-opus-4-8", + ), + system: "You are concise.", + tools: [{ name: "lookup", description: "Look up a value", inputSchema: { type: "object", properties: {} } }], + prompt: "hi", + }), + ) + + expect(prepared.body).toMatchObject({ + tools: [{ name: "lookup", cache_control: { type: "ephemeral" } }], + system: [{ type: "text", text: "You are concise.", cache_control: { type: "ephemeral" } }], + messages: [{ role: "user", content: [{ type: "text", text: "hi", cache_control: { type: "ephemeral" } }] }], + }) + }), + ) + it.effect("'auto' is a no-op on OpenAI (implicit caching protocol)", () => Effect.gen(function* () { const prepared = yield* compileRequest(