Skip to content

Conversation

@subtleGradient
Copy link
Contributor

Add prompt-caching examples for AI SDK v5

  • 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

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

Copy link
Contributor Author

subtleGradient commented Nov 11, 2025

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@socket-security
Copy link

socket-security bot commented Nov 11, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​openrouter/​ai-sdk-provider@​1.2.210010010097100
Addedai@​5.0.93100100100100100

View full report

@subtleGradient subtleGradient marked this pull request as ready for review November 11, 2025 23:53
Copilot AI review requested due to automatic review settings November 11, 2025 23:53
Copilot finished reviewing on behalf of subtleGradient November 11, 2025 23:55
Copy link

Copilot AI left a 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.cacheControl usage 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.

- 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
"dependencies": {
"@openrouter-examples/shared": "workspace:*",
"@openrouter/ai-sdk-provider": "1.2.2",
"ai": "^5.0.92"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

freeze deps

Copy link
Contributor Author

subtleGradient commented Nov 13, 2025

Merge activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants