fix(gemini): surface token usage from image generateContent path (#330)#655
Conversation
The Gemini image adapter hardcoded `usage: undefined`, so the `image:usage` devtools event never fired for Gemini image generation even though the `generateContent` response carries `usageMetadata`. Parse `usageMetadata` (promptTokenCount / candidatesTokenCount / totalTokenCount) into `ImageGenerationResult.usage` on the native path, matching the convention used by the Gemini text adapter. The Imagen (`generateImages`) path is left as-is because that SDK response type does not expose `usageMetadata`. Co-Authored-By: Claude Opus 4.8 (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 (3)
📝 WalkthroughWalkthroughThe Gemini image adapter now extracts and exposes token usage metadata from the generateContent API response. The implementation parses usageMetadata fields into a standardized usage object, backed by a test case that validates the mapping, and documented in a patch changeset. ChangesGemini image adapter usage metadata
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 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 docstrings
🧪 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. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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 |
🚀 Changeset Version Preview8 package(s) bumped directly, 22 bumped as dependents. 🟥 Major bumps
🟨 Minor bumps
🟩 Patch bumps
|
|
View your CI Pipeline Execution ↗ for commit 8106603
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-skills
@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-isolate-cloudflare
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@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-utils
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
🎯 Changes
Fixes #330. The Gemini image adapter hardcoded
usage: undefined, soImageGenerationResult.usagewas never populated and theimage:usagedevtools event never fired for Gemini image generation — even though thegenerateContentresponse carriesusageMetadata.This parses
usageMetadata(promptTokenCount/candidatesTokenCount/totalTokenCount) intousageon the nativegenerateContentpath (e.g. Nano Banana), matching the convention already used by the Gemini text adapter.The Imagen (
generateImages) path is intentionally left unchanged: theGenerateImagesResponseSDK type does not exposeusageMetadata, so parsing it there would require a speculativeas anycast for a field that may never exist.✅ Checklist
pnpm run test:pr.🚀 Release Impact
🤖 Generated with Claude Code
Summary by CodeRabbit