Count tokens in a Message changedapi/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
3,001
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits25to this page, all time
## Errors
The whole hunk
from line 3001, old and new numbered
/
from line 3001
30013001
30023002 The total number of tokens across the provided list of messages, system prompt, and tools.
30033003
3004## Errors
3005
3006Any method can also return the general [HTTP errors](https://platform.claude.com/docs/en/api/errors?sdk_languages=http).
3007
3008Each code below is the value of `error.details.error_code` in the response body.
3009
3010- `available_tools_limit_exceeded` (HTTP status 400)
3011
3012 The tools available after a message exceed a limit on their number or their size.
3013
3014- `claude_code_key_creator_not_member` (HTTP status 400)
3015
3016 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.
3017
3018- `compaction_block_ambiguous` (HTTP status 400)
3019
3020 `messages` holds more than one `compaction` block with content. Send only the block the conversation returned last.
3021
3022- `compaction_block_misplaced` (HTTP status 400)
3023
3024 The `compaction` block is not the first block of the conversation, or is in a `system` message.
3025
3026- `compaction_content_mismatch` (HTTP status 400)
3027
3028 The `compaction` block's `content` differs from the text its `signature` recorded.
3029
3030- `compaction_nothing_to_summarize` (HTTP status 400)
3031
3032 `messages` holds no `user` or `assistant` content to summarize or adopt.
3033
3034- `compaction_signature_invalid` (HTTP status 400)
3035
3036 The `compaction` block's `signature` does not verify.
3037
3038- `compaction_tool_changes_mismatch` (HTTP status 400)
3039
3040 The `compaction` block's `tool_changes` differs from what was returned with the block.
3041
3042- `organization_on_hold` (HTTP status 400)
3043
3044 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.
3045
3046- `request_body_encoding_invalid` (HTTP status 400)
3047
3048 The request body is not valid for its `Content-Encoding`.
3049
3050- `request_body_encoding_unsupported` (HTTP status 400)
3051
3052 The request's `Content-Encoding` is not supported.
3053
3054- `tool_name_conflict` (HTTP status 400)
3055
3056 A tool made available in `messages` takes a name that an available tool of another kind, or of another MCP server, already holds.
3057
3058- `tool_reference_unresolved` (HTTP status 400)
3059
3060 A tool change or MCP tool listing references a tool or MCP server that is not defined at that position in the conversation.
3061
3062- `request_body_too_large_after_decoding` (HTTP status 413)
3063
3064 The compressed request body exceeds the request size limit once decoded.
3065
3066- `enforced_spend_limit_reached` (HTTP status 429)
3067
3068 The organization has crossed the monthly API usage threshold of its API tier.
3069
3070- `compaction_unavailable` (HTTP status 529)
3071
3072 The compaction could not be completed for a transient server reason. Retry the request.
3073
30043074## Example
30053075
30063076```bash
No line in this hunk matches that.