feat: expose cached token count in usage statistics#636
Conversation
Provider adapters now forward cached/prompt-cache token counts into the unified `cachedTokens` field on `RunFinishedEvent.usage`, `UsageInfo`, and `FinishInfo`. This lets consumers calculate accurate costs by distinguishing cached vs uncached input tokens. Provider mapping: - OpenAI Chat Completions: `prompt_tokens_details.cached_tokens` - OpenAI Responses API: `input_tokens_details.cached_tokens` - Anthropic: `cache_read_input_tokens` - Gemini: `usageMetadata.cachedContentTokenCount` - OpenRouter: `promptTokensDetails.cachedTokens` - Groq/Grok: inherited from openai-base - Ollama: no caching support (field omitted) The field is optional — only present when the provider returns a non-null value, so existing consumers are unaffected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
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 (7)
📝 WalkthroughWalkthroughThis PR adds support for forwarding cached token counts from AI provider APIs through ChangesCached Token Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 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)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: lockfile failed supply-chain policy check. Run 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 |
Provider adapters now forward cached/prompt-cache token counts into the unified
cachedTokensfield onRunFinishedEvent.usage,UsageInfo, andFinishInfo. This lets consumers calculate accurate costs by distinguishing cached vs uncached input tokens.Provider mapping:
prompt_tokens_details.cached_tokensinput_tokens_details.cached_tokenscache_read_input_tokensusageMetadata.cachedContentTokenCountpromptTokensDetails.cachedTokensThe field is optional — only present when the provider returns a non-null value, so existing consumers are unaffected.
Usage