Skip to content

fix(model): count document context budget with client tokenizers - #3254

Draft
kunal0137 wants to merge 1 commit into
devfrom
fix-context-budget-tokenizers
Draft

kunal0137 wants to merge 1 commit into
devfrom
fix-context-budget-tokenizers

Conversation

@kunal0137

Copy link
Copy Markdown
Collaborator

The attachment preflight counted UTF-8 bytes of the serialized messages as tokens, so a ~40K-token request with a docx was rejected against a 262K window. Count the built provider request with the client's own counter (tiktoken, Anthropic/Bedrock/Google count_tokens, or an optional vLLM /tokenize endpoint) and fall back to bytes / 3 when none is available.

Adds an optional tokenize_endpoint kwarg to OpenAiClient.

Description

Changes Made

How to Test

  1. Steps to reproduce/test the behavior
  2. Expected outcomes

Notes

The attachment preflight counted UTF-8 bytes of the serialized messages
as tokens, so a ~40K-token request with a docx was rejected against a
262K window. Count the built provider request with the client's own
counter (tiktoken, Anthropic/Bedrock/Google count_tokens, or an optional
vLLM /tokenize endpoint) and fall back to bytes / 3 when none is available.

Adds an optional tokenize_endpoint kwarg to OpenAiClient.
@snyk-io

snyk-io Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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