Skip to content

fix: add automatic caching for anthropic#12743

Merged
gr2m merged 4 commits intovercel:mainfrom
jaderiverstokes:patch-1
Feb 24, 2026
Merged

fix: add automatic caching for anthropic#12743
gr2m merged 4 commits intovercel:mainfrom
jaderiverstokes:patch-1

Conversation

@jaderiverstokes
Copy link
Copy Markdown
Contributor

Background

Anthropic now supports automatic caching. The top level provider options supports it already, however it gets stripped before being sent to the provider.

Summary

Pass the cacheControl flag through the provider.

Manual Verification

Adds unit test.

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #12712

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Feb 20, 2026
@buibaoanh
Copy link
Copy Markdown

@jaderiverstokes wondering if amazon-bedrock requires the same fix?

@gr2m gr2m changed the title Add automatic cacheing for anthropic Add automatic caching for anthropic Feb 24, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gr2m gr2m changed the title Add automatic caching for anthropic fix: add automatic caching for anthropic Feb 24, 2026
@gr2m gr2m merged commit 17978c6 into vercel:main Feb 24, 2026
18 checks passed
gr2m added a commit that referenced this pull request Feb 24, 2026
## Summary

Backport of #12743 to `release-v5.0`.

- Passes the `cacheControl` provider option as a top-level
`cache_control` field in the Anthropic API request body to support
[automatic
caching](https://platform.claude.com/docs/en/docs/build-with-claude/prompt-caching#automatic-caching)
- Includes tests for both `{ type: 'ephemeral' }` and `{ type:
'ephemeral', ttl: '1h' }`
- Includes patch changeset for `@ai-sdk/anthropic`

---------

Co-authored-by: Jade River Stokes <jaderiverstokes@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic automatic caching support

3 participants