Skip to content

bugfix: include reasoning tokens to completion tokens for google provider #6738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

modestaspruckus
Copy link

@modestaspruckus modestaspruckus commented Jun 13, 2025

Background

Gemini 2.5 pro latest snapshot 06-05 have thinking mode enabled by default. It is not reliable to track costs of tokens because reasoning tokens are not accumulated into output tokens.

Summary

  • I have added additional method which calculates reasoning tokens from total token count and accumulates them into output tokens.

Verification

  • usageMetadata returns totalTokenCount where totalTokenCount != (promptTokenCount + candidatesTokenCount) because thoughtsTokenCount is not included

image

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

Ideally sdk could expose thoughtTokens seperately or proxy total token count without auto calculation.

Related Issues

#6082

bugfix: include reasoning tokens to completion tokens
@modestaspruckus modestaspruckus changed the title bugfix: include reasoning tokens to completion tokens bugfix: include reasoning tokens to completion tokens for google provider Jun 13, 2025
@modestaspruckus
Copy link
Author

@lgrammel could you take a look at this one pls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant