Repository navigation
fix(core): bill gemini thinking tokens when attaching model pricing - #1427
Merged
willkill07 merged 2 commits intoOct 21, 2026
Merged
willkill07 merged 2 commits into
willkill07 merged 2 commits into
Conversation
- attach_estimated_cost_for_provider bills gemini thoughts_tokens at the output rate through billed_usage - checked token sums so an overflowing gemini total or billed output count leaves total_tokens or cost unset - test: thinking-token billing and overflow cases Signed-off-by: Greyson Lalonde <[email protected]>
Contributor
2 tasks done
willkill07
reviewed
Oct 21, 2026
willkill07
left a comment
Member
There was a problem hiding this comment.
I really like the logic improvements to model_pricing.rs
willkill07
approved these changes
Oct 21, 2026
willkill07
pushed a commit
that referenced
this pull request
Oct 21, 2026
#### Overview <!-- Describe your pull request here --> Fixes gemini usage accounting to include tool-use prompt tokens and their associated input costs. - [x] I confirm this contribution is my own work, or I have the right to submit it under this project's license. - [x] I searched existing issues and open pull requests, and this does not duplicate existing work. #### Details <!-- Describe the changes made in this PR. --> - added `tool_use_prompt_tokens` to `ApiSpecificResponse::GeminiGenerateContent`, parsed from `toolUsePromptTokenCount`. rust code constructing this variant must provide this field. - included tool-use prompt tokens in `total_tokens`, consistent with google `totalTokenCount`. - added input-rate costs for tool-use prompt tokens, excludes them when grounding metadata shows google search or google maps, as those are per-request, google doesn't document retrieved context as input tokens. - select prompt-token pricing tier using the reported prompt count before adding tool-use prompt tokens. - added tests for token totals, `api_specific`, input-rate billing, grounding exclusions, pricing tiers, input overflow, and redaction pass-through. - documented `tool_use_prompt_tokens` and billing in `provider-response-codecs.mdx`. #### Where should the reviewer start? <!-- Point to the most important file, test, or design decision. --> `billed_usage` and `ToolUsePromptBilling` in `crates/core/src/codec/model_pricing.rs` #### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to) - Relates to #1427 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Gemini response details now include tool-use prompt tokens. - Gemini billing accounts for thinking tokens, tool usage, grounding, URL context, and code execution. - Pricing tiers use the original prompt-token count for more accurate estimates. - **Bug Fixes** - Improved fallback token totals and cost calculations. - Costs are omitted when usage exceeds supported billing limits or billing evidence is inconclusive. - **Documentation** - Updated guidance on Gemini token accounting and billing rules. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Greyson Lalonde <[email protected]>
This branch was previously 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.
Overview
Details
billed_usagefoldsthoughts_tokensinto billed output count forattach_estimated_cost_for_providerand built-in gemini codec.total_tokensor the cost estimate unset.Where should the reviewer start?
billed_usageincrates/core/src/codec/model_pricing.rs.Summary by CodeRabbit
Bug Fixes
Documentation