Count tokens in a Message
Count the number of tokens in a Message.
The Token Count API can be used to count the number of tokens in a Message, including tools, images, and documents, without creating it.
Learn more about token counting in our user guide
Headers
The version of the Claude API you want to use.
Read more about versioning and our version history here.
The version of the Claude API you want to use.
Read more about versioning and our version history here.
The user profile ID to attribute this request to. Use when acting on behalf of a party other than your organization. Requires the user-profiles beta header.
The user profile ID to attribute this request to. Use when acting on behalf of a party other than your organization. Requires the user-profiles beta header.
Request body
Example request
{
"messages": [
{
"content": "Hello, world",
"role": "user"
}
],
"model": "claude-opus-5"
}Response
Successful Response
Example response
{
"input_tokens": 2095
}Changes
Changed in 22 of the 68 revisions of this API.123142
- ●
removed the request property
///request-property-removed
- ●
removed the request property
///request-property-removed
- ○
added
subschema #2subschema #3to therequest propertyanyOflistrequest-property-any-of-added
This revision also has 1 change that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ●
- ○
added the new optional request property
///////////////new-optional-request-property
- ○
added the new optional request property
//////new-optional-request-property
- ○
added the new optional request property
////////////new-optional-request-property
- ○
added the new optional request property
//////new-optional-request-property
- ○
added the new optional request property
//////////new-optional-request-property
- ○
added the new optional request property
////////////////new-optional-request-property
- ○
added the new optional request property
//////new-optional-request-property
- ○
added
browser_statediscriminator mapping keys to the////////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the/////////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the///////////////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the//////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the//////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the////////////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the//////////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the//////////request propertyrequest-property-discriminator-mapping-added
- ○
added
filediscriminator mapping keys to the////////////////request propertyrequest-property-discriminator-mapping-added
- ○
added to the
/request propertyoneOflistrequest-property-one-of-added
- ○
added to the
/////////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
//////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
//////////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
///////////////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
//////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
////////////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
//////////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
////////////////request propertyoneOflistrequest-property-one-of-added
- ○
added to the
////////request propertyoneOflistrequest-property-one-of-added
- ○
- ▲
removed from the
////request propertyoneOflistrequest-property-one-of-removed
- ○
removed
mid_conv_systemdiscriminator mapping keys from the////request propertyrequest-property-discriminator-mapping-deleted
This revision also has 2 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ▲
- ○
the
////////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
////////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
////////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
//////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
//////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
//////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
///////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
///////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
///////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
///////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
///////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
///////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
/////////////////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
the
////////request property's maxLength was increased from255to500request-property-max-length-increased
- ○
- ▲
removed
subschema #17subschema #18from therequest propertyanyOflistrequest-property-any-of-removed
- ▲
- ▲
removed
subschema #5subschema #6subschema #8subschema #12subschema #13subschema #16subschema #17from therequest propertyanyOflistrequest-property-any-of-removed
- ○
added
subschema #5subschema #6subschema #7subschema #9subschema #13subschema #14subschema #17subschema #18to therequest propertyanyOflistrequest-property-any-of-added
- ▲
- ○
added
subschema #2to therequest propertyanyOflistrequest-property-any-of-added
- ○
- ○
added to the
/request propertyoneOflistrequest-property-one-of-added
- ○
- ○
added the new optional
headerrequest parameteranthropic-user-profile-idnew-optional-request-parameter
- ○
- ▲
removed
subschema #17subschema #18subschema #19subschema #20subschema #21from therequest propertyanyOflistrequest-property-any-of-removed
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added the new
code_execution_20260521enum value to the request property////request-property-enum-value-added
- ○
added to the
/request propertyoneOflistrequest-property-one-of-added
This revision also has 1 change that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ▲