fix(ai-anthropic): pass system prompts as TextBlockParam[] to support prompt caching#393
fix(ai-anthropic): pass system prompts as TextBlockParam[] to support prompt caching#393imsherrill wants to merge 2 commits intoTanStack:mainfrom
Conversation
… prompt caching The Anthropic adapter joined system prompts into a plain string before passing them to the API. This prevented using Anthropic's prompt caching on system prompts, since only the array form (TextBlockParam[]) supports cache_control. Convert systemPrompts to TextBlockParam[] so that users can override with cache_control via modelOptions.system.
…ersion Verify that systemPrompts are passed as TextBlockParam[] (not a joined string) and that modelOptions.system with cache_control takes precedence.
|
View your CI Pipeline Execution ↗ for commit 7ad955e
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-devtools-core
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-groq
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-openrouter
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Anthropic adapter's system prompt handling was updated to pass system prompts as an array of text blocks ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Changes
The Anthropic adapter joins system prompts into a plain string before passing them to the API:
This prevents using Anthropic's prompt caching on system prompts. The Anthropic SDK accepts
systemas eitherstringorTextBlockParam[], and only the array form supportscache_control.This PR converts
systemPromptstoTextBlockParam[]instead of joining to a string. Users who wantcache_controlcan pass structured blocks viamodelOptions.system, which already takes priority via the provider options spread.systemPrompts: ['...']usage works identicallyInternalTextProviderOptions.systemtype already acceptsstring | Array<TextBlockParam>Closes #379
Checklist
pnpm run test:pr.Release Impact
Summary by CodeRabbit
Refactor
Tests