Repository navigation
fix(ai): enable prompt caching on Azure Foundry Claude models - #66686
kitlangton wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Looks good. I enumerated every registered language-model route (route ID and protocol) and checked it against the old route-ID allowlist and the new protocol allowlist: only azure-anthropic-messages changes (it now gets markers). Every other route is unchanged, including the per-model rules for OpenRouter, Vercel AI Gateway and alibaba-chat, and Azure OpenAI Chat and Responses. Both new cache-policy cases fail on the base and pass here. The full packages/ai suite passes (2,310 pass, 0 fail), and typecheck:tsc is clean. I couldn't check it against a live Foundry deployment.
Public API: unchanged. The allowlist is internal, and custom routes built on anthropic-messages with a new ID now get markers by default, as described.
The open PR #62547 fixes the same bug, so one of the two should be closed.
One inline note on the new loop test: the added table entry already covers the fix.
Fixes #62546
| ), | ||
| ) | ||
|
|
||
| it.effect("every registered Anthropic Messages route emits inline cache markers", () => |
There was a problem hiding this comment.
The azure-anthropic-messages entry added to messagesModels above already covers the fix. This loop test is harder to follow than it needs to be: it dynamically imports every provider, picks routes by a -messages naming heuristic, asserts a magic >= 12 count that will need bumping whenever routes change, and runs two compiles per route. Since the policy is now keyed on protocol, could this be cut down to one explicit case (e.g. a custom AnthropicMessages.route.with({ id: "custom-messages" }) getting markers), or dropped?
There was a problem hiding this comment.
The new commit fixes my earlier test comment: the loop over all registered routes is gone, and one explicit custom anthropic-messages route test replaces it. That test and the Azure case both fail on the base and pass here. The full packages/ai suite passes (2,310 pass, 0 fail), and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.
Claude models on Azure AI Foundry now cache prompts instead of paying full input price on every step.
Foundry serves Claude over Anthropic's Messages wire format, which requires inline cache markers in the request body, and OpenCode skipped Azure's Messages route when placing them. Azure OpenAI Chat and Responses deployments still use Azure's automatic prefix caching and are unchanged, while custom SDK routes built on the Anthropic Messages protocol now also receive inline cache markers by default.
🔍 Origin: reported in #62546 (closes #62546)
❌ Before
azure-anthropic-messages.✅ After
anthropic-messages) instead of a per-provider route name.cache_controlbreakpoints are placed on tools, system boundaries, and the conversation tail, matching every other Anthropic Messages provider.📊 Proof
"auto") prompt cachingcache_controlmarkersanthropic-messages("auto"and{ tools: true, ttl: "1h" })Both new tests in
packages/ai/test/cache-policy.test.tsfail without thecache-policy.tschange (31pass,0fail with it; full@opencode/aisuite2,310pass).👀 Read:
packages/ai/src/cache-policy.ts(RESPECTS_INLINE_HINTSandselectPolicy) — keying onroute.protocolfolds all eightanthropic-messagesroutes into one entry while keepingopenrouter-chat,vercel-ai-gateway-messages, andalibaba-chaton their per-model filters. The rest is routine.🔍 Also found independently in a code audit
Checks run
bun run test(inpackages/ai): 2,310 pass, 29 skip, 0 failbun test test/cache-policy.test.ts --rerun-each 10 --randomize(inpackages/ai): 310 pass, 0 failbun run typecheck(inpackages/ai): 0 errorsbun run typecheck:tsc(inpackages/ai): 0 errorsbun run check(repo root): 0 errorsAdded by the opencode bot (AI-generated).
Fixes #62546