Follow Discord
Sweep 20 Nov 2026 · 19:55Z Build v2.1.330 547 read Stable v2.1.323 Latest v2.1.330 Next v2.1.330 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

Count tokens in a Message changedapi/beta/messages/count_tokens

Nearest release: v2.1.328, published under an hour before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+70added
Lines−0removed
From line 4,142 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits34to this page, all time

## Errors

The whole hunk

from line 4142, old and new numbered
/
lines
from line 4142
41424142 
41434143 The total number of tokens across the provided list of messages, system prompt, and tools.
41444144 
4145## Errors
4146 
4147Any method can also return the general [HTTP errors](https://platform.claude.com/docs/en/api/errors?sdk_languages=http).
4148 
4149Each code below is the value of `error.details.error_code` in the response body.
4150 
4151- `available_tools_limit_exceeded` (HTTP status 400)
4152 
4153 The tools available after a message exceed a limit on their number or their size.
4154 
4155- `claude_code_key_creator_not_member` (HTTP status 400)
4156 
4157 The API key belongs to the Claude Code workspace, and the user who created it is no longer a member of the organization or of that workspace.
4158 
4159- `compaction_block_ambiguous` (HTTP status 400)
4160 
4161 `messages` holds more than one `compaction` block with content. Send only the block the conversation returned last.
4162 
4163- `compaction_block_misplaced` (HTTP status 400)
4164 
4165 The `compaction` block is not the first block of the conversation, or is in a `system` message.
4166 
4167- `compaction_content_mismatch` (HTTP status 400)
4168 
4169 The `compaction` block's `content` differs from the text its `signature` recorded.
4170 
4171- `compaction_nothing_to_summarize` (HTTP status 400)
4172 
4173 `messages` holds no `user` or `assistant` content to summarize or adopt.
4174 
4175- `compaction_signature_invalid` (HTTP status 400)
4176 
4177 The `compaction` block's `signature` does not verify.
4178 
4179- `compaction_tool_changes_mismatch` (HTTP status 400)
4180 
4181 The `compaction` block's `tool_changes` differs from what was returned with the block.
4182 
4183- `organization_on_hold` (HTTP status 400)
4184 
4185 Anthropic has disabled the organization for trust and safety reasons. An organization disabled for any other reason, such as billing, does not get this code. `appeal_url`, when present, is where the organization can appeal.
4186 
4187- `request_body_encoding_invalid` (HTTP status 400)
4188 
4189 The request body is not valid for its `Content-Encoding`.
4190 
4191- `request_body_encoding_unsupported` (HTTP status 400)
4192 
4193 The request's `Content-Encoding` is not supported.
4194 
4195- `tool_name_conflict` (HTTP status 400)
4196 
4197 A tool made available in `messages` takes a name that an available tool of another kind, or of another MCP server, already holds.
4198 
4199- `tool_reference_unresolved` (HTTP status 400)
4200 
4201 A tool change or MCP tool listing references a tool or MCP server that is not defined at that position in the conversation.
4202 
4203- `request_body_too_large_after_decoding` (HTTP status 413)
4204 
4205 The compressed request body exceeds the request size limit once decoded.
4206 
4207- `enforced_spend_limit_reached` (HTTP status 429)
4208 
4209 The organization has crossed the monthly API usage threshold of its API tier.
4210 
4211- `compaction_unavailable` (HTTP status 529)
4212 
4213 The compaction could not be completed for a transient server reason. Retry the request.
4214 
41454215## Example
41464216 
41474217```bash
Feedback