puter icon indicating copy to clipboard operation
puter copied to clipboard

feat: meter Gemini thinking tokens and grounding requests

Open Aaryan-Dadu opened this issue 6 months ago • 3 comments

Summary

  • Thinking tokens: Extracted from standard completion tokens to ensure they are billed accurately at the correct model specific rate.
  • Grounding requests: Added flat-fee metering for Google Search by tracking grounding_metadata across both streaming and non-streaming responses.
  • Pricing updates: Corrected stale rates for Gemini 2.5 Flash output, cached tokens, thinking tokens, and grounding requests.

Closes #3132

Test

  • All pre-existing tests pass.
  • 5 unit tests for the corresponding changes have been added
  • 4 pre-existing test assertions updated to include thinking_tokens: 0 and grounding_requests: 0 in the expected usage shapes Screenshot From 2026-05-28 15-12-15

Aaryan-Dadu avatar May 28 '26 09:05 Aaryan-Dadu

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 28 '26 09:05 CLAassistant

are thinking tokens not already included in output tokens in the usage object?

ProgrammerIn-wonderland avatar May 29 '26 18:05 ProgrammerIn-wonderland

are thinking tokens not already included in output tokens in the usage object?

Yes they are already included but we split them because they are billed at different rates, like this: thinking_rate*thinking_tokens + standard_rate*(completion_tokens - thinking_tokens)

Aaryan-Dadu avatar May 29 '26 19:05 Aaryan-Dadu

@ProgrammerIn-wonderland is this mergable?

Salazareo avatar Jun 10 '26 00:06 Salazareo