fix: vertex count tokens unsupported fields - #5619
Merged
Merged
Conversation
Contributor
📝 WalkthroughWalkthroughVertex CountTokens request sanitization now uses a centralized helper that removes unsupported ChangesVertex CountTokens sanitization
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
TejasGhatte
marked this pull request as ready for review
July 28, 2026 12:59
Collaborator
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
18 tasks
This was referenced Jul 29, 2026
Contributor
Merge activity
|
akhsaul
pushed a commit
to akhsaul/bifrost
that referenced
this pull request
Aug 27, 2026
## Summary The Vertex `countTokens` endpoint rejects several fields that are valid in `generateContent` requests, causing 400 errors. Previously, the field-stripping logic incorrectly removed `generationConfig` and `systemInstruction`, which the `countTokens` endpoint actually supports and uses to produce accurate token counts. This PR fixes the set of fields being stripped and consolidates the logic into a dedicated helper. ## Changes - Introduced `stripVertexCountTokensUnsupportedFields` to replace the inline ad-hoc field deletions in `CountTokens`. The new helper drops only the fields the `countTokens` endpoint actually rejects: `toolConfig`, `safetySettings`, `cachedContent`, `serviceTier`, and `labels`. - Removed the incorrect stripping of `generationConfig` and `systemInstruction`, both of which are valid and meaningful to the `countTokens` endpoint. - Added unit tests covering: fields that should be preserved, fields that should be dropped, and a nil/empty body edge case. ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [x] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./core/providers/vertex/... ``` Verify that `TestStripVertexCountTokensUnsupportedFields` passes, confirming that `systemInstruction`, `tools`, and `generationConfig` survive stripping while `toolConfig`, `safetySettings`, `cachedContent`, `serviceTier`, and `labels` are removed. ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations No security implications. This change only affects which JSON fields are forwarded to the Vertex `countTokens` endpoint. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
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.

Summary
The Vertex
countTokensendpoint rejects several fields that are valid ingenerateContentrequests, causing 400 errors. Previously, the field-stripping logic incorrectly removedgenerationConfigandsystemInstruction, which thecountTokensendpoint actually supports and uses to produce accurate token counts. This PR fixes the set of fields being stripped and consolidates the logic into a dedicated helper.Changes
stripVertexCountTokensUnsupportedFieldsto replace the inline ad-hoc field deletions inCountTokens. The new helper drops only the fields thecountTokensendpoint actually rejects:toolConfig,safetySettings,cachedContent,serviceTier, andlabels.generationConfigandsystemInstruction, both of which are valid and meaningful to thecountTokensendpoint.Type of change
Affected areas
How to test
go test ./core/providers/vertex/...Verify that
TestStripVertexCountTokensUnsupportedFieldspasses, confirming thatsystemInstruction,tools, andgenerationConfigsurvive stripping whiletoolConfig,safetySettings,cachedContent,serviceTier, andlabelsare removed.Screenshots/Recordings
N/A
Breaking changes
Related issues
Security considerations
No security implications. This change only affects which JSON fields are forwarded to the Vertex
countTokensendpoint.Checklist
docs/contributing/README.mdand followed the guidelines