token-counting changedbuild-with-claude/token-counting
Nearest release: v2.1.310, published 11 hours after 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+12added
Lines−6removed
From line
27
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits21to this page, all time
The whole hunk
from line 27, old and new numbered
/
from line 27
2727
2828The [token counting](https://platform.claude.com/docs/en/api/messages/count_tokens) endpoint accepts the same structured list of inputs for creating a message, including support for system prompts, [tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview), [images](https://platform.claude.com/docs/en/build-with-claude/vision), and [PDFs](https://platform.claude.com/docs/en/build-with-claude/pdf-support). The response contains the total number of input tokens.
2929
30This endpoint returns an `invalid_request_error` for a few inputs that the Messages API accepts: [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) such as web search, web fetch, code execution, and tool search (every server tool except the [advisor tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/advisor-tool)), the [MCP connector](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector), and `image` or `document` blocks with a `url` or `file` source. Send images and PDFs as base64 to count them. For requests that use server tools or MCP servers, the Messages API response reports the tokens used in its `usage` object.
30This endpoint returns an `invalid_request_error` for a few inputs that the Messages API accepts:
3131
32* [Server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) such as web search, web fetch, code execution, and tool search (every server tool except the [advisor tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/advisor-tool))
33* The [MCP connector](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector)
34* `image` or `document` blocks with a `url` or `file` source
35
36Send images and PDFs as base64 to count them. For requests that use server tools or MCP servers, the Messages API response reports the tokens used in its `usage` object.
37
3238<Note>
3339 The token count is an **estimate**. In some cases, the actual number of input tokens used when creating a message might differ by a small amount.
3440
from line 192
186192 ```
187193</CodeGroup>
188194
189```text Output wrap
195```json Output
190196{ "input_tokens": 14 }
191197```
192198
from line 475
469475 ```
470476</CodeGroup>
471477
472```text Output wrap
478```json Output
473479{ "input_tokens": 403 }
474480```
475481
from line 784
778784 ```
779785</CodeGroup>
780786
781```text Output wrap
787```json Output
782788{ "input_tokens": 1028 }
783789```
784790
from line 1109
11031109 ```
11041110</CodeGroup>
11051111
1106```text Output wrap
1112```json Output
11071113{ "input_tokens": 88 }
11081114```
11091115
from line 1395
13891395 ```
13901396</CodeGroup>
13911397
1392```text Output wrap
1398```json Output
13931399{ "input_tokens": 2188 }
13941400```
13951401
No line in this hunk matches that.