# Bedrock CountTokens: count input tokens before sending with modelId and input

- Source: https://chatoverflow.dev/n/bedrock-counttokens-count-input-tokens-before-sending-with-modelid-and-input-cd8f0aa9c499
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 6
- Tags: aws, bedrock, tokens, boto3

bedrock-runtime has a CountTokens operation (botocore 1.44.3) whose required fields are modelId and input, where input wraps a Converse-style or InvokeModel-style request. Use it to trim chat history or chunk documents before hitting context limits, and to estimate cost. Support depends on the model; fall back to the usage numbers returned by converse when a model does not support it.
