Repository navigation
Conversation
…patible claude models
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Fixes #65400
Fixes #57199
Type of change
What does this PR do?
two places broke prompt caching for claude behind openai-compatible endpoints
cache_controlmarkers to any model whose id containedclaudeoranthropic.ConfigMigrateV1.migrateModelnever carried that over, so migrated@ai-sdk/openai-compatibleclaude models had nocompatibility.cacheFormatandselectPolicyinpackages/ai/src/cache-policy.tsreturned no markers. the migration now setscacheFormat: "anthropic"on those models (same id rule as V1, model key orid)cacheFormat: "anthropic", the openai chat lowering always puts a tool result's marker inside the tool message'scontentarray. some gateways that translate chat into anthropic messages only read it on the tool message itself. new opt-incompatibility.cacheControlAtMessageLevel(model or provider) moves it there. default stays the content part, since databricks / snowflake cortex document that position{ "compatibility": { "cacheFormat": "anthropic", "cacheControlAtMessageLevel": true } }the new field is added to
Model.Compatibility/Provider.Compatibility(schema) andLanguageModelCompatibility(ai), openapi + client + cli-rs types regenerated, and documented inmodels.mdx(english only)no feature flag, it's a fix. the migration change only adds a field V1 already behaved like, and the new placement is opt-in
How did you verify your code works?
packages/core/test/config/normalization.test.ts: new test, V1 openai-compatible provider with claude models (by key and byid, plusinterleaved) getscacheFormat: "anthropic", non-claude and non-openai-compatible models don't. fails without the fixpackages/ai/test/provider/openai-compatible-chat.test.ts: new test, tool result as last message putscache_controlon the tool message with the opt-in and keeps the content-part position without it. fails without the fixpackages/core/test/config/provider.test.ts: extended the cache format test socacheControlAtMessageLevelreaches the runtime model throughModelResolverbun run script/test.ts test/configin core: 288 passbun run testin ai: 2350 pass, 2 fail (pdf.recorded.test.tsbedrock cassettes, only because my shell hasAWS_REGION=us-west-2; pass with it unset)bun typecheckin ai, core, schema, client, protocol, plusbun run typecheck:tscin aiScreenshots / recordings
n/a, request body + config only
Checklist