Skip to content

Comments

google-genai: include thinking tokens in output token count#4206

Open
Rima-ag wants to merge 5 commits intoopen-telemetry:mainfrom
Rima-ag:thoughts-tokens
Open

google-genai: include thinking tokens in output token count#4206
Rima-ag wants to merge 5 commits intoopen-telemetry:mainfrom
Rima-ag:thoughts-tokens

Conversation

@Rima-ag
Copy link

@Rima-ag Rima-ag commented Feb 14, 2026

Description

Updates the Google GenAI instrumentation to include thinking tokens in the total output token count.

Previously only candidate tokens were counted in the output_tokens, resulting in inaccurate cost estimations for models that produce separate thinking tokens.

Thinking tokens are reported in GenerateContentResponseUsageMetadata.thoughts_token_count.

Fixes #3890

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit tests

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 14, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Rima-ag / name: Rima-ag (5ed7c8d)

@Rima-ag Rima-ag changed the title Thoughts tokens Include thinking tokens in output tokens Feb 14, 2026
@Rima-ag Rima-ag changed the title Include thinking tokens in output tokens Fix: include thinking tokens in Google GenAI output token count Feb 14, 2026
@Rima-ag Rima-ag changed the title Fix: include thinking tokens in Google GenAI output token count google-genai: include thinking tokens in output token count Feb 14, 2026
@Rima-ag Rima-ag marked this pull request as ready for review February 19, 2026 19:50
@Rima-ag Rima-ag requested a review from a team as a code owner February 19, 2026 19:50
@Rima-ag
Copy link
Author

Rima-ag commented Feb 19, 2026

i just saw open-telemetry/semantic-conventions#3383 that adds gen_ai.usage.reasoning.output_tokens to spans, should i followup on this PR by filling this field once the semantic convention is merged?

@aabmass
Copy link
Member

aabmass commented Feb 19, 2026

I think @DylanRussell can help decide here. It would be nice to get the general convention in as well. At least we should define a gcp.* one if it's not generalizable.

@DylanRussell
Copy link
Contributor

Isn't open-telemetry/semantic-conventions#3383 a general convention for an attribute on both logs on spans ? Yes I think we should wait for that to be merged if this isn't urgent, there are still a couple unresolved things on that PR

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.

Google GenAI instrumentation needs to count thinking tokens

8 participants