Repository navigation
fix(google): count tool-use prompt tokens as input tokens - #485
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GoogleProvider.value_tokens()reportedprompt_token_count(minus cached) as the input tokens and ignoredtool_use_prompt_token_count. Gemini reports the tokens of content fetched by built-in tools (URL context, search, ...) there, separately from the prompt, and Google's URL context documentation says that content "is counted as part of the input tokens". A turn that fetched a large page therefore under-reported its input tokens and cost: withprompt_token_count=27,tool_use_prompt_token_count=10309,candidates_token_count=40andthoughts_token_count=200, the turn tokens were(27, 240, 0).value_tokens()now addstool_use_prompt_token_countto the input tokens, giving(10336, 240, 0)for that response. Responses without tool-use tokens are unchanged.Tests:
test_google_value_tokens_counts_tool_use_prompt_tokens_as_inputuses a realGenerateContentResponseUsageMetadataand fails on main;test_google_value_tokens_without_tool_use_prompt_tokenschecks the cached-token case is unchanged. CHANGELOG entry added.This change was made with Claude Code.
🤖 Generated with Claude Code
🤖 Generated with Claude Code