Count a Messages request's input tokens (cached 10 min by body; not billed; counts toward RPM only)
curl --request POST \
--url https://api.antarah.dev/v1/messages/count_tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "a1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"system": "<string>",
"tools": [
{
"name": "<string>",
"type": "<string>",
"description": "<string>",
"input_schema": {}
}
],
"tool_choice": {
"type": "auto",
"disable_parallel_tool_use": true
},
"thinking": false
}
'import requests
url = "https://api.antarah.dev/v1/messages/count_tokens"
payload = {
"model": "a1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"system": "<string>",
"tools": [
{
"name": "<string>",
"type": "<string>",
"description": "<string>",
"input_schema": {}
}
],
"tool_choice": {
"type": "auto",
"disable_parallel_tool_use": True
},
"thinking": False
}
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: 'a1',
messages: [{role: 'user', content: '<string>'}],
system: '<string>',
tools: [
{name: '<string>', type: '<string>', description: '<string>', input_schema: {}}
],
tool_choice: {type: 'auto', disable_parallel_tool_use: true},
thinking: false
})
};
fetch('https://api.antarah.dev/v1/messages/count_tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.antarah.dev/v1/messages/count_tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'a1',
'messages' => [
[
'role' => 'user',
'content' => '<string>'
]
],
'system' => '<string>',
'tools' => [
[
'name' => '<string>',
'type' => '<string>',
'description' => '<string>',
'input_schema' => [
]
]
],
'tool_choice' => [
'type' => 'auto',
'disable_parallel_tool_use' => true
],
'thinking' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.antarah.dev/v1/messages/count_tokens"
payload := strings.NewReader("{\n \"model\": \"a1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {}\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\",\n \"disable_parallel_tool_use\": true\n },\n \"thinking\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.antarah.dev/v1/messages/count_tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"a1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {}\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\",\n \"disable_parallel_tool_use\": true\n },\n \"thinking\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.antarah.dev/v1/messages/count_tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"a1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {}\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\",\n \"disable_parallel_tool_use\": true\n },\n \"thinking\": false\n}"
response = http.request(request)
puts response.read_body{
"input_tokens": 123
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}Count tokens
POST
/
v1
/
messages
/
count_tokens
Count a Messages request's input tokens (cached 10 min by body; not billed; counts toward RPM only)
curl --request POST \
--url https://api.antarah.dev/v1/messages/count_tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "a1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"system": "<string>",
"tools": [
{
"name": "<string>",
"type": "<string>",
"description": "<string>",
"input_schema": {}
}
],
"tool_choice": {
"type": "auto",
"disable_parallel_tool_use": true
},
"thinking": false
}
'import requests
url = "https://api.antarah.dev/v1/messages/count_tokens"
payload = {
"model": "a1",
"messages": [
{
"role": "user",
"content": "<string>"
}
],
"system": "<string>",
"tools": [
{
"name": "<string>",
"type": "<string>",
"description": "<string>",
"input_schema": {}
}
],
"tool_choice": {
"type": "auto",
"disable_parallel_tool_use": True
},
"thinking": False
}
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: 'a1',
messages: [{role: 'user', content: '<string>'}],
system: '<string>',
tools: [
{name: '<string>', type: '<string>', description: '<string>', input_schema: {}}
],
tool_choice: {type: 'auto', disable_parallel_tool_use: true},
thinking: false
})
};
fetch('https://api.antarah.dev/v1/messages/count_tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.antarah.dev/v1/messages/count_tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'a1',
'messages' => [
[
'role' => 'user',
'content' => '<string>'
]
],
'system' => '<string>',
'tools' => [
[
'name' => '<string>',
'type' => '<string>',
'description' => '<string>',
'input_schema' => [
]
]
],
'tool_choice' => [
'type' => 'auto',
'disable_parallel_tool_use' => true
],
'thinking' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.antarah.dev/v1/messages/count_tokens"
payload := strings.NewReader("{\n \"model\": \"a1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {}\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\",\n \"disable_parallel_tool_use\": true\n },\n \"thinking\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.antarah.dev/v1/messages/count_tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"a1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {}\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\",\n \"disable_parallel_tool_use\": true\n },\n \"thinking\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.antarah.dev/v1/messages/count_tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"a1\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"<string>\"\n }\n ],\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {}\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\",\n \"disable_parallel_tool_use\": true\n },\n \"thinking\": false\n}"
response = http.request(request)
puts response.read_body{
"input_tokens": 123
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>"
},
"request_id": "<string>"
}Authorizations
projectKeysession
ak_… project API key (or x-api-key)
Body
application/json
Public model ID, e.g. a1 (A-05)
Minimum string length:
1Example:
"a1"
Required array length:
1 - 10000 elements- Option 1
- Option 2
Show child attributes
Show child attributes
Maximum array length:
128Show child attributes
Show child attributes
- Option 1
- Option 2
- Option 3
- Option 4
Show child attributes
Show child attributes
Available options:
false Response
OK
