Guides
Counting tokens
What it is for
Tokens are what you are billed for and how much a conversation can hold is measured in. To see how large a request is before you send it, post the same body to /v1/count-tokens. It returns input_tokens and does not produce a reply. Counting is free and not billed, and is limited to 100 a minute per key. The SDK methods are client.chat.countTokens in TypeScript and client.chat.count_tokens in Python.
Count a request
curl https://antarya.ai/v1/count-tokens \
-H "Authorization: Bearer $ANTARYA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"system": "Answer in plain English.",
"messages": [
{"role": "user", "content": "Summarise this contract'"'"'s termination clause."}
]
}'Output
{"input_tokens": 23}What it counts
The count covers everything the request sends: system, every message, tool descriptions, a response schema, and files and images in the messages. It does not count the reply, which is only known afterwards in usage.output_tokens.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
messages | array | YesRequired | The conversation to count, as in a chat request. |
system | text | No | Counted with the messages. |
tools | array | No | Counted with the messages. |
response_format | object | No | Counted with the messages. |
Limits
| Limit | Value |
|---|---|
| Counting requests per minute | 100 a minute per key |
| Cost of a count | Free, not billed |