Count tokens in a Message changedapi/beta/messages/count_tokens
Nearest release: v2.1.296, published 4 hours 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+9added
Lines−13removed
From line
147
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits19to this page, all time
The whole hunk
from line 147, old and new numbered
/
from line 147
147147
148148 Each input message must be an object with a `role` and `content`. You can specify a single `user`-role message, or you can include multiple `user` and `assistant` messages.
149149
150 If the final message uses the `assistant` role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response.
150 If the final message uses the `assistant` role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response. This is called prefill. On models that don't support prefill, creating a message that ends with a partial `assistant` response returns a 400 error. See [Prefill not supported](https://platform.claude.com/docs/en/api/errors#prefill-not-supported).
151151
152152 Example with a single `user` message:
153153
from line 165
165165 ]
166166 ```
167167
168 Example with a partially-filled response from Claude:
168 Example with a partially-filled response from Claude, for models that support prefill:
169169
170170 ```json
171171 [
from line 3152
31523152
31533153 - `"claude-haiku-4-5"`
31543154
3155 Fastest model with near-frontier intelligence
3156
31573155 - `"claude-haiku-4-5-20251001"`
31583156
3159 Fastest model with near-frontier intelligence
3160
31613157 - `"claude-opus-4-5"`
31623158
31633159 Powerful intelligence for long-running agents and coding
from line 3749
37533749
37543750- `thinking: optional BetaThinkingConfigParam`
37553751
3756 Configuration for enabling Claude's extended thinking.
3752 Configuration for Claude's thinking.
37573753
3758 When enabled, responses include `thinking` content blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your `max_tokens` limit.
3754 With `{"type": "adaptive"}`, Claude decides when and how much to think. With `{"type": "enabled"}` (manual extended thinking), you set a `budget_tokens` of at least 1,024. Thinking tokens count toward your `max_tokens` limit.
37593755
3760 See [extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking) for details.
3756 Which `type` values are accepted, and what happens when you omit `thinking`, depend on the model. See [thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#configuring-thinking) for each model's behavior.
37613757
37623758 - `BetaThinkingConfigEnabled object`
37633759
from line 3783
37873783
37883784 - `display: optional "summarized" or "omitted" or "updates" or null`
37893785
3790 Controls how thinking content appears in the response. When set to `summarized`, thinking is returned normally. When set to `omitted`, thinking content is redacted but a signature is returned for multi-turn continuity. Defaults to `summarized`.
3786 Controls how thinking content appears in the response. When set to `summarized`, thinking is returned normally. When set to `omitted`, thinking content is redacted but a signature is returned for multi-turn continuity. The default depends on the model; see [Controlling thinking display](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display).
37913787
37923788 - `"summarized"`
37933789
from line 3809
38133809
38143810 - `display: optional "summarized" or "omitted" or "updates" or null`
38153811
3816 Controls how thinking content appears in the response. When set to `summarized`, thinking is returned normally. When set to `omitted`, thinking content is redacted but a signature is returned for multi-turn continuity. Defaults to `summarized`.
3812 Controls how thinking content appears in the response. When set to `summarized`, thinking is returned normally. When set to `omitted`, thinking content is redacted but a signature is returned for multi-turn continuity. The default depends on the model; see [Controlling thinking display](https://platform.claude.com/docs/en/build-with-claude/thinking#controlling-thinking-display).
38173813
38183814 - `"summarized"`
38193815
No line in this hunk matches that.