Skip to content

feat: add /tokenize for chat completion on aws bedrock converse api#2404

Open
hustxiayang wants to merge 3 commits into
envoyproxy:mainfrom
hustxiayang:tokenize-bedrock
Open

feat: add /tokenize for chat completion on aws bedrock converse api#2404
hustxiayang wants to merge 3 commits into
envoyproxy:mainfrom
hustxiayang:tokenize-bedrock

Conversation

@hustxiayang

@hustxiayang hustxiayang commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description
Add /tokenize support for chat completion on AWS Bedrock Converse API CountTokens API. This is a split from #1650 as planned.

@hustxiayang
hustxiayang requested a review from a team as a code owner July 21, 2026 18:51
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 21, 2026
@hustxiayang

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@aabchoo

aabchoo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@hustxiayang

Copy link
Copy Markdown
Contributor Author

/retest

@codecov-commenter

codecov-commenter commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.30108% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.84%. Comparing base (7632b9d) to head (943374c).

Files with missing lines Patch % Lines
internal/translator/converse_helper.go 79.16% 45 Missing and 10 partials ⚠️
internal/translator/tokenize_awsbedrock.go 77.77% 12 Missing and 10 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2404      +/-   ##
==========================================
- Coverage   84.85%   84.84%   -0.01%     
==========================================
  Files         154      156       +2     
  Lines       22405    22508     +103     
==========================================
+ Hits        19011    19097      +86     
- Misses       2238     2245       +7     
- Partials     1156     1166      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

  Adds /tokenize support for AWS Bedrock via the Converse-style CountTokens
  API (AWSBedrock schema), reusing awsbedrock.CountTokensResponse. Completion
  prompts are converted to chat messages. Also fixes two loop-variable
  address-of patterns flagged in review. Registers the schema in the
  tokenize endpoint spec.

Signed-off-by: yxia216 <yxia216@bloomberg.net>
@hustxiayang
hustxiayang marked this pull request as draft July 21, 2026 20:48
Signed-off-by: yxia216 <yxia216@bloomberg.net>
@hustxiayang
hustxiayang marked this pull request as ready for review July 22, 2026 01:28
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 22, 2026

// openAIToolsToBedrockToolConfig converts openai ChatCompletion tools (and optional
// tool_choice) into an aws bedrock tool configuration. toolChoice may be nil.
func openAIToolsToBedrockToolConfig(tools []openai.Tool, toolChoice *openai.ChatCompletionToolChoiceUnion, model string,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please introduce tests for this file?

// only. This is provider-agnostic (unlike the Anthropic-specific path) because the Converse
// translator also serves Amazon Nova, Meta Llama, etc.
// See: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_CountTokens.html
for _, prefix := range []string{"us-gov.", "us.", "eu.", "apac.", "global."} {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing:

  • uk.
  • au.
  • jp.

Comment on lines +643 to +644
type CountTokensConverseInput struct {
Messages []*Message `json:"messages"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing omitempty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants