API reference

Count tokens

Count a request

POST https://antarya.ai/v1/count-tokens

Send the body you would send to /v1/chat. Antarya returns the number of input tokens and does not write a reply. Counting is free and is not billed. It is limited to 100 a minute per key, apart from the chat limits. The guide explains what the count covers.

Headers

Header Value
Authorization Bearer $ANTARYA_API_KEY
Content-Type application/json
curl https://antarya.ai/v1/count-tokens \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Draft a reply that declines the meeting."}
    ]
  }'
Output
{"input_tokens": 12}

Request body

NameTypeRequiredDescription
messagesarrayYesRequiredThe conversation to count, as in a chat request.
modeltextNoThe id or alias of the model. Models can count tokens differently.
systemtextNoCounted with the messages.
toolsarrayNoCounted with the messages.
response_formatobjectNoCounted with the messages.

Response

NameTypeRequiredDescription
input_tokensnumberYesRequiredThe tokens the request would use as input.

Next steps