I’m building a Node.js application that uses Gemini’s streaming content API, and I’m trying to figure out how to track token usage for streamed responses.
Specifically, I’m using the generateContentStream method from the @google/genai SDK:
const { GoogleGenAI, ThinkingLevel } = require(“@google/genai”);
My use case requires knowing how many tokens are consumed so I can apply usage limits and enforce quotas for users. With OpenAI’s streaming APIs, this is straightforward because the SDK includes token usage and metadata as part of the streamed response.
However, I can’t find any way to access token usage information when using Gemini’s generateContentStream. This feels like a critical feature for production applications, especially when implementing billing, rate limiting, or usage caps.
Am I missing something, or is token usage simply not exposed for streaming responses in Gemini yet? If there’s a recommended workaround or best practice, I’d really appreciate any guidance.