fix(anthropic): strip server-side tools from count_tokens requests (#5702)#5705
Closed
MohammadYusif wants to merge 1 commit into
Closed
fix(anthropic): strip server-side tools from count_tokens requests (#5702)#5705MohammadYusif wants to merge 1 commit into
MohammadYusif wants to merge 1 commit into
Conversation
…ydantic#5702) The Anthropic count_tokens endpoint rejects server-side tools such as CodeExecutionTool, WebSearchTool, and WebFetchTool with a 400 error ("Server tools are not supported in the count_tokens endpoint"). `_messages_count_tokens` was forwarding the full tool list produced by `_add_native_tools` — including those server tools — unchanged to the endpoint. The fix filters out any tool whose `type` field starts with a server-tool prefix before the call, preserving all function/memory/ tool-search/MCP tools that the endpoint does accept. Adds a unit test that verifies each server-side native tool is excluded from the count_tokens payload.
Contributor
|
Thanks for your interest in this issue! However, there are already open PRs addressing issue #5702: #5704, #5703. To avoid duplicate efforts, this PR has been closed. If you'd like to contribute, you can review the existing PRs or share your thoughts on issue #5702. If you believe the existing PRs are inactive, please comment on the issue and a maintainer can reassess. |
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.
The Anthropic count_tokens endpoint rejects server-side tools such as
CodeExecutionTool, WebSearchTool, and WebFetchTool with a 400 error
("Server tools are not supported in the count_tokens endpoint").
_messages_count_tokenswas forwarding the full tool list produced by_add_native_tools— including those server tools — unchanged to theendpoint. The fix filters out any tool whose
typefield starts with aserver-tool prefix before the call, preserving all function/memory/
tool-search/MCP tools that the endpoint does accept.
Adds a unit test that verifies each server-side native tool is excluded
from the count_tokens payload.
Checklist