Repository navigation
feat(ai-anthropic, ai-bedrock, ai-claude-code)!: report the total input in promptTokens - #1677
Conversation
…t in promptTokens promptTokens is now uncached + cache read + cache write on the Anthropic, Bedrock Converse, and Claude Code adapters. totalTokens follows. The cache parts stay in promptTokensDetails.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (15)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe Anthropic, Bedrock, and Claude Code adapters now include cache-read and cache-write tokens in ChangesCached Prompt Usage
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The adapters and documentation consistently describe full-input prompt tokens. No identified issue prevents merging after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)Full details: Docstring CoverageExplanation Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 9 files. (6 skipped: 6 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
|
View your CI Pipeline Execution ↗ for commit d8aa49e
☁️ Nx Cloud last updated this comment at |
Coverage✅ Coverage held across 4 compared package(s). Each package is measured twice in this job — on this PR and on its merge-base with
|
@tanstack/ai
@tanstack/ai-acp
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-bedrock
@tanstack/ai-byteplus
@tanstack/ai-claude-code
@tanstack/ai-client
@tanstack/ai-cloudflare
@tanstack/ai-code-mode
@tanstack/ai-code-mode-snippets
@tanstack/ai-codex
@tanstack/ai-cohere
@tanstack/ai-compaction
@tanstack/ai-devtools-core
@tanstack/ai-durable-stream
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-grok-build
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-daytona
@tanstack/ai-isolate-e2b
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-isolate-quickjs-bun
@tanstack/ai-llmgateway
@tanstack/ai-lovable
@tanstack/ai-mcp
@tanstack/ai-memory
@tanstack/ai-mistral
@tanstack/ai-octane
@tanstack/ai-ollama
@tanstack/ai-ollaya
@tanstack/ai-openai
@tanstack/ai-opencode
@tanstack/ai-openrouter
@tanstack/ai-perplexity
@tanstack/ai-persistence
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-reactor
@tanstack/ai-remix
@tanstack/ai-sandbox
@tanstack/ai-sandbox-blaxel
@tanstack/ai-sandbox-boxd
@tanstack/ai-sandbox-cloudflare
@tanstack/ai-sandbox-daytona
@tanstack/ai-sandbox-docker
@tanstack/ai-sandbox-e2b
@tanstack/ai-sandbox-local-process
@tanstack/ai-sandbox-railway
@tanstack/ai-sandbox-sprites
@tanstack/ai-sandbox-upstash-box
@tanstack/ai-sandbox-vercel
@tanstack/ai-skills
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-typesafe
@tanstack/ai-utils
@tanstack/ai-vercel-gateway
@tanstack/ai-vertex
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/ai-worldlabs
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
@tanstack/svelte-ai-devtools
commit: |
usage.promptTokensnow counts the whole input on Anthropic, Bedrock Converse, and Claude Code: uncached tokens, plus cache reads, plus cache writes. Before, these three adapters counted only the uncached tokens, while every other adapter counted the total.totalTokensfollows the new value. The cache split stays inpromptTokensDetails.This PR is split out of #1555.
🎯 Changes
ai-anthropic(src/usage.ts),ai-bedrock(src/converse/usage.ts), andai-claude-code(src/stream/translate.ts) addcachedTokensandcacheWriteTokensintopromptTokens.totalTokensis never less than the sum of the parts.message_startfallback (start) now also covers the cache counts.cacheWrite1hTokens. It ships later with the model catalog.## Token usagesection inchat/stream-events.md, with an upgrade note.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.docs/for this change, or this change is not user-facing.pnpm changeset), or this PR does not change a published package.🚀 Release Impact
Testing
Commands run
vitest run:ai-anthropic194 tests,ai-bedrock120 tests,ai-claude-code71 tests. All pass.test:typesandtest:oxlintfor the three packages: both pass.pnpm test:docs: no broken links.pnpm test:prand the E2E suite. CI runs them.Manual test
pnpm --dir packages/ai-anthropic exec vitest run tests/usage-extraction.test.ts.input_tokens: 100,cache_read_input_tokens: 25, andcache_creation_input_tokens: 50reportspromptTokens: 175.packages/ai-bedrock(the usage tests) andpackages/ai-claude-code(the translate tests).How this PR makes testing easy
anthropic-structured-usage.spec.tschanges from 125 to 5885, andbedrock-converse-cache.spec.tschanges from 3 to 8412. The aimock responses inglobal-setup.tshard-code the cache counts (5760 and 8409), so the new values come from this change only.Risk / rollback
Breaking for one pattern. Code that adds
cachedTokens(orcacheWriteTokens) topromptTokensto get the total now counts the cache two times. Fix: usepromptTokensas the total. Cost dashboards built on the old number show a larger input count after the upgrade. To undo, revert this PR.Public API change
Before (Anthropic with a cache hit)
After
Summary by CodeRabbit
Bug Fixes
promptTokensandtotalTokens, providing a more complete view of usage.Documentation
promptTokens, which would double-count them.