Add prompt-caching examples for AI SDK v5#43
Merged
subtleGradient merged 11 commits intomainfrom Nov 19, 2025
Merged
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Nov 11, 2025
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive prompt caching examples for AI SDK v5, demonstrating how to use Anthropic's prompt caching feature via OpenRouter with the Vercel AI SDK. The examples showcase the critical configuration requirement of extraBody.stream_options.include_usage for capturing cache metrics.
Key Changes:
- New AI SDK v5 workspace with three prompt caching examples (user message, multi-message conversation, and control scenario)
- Configuration demonstrating
providerOptions.openrouter.cacheControlusage pattern - Documentation linking AI SDK v5 examples to main prompt caching guide
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| typescript/package.json | Adds ai-sdk-v5 workspace to monorepo |
| typescript/ai-sdk-v5/package.json | Defines workspace dependencies and example runner scripts |
| typescript/ai-sdk-v5/tsconfig.json | TypeScript configuration for the new workspace |
| typescript/ai-sdk-v5/README.md | Main workspace documentation with setup and configuration details |
| typescript/ai-sdk-v5/src/prompt-caching/README.md | Prompt caching examples overview and usage guide |
| typescript/ai-sdk-v5/src/prompt-caching/anthropic-user-message-cache.ts | Example demonstrating cache control on user message content |
| typescript/ai-sdk-v5/src/prompt-caching/anthropic-no-cache-control.ts | Control scenario validating cache behavior |
| typescript/ai-sdk-v5/src/prompt-caching/anthropic-multi-message-cache.ts | Multi-turn conversation caching example |
| docs/prompt-caching.md | Links to new AI SDK v5 examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
typescript/ai-sdk-v5/src/prompt-caching/anthropic-user-message-cache.ts
Outdated
Show resolved
Hide resolved
typescript/ai-sdk-v5/src/prompt-caching/anthropic-no-cache-control.ts
Outdated
Show resolved
Hide resolved
typescript/ai-sdk-v5/src/prompt-caching/anthropic-multi-message-cache.ts
Outdated
Show resolved
Hide resolved
This was referenced Nov 11, 2025
998a95f to
08b17d0
Compare
This was referenced Nov 12, 2025
08b17d0 to
5138ba6
Compare
56a6d62 to
86e729c
Compare
42726ef to
6a73a21
Compare
86e729c to
eb2df02
Compare
6a73a21 to
0147fbe
Compare
louisgv
reviewed
Nov 13, 2025
| "dependencies": { | ||
| "@openrouter-examples/shared": "workspace:*", | ||
| "@openrouter/ai-sdk-provider": "1.2.2", | ||
| "ai": "^5.0.92" |
louisgv
approved these changes
Nov 13, 2025
Contributor
Author
Merge activity
|
0147fbe to
bfdfeeb
Compare
eb2df02 to
62ba78a
Compare
- Add typescript/ai-sdk-v5/src/prompt-caching/user-message-cache.ts - Demonstrates cache_control using providerOptions.openrouter.cacheControl - Shows critical configuration: extraBody.stream_options.include_usage - Evidence-based verification via providerMetadata.openrouter.usage
Add FIXME comments noting that providerMetadata.openrouter.usage should be properly typed as OpenRouterUsage instead of JSONValue.
- Update package.json scripts to use correct anthropic- prefixed filenames - Fix file path references in comments and README - Fix model name consistency (claude-3.5-sonnet → claude-3-5-sonnet) - Update README to reference directory instead of single file
Copilot feedback: Model name 'claude-3-5-sonnet' vs 'claude-3.5-sonnet' inconsistency. Solution: Remove 'AI SDK v5 Usage' section entirely - complete code in example files. Prevents docs from going stale when models/APIs change.
Replace hardcoded filename list with run-examples.ts that auto-discovers all .ts files in src/ Benefits: - Add new example → automatically included in 'bun examples' - Rename example → no package.json update needed - Impossible for package.json to reference non-existent files
- Replace local docs link with https://openrouter.ai/docs/features/prompt-caching - Ensures documentation stays current and avoids duplication
bfdfeeb to
f9b8149
Compare
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.

Add prompt-caching examples for AI SDK v5
Run biome format and fix lint issues
Simplify AI SDK v5 prompt-caching README to link to main docs
Rename prompt caching examples with anthropic prefix