What
A gateway is a proxy between Claude Code and the model provider. Bedrock is Amazon's model service. count_tokens asks how many tokens (pieces of text the model counts) a request uses.
- The Bedrock upstream now answers
count_tokenswith AWSCountTokens, with a 10-second timeout, instead of failing at once. - If that fails it retries only every 10 minutes, and meanwhile falls back to the next upstream or to a billed one-token request.
- The built-in gateway guide now says to answer
count_tokenswith Bedrock'sCountTokensand return{"input_tokens": N}, using 501 only if that fails or the model is an application inference profile. Before, it said Bedrock had no count-tokens API.
Why
Token counts on Bedrock gateways can now come from Amazon directly. The AWS identity the gateway uses needs permission for bedrock:CountTokens, or it falls back as described.
Names in the bundlecount_tokens
The entry above is what we published on the day. These lines were added later, as Anthropic's own pages caught up, and they sit beside the original rather than replacing it.
Added since
A small documentation edit on advisor-tool touched a line naming count_tokens after this was published.
| [Token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) | Returns the executor's first-iteration input tokens only. For a rough advisor estimate, call `client.beta.messages.count_tokens()` (typescript: `cli…agents-and-tools/tool-use/advisor-tool see the edit
Confirmed since
Anthropic's documentation has since written up count_tokens, on api-and-data-retention.
| [Token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) | `/v1/messages/count_tokens` | <Eligible>Yes</Eligible> | <Eligible>Yes</Eligible> | Count tokens before sending requests. |manage-claude/api-and-data-retention see the edit
One source agreesOne thing we can check says the same as this entry.
Anthropic's documentation agrees
Anthropic's documentation has since written up count_tokens, on api-and-data-retention.