API reference
Count message tokens
Reference for POST /v1/messages/count_tokens, which estimates the input tokens of a message request.
This page is the reference for the token counting endpoint. It is intended for developers who use Anthropic clients that check the prompt size before they send a request.
Endpoint
POST https://api.engy.ai/v1/messages/count_tokensAuthentication
This endpoint does not require authentication.
Parameters
Body parameters
The request body has the same format as Create a message. The endpoint uses system, messages, and tools, and ignores the other parameters.
Response
Response fields
| Field | Type | Description |
|---|---|---|
input_tokens | Integer | The estimated number of input tokens. |
The value is an estimate based on the size of the text, at about 4 bytes per token. It is not a count by the model's tokenizer. The actual count, which Engy uses for billing, is returned in the usage field of each response.
Errors
This endpoint does not return endpoint-specific errors.
Example
curl https://api.engy.ai/v1/messages/count_tokens \
-H "Content-Type: application/json" \
-d '{
"model": "kimi-k3",
"system": "You are a concise assistant.",
"messages": [{"role": "user", "content": "What is the capital of France?"}]
}'Response:
{
"input_tokens": 14
}