Skip to content

Count Gemini Live reasoning tokens in text output usage - #1517

Open
pcbeingused33 wants to merge 1 commit into
SciSharp:masterfrom
pcbeingused33:fix/gemini-live-thought-token-usage
Open

pcbeingused33 wants to merge 1 commit into
SciSharp:masterfrom
pcbeingused33:fix/gemini-live-thought-token-usage

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Gemini Live sends reasoning usage separately as thoughtsTokenCount. BotSharp drops that field during deserialization and calculates text output cost from the reported TEXT modality alone. Google bills reasoning tokens at the text output rate. Google AI Developers Forum

Read thoughtsTokenCount from Live usage metadata and add it to the text output count passed to the content hooks. A missing field contributes zero. Audio output continues to use the reported AUDIO count.

The regression test deserializes a completed audio turn with a transcript, then checks that the content hook receives 42 audio output tokens and 17 text output tokens.

dotnet test tests/BotSharp.Core.UnitTests/BotSharp.Core.UnitTests.csproj --filter FullyQualifiedName~GoogleAiRealtimeUsageTests

This change was prepared with assistance from an AI coding tool (Codex).

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

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