Count tokens
curl --request POST \
--url https://api.altrum.ai/anthropic/v1/messages/count_tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "anthropic/claude-sonnet-4-5",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
'import requests
url = "https://api.altrum.ai/anthropic/v1/messages/count_tokens"
payload = {
"model": "anthropic/claude-sonnet-4-5",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'anthropic/claude-sonnet-4-5',
messages: [{role: 'user', content: 'Say hello.'}]
})
};
fetch('https://api.altrum.ai/anthropic/v1/messages/count_tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"input_tokens": 10
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}Anthropic format
Count tokens
Counts the tokens a Messages request would use, without sending it to the model.
POST
/
anthropic
/
v1
/
messages
/
count_tokens
Count tokens
curl --request POST \
--url https://api.altrum.ai/anthropic/v1/messages/count_tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "anthropic/claude-sonnet-4-5",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
'import requests
url = "https://api.altrum.ai/anthropic/v1/messages/count_tokens"
payload = {
"model": "anthropic/claude-sonnet-4-5",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'anthropic/claude-sonnet-4-5',
messages: [{role: 'user', content: 'Say hello.'}]
})
};
fetch('https://api.altrum.ai/anthropic/v1/messages/count_tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"input_tokens": 10
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}{
"type": "error",
"error": {
"type": "model_blocked",
"message": "Model 'claude-opus-4' is not allowed"
},
"request_id": "4f9c..."
}Authorizations
bearerapiKeygoogleApiKeyaltrumKey
Your virtual key, sk-alt-.... What every OpenAI and Anthropic SDK sends.
Headers
Your own reference for the request. Altrum uses it instead of making one, and returns it.
Body
application/json
Response
The count.