Skip to content

feat(bedrock): add support for count_tokens#1141

Open
Ashutosh0x wants to merge 5 commits intoanthropics:mainfrom
Ashutosh0x:feat/bedrock-count-tokens
Open

feat(bedrock): add support for count_tokens#1141
Ashutosh0x wants to merge 5 commits intoanthropics:mainfrom
Ashutosh0x:feat/bedrock-count-tokens

Conversation

@Ashutosh0x
Copy link

This PR adds support for the \count_tokens\ method to the \AnthropicBedrock\ client by routing requests to the Bedrock Runtime \CountTokens\ API.

Including the 'caller' field in 'tool_use' blocks within input
messages causes API errors (especially for computer-use) because
the API expects only standard fields like id, name, type, and input.

This field was recently added to the SDK models and parameters but
should not be sent back to the API.

This PR:
1. Removes 'caller' from BetaToolUseBlockParam and
   BetaServerToolUseBlockParam.
2. Adds __api_exclude__ = {"caller"} to BetaToolUseBlock and
   BetaServerToolUseBlock models.
3. Modifies the internal transformer to explicitly strip 'caller'
   if it's not annotated in a TypedDict, ensuring raw dicts or
   unfiltered model dumps don't leak it back to the API.

Fixes anthropics#1112
@Ashutosh0x Ashutosh0x requested a review from a team as a code owner January 22, 2026 04:50
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