Token counting API lets you measure a request before sending it
A new endpoint returns the token count for a Messages request — system prompt, messages, tools, and images included — so you can check size and estimate cost before spending an inference call.
What does this mean for me?
Engineering leadership
Cost, risk, timeline, team impact Worth knowingFree endpoint that lets teams estimate input cost and context fit before spending an inference call. Useful for cost-guarding high-volume pipelines; no budget action.
Engineer
What to change, what breaks, what to test Worth knowingPOST your Messages payload to the token counting endpoint to get the exact input token count including system prompt, tools, images and documents. It's free and left beta on 17 December 2024 — use it to reject oversized requests instead of approximating with a local tokenizer.
General consumer
Using the Claude apps, not the API No impactNothing to do — this is an API-only change and does not affect the Claude apps.
Token counting launched on November 1, 2024: post the same payload you would send to Messages and get back the input token count, including system prompt, tools, and image or document content.
Before this, sizing a prompt against a model’s context window meant approximating with a local tokenizer that did not account for tool schemas or images. The endpoint is free to call and left beta on December 17, 2024.
API surface
| Parameter | Change | Breaking | Models |
|---|---|---|---|
/v1/messages/count_tokens | added | no |
Topics: Images, audio and video
Terms on this page: Context window