Skip to content

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

Closed
Rima-ag wants to merge 10 commits intoopen-telemetry:mainfrom
Rima-ag:thoughts-tokens
Closed

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

Conversation

@Rima-ag
Copy link
Copy Markdown
Contributor

@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.

#3890
Related to open-telemetry/semantic-conventions#3194

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
Copy Markdown

linux-foundation-easycla Bot commented Feb 14, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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

@DylanRussell
Copy link
Copy Markdown
Contributor

Ah forgot this was open and opened the exact same PR: #4493

@Rima-ag
Copy link
Copy Markdown
Contributor Author

Rima-ag commented Apr 28, 2026

@DylanRussell I just resolved the conflicts, would you mind having a look?

I have a followup draft PR #4276 to report thinking tokens in a separate field too and will request review as soon as this one is merged

@DylanRussell
Copy link
Copy Markdown
Contributor

Rima I think we should go ahead and merge my PR which is all ready: #4493

@Rima-ag Rima-ag closed this May 2, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in Python PR digest May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gen-ai Related to generative AI hold

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

10 participants