-
Notifications
You must be signed in to change notification settings - Fork 43
Add prompt-caching examples for AI SDK v5 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pdf-example-fetch
Are you sure you want to change the base?
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
998a95f to
08b17d0
Compare
08b17d0 to
5138ba6
Compare
56a6d62 to
86e729c
Compare
42726ef to
6a73a21
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
86e729c to
eb2df02
Compare
6a73a21 to
0147fbe
Compare
| "dependencies": { | ||
| "@openrouter-examples/shared": "workspace:*", | ||
| "@openrouter/ai-sdk-provider": "1.2.2", | ||
| "ai": "^5.0.92" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
freeze deps
Merge activity
|

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