API Reference
Count Anthropic Messages input tokens
POST
/
v1
/
messages
/
count_tokens
Count Anthropic Messages input tokens
curl --request POST \
--url https://api.example.com/v1/messages/count_tokens \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>"
}
],
"system": "<string>",
"tools": [
{}
],
"tool_choice": {
"name": "<string>",
"disable_parallel_tool_use": true
},
"thinking": {
"budget_tokens": 499995
},
"output_config": {
"format": {
"type": "<string>",
"schema": {}
}
},
"context_management": {
"edits": [
{
"type": "<string>",
"keep": "<string>"
}
]
}
}
'import requests
url = "https://api.example.com/v1/messages/count_tokens"
payload = {
"model": "<string>",
"messages": [{ "content": "<string>" }],
"system": "<string>",
"tools": [{}],
"tool_choice": {
"name": "<string>",
"disable_parallel_tool_use": True
},
"thinking": { "budget_tokens": 499995 },
"output_config": { "format": {
"type": "<string>",
"schema": {}
} },
"context_management": { "edits": [
{
"type": "<string>",
"keep": "<string>"
}
] }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [{content: '<string>'}],
system: '<string>',
tools: [{}],
tool_choice: {name: '<string>', disable_parallel_tool_use: true},
thinking: {budget_tokens: 499995},
output_config: {format: {type: '<string>', schema: {}}},
context_management: {edits: [{type: '<string>', keep: '<string>'}]}
})
};
fetch('https://api.example.com/v1/messages/count_tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"input_tokens": 1
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}Headers
Bearer API key.
API key alternative for Anthropic-compatible clients. Authorization takes precedence when both headers are present.
Body
application/json
Anthropic Messages count-tokens-compatible request.
Minimum string length:
1Minimum array length:
1Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Supported beta context-management subset.
keep=all does not remove any replayed thinking blocks, so it can be
safely consumed at the compatibility boundary and omitted from the vLLM
provider payload.
Show child attributes
Show child attributes
Response
Successful Response
Required range:
x >= 0Last modified on August 11, 2026
⌘I
Count Anthropic Messages input tokens
curl --request POST \
--url https://api.example.com/v1/messages/count_tokens \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>"
}
],
"system": "<string>",
"tools": [
{}
],
"tool_choice": {
"name": "<string>",
"disable_parallel_tool_use": true
},
"thinking": {
"budget_tokens": 499995
},
"output_config": {
"format": {
"type": "<string>",
"schema": {}
}
},
"context_management": {
"edits": [
{
"type": "<string>",
"keep": "<string>"
}
]
}
}
'import requests
url = "https://api.example.com/v1/messages/count_tokens"
payload = {
"model": "<string>",
"messages": [{ "content": "<string>" }],
"system": "<string>",
"tools": [{}],
"tool_choice": {
"name": "<string>",
"disable_parallel_tool_use": True
},
"thinking": { "budget_tokens": 499995 },
"output_config": { "format": {
"type": "<string>",
"schema": {}
} },
"context_management": { "edits": [
{
"type": "<string>",
"keep": "<string>"
}
] }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [{content: '<string>'}],
system: '<string>',
tools: [{}],
tool_choice: {name: '<string>', disable_parallel_tool_use: true},
thinking: {budget_tokens: 499995},
output_config: {format: {type: '<string>', schema: {}}},
context_management: {edits: [{type: '<string>', keep: '<string>'}]}
})
};
fetch('https://api.example.com/v1/messages/count_tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"input_tokens": 1
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "<string>",
"param": "<string>",
"doc_url": "<string>"
}
}