POST /v1/messages/count_tokens
Image input is enabled on deepseek-v4.1-flash-1017, deepseek-v4.1-flash-0910, glm-5.3-flash and qwen3.8-27b. User and tool messages accept base64 data URLs with PNG, JPEG or WebP headers. Model API requests allow 12,000,000 bytes (12 MB). Images bill as ordinary input tokens at existing rates, with no surcharge. Other models (including every -rr model and glm-5.3), remote URLs and invalid/unsupported images receive [Image omitted: this text-only model cannot inspect it. Ask for a text description.] in place. Images are never fetched from URLs. Conservative input-token estimate, capped at the model context limit; not tokenizer-exact or a guarantee that generation will fit. No inference call or credit reservation.
Authentication
Send Authorization: Bearer $REDROUTER_API_KEY or x-api-key: $REDROUTER_API_KEY.
Request body
application/json · required
{
"$ref": "#/components/schemas/MessagesCountRequest"
}
Request examples
curl -X POST 'https://redrouter.org/v1/messages/count_tokens' \
-H "Authorization: Bearer $REDROUTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"messages": [
{
"content": "Hello",
"role": "user"
}
],
"model": "red-cyber-1"
}'
import os, json
from urllib.request import Request, urlopen
body = json.loads(r'''{
"messages": [
{
"content": "Hello",
"role": "user"
}
],
"model": "red-cyber-1"
}''')
request = Request(
"https://redrouter.org/v1/messages/count_tokens",
method="POST",
data=json.dumps(body).encode(),
headers={
"Authorization": "Bearer " + os.environ["REDROUTER_API_KEY"],
"Content-Type": "application/json",
},
)
with urlopen(request) as response:
print(json.load(response))
const key = process.env.REDROUTER_API_KEY;
const response = await fetch("https://redrouter.org/v1/messages/count_tokens", {
method: "POST",
headers: {
Authorization: `Bearer ${key}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"messages": [
{
"content": "Hello",
"role": "user"
}
],
"model": "red-cyber-1"
}),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
Responses
200 · Estimated input tokens
application/json
{
"additionalProperties": false,
"properties": {
"input_tokens": {
"minimum": 0,
"type": "integer"
}
},
"required": [
"input_tokens"
],
"type": "object"
}
400 · Request refused
application/json
{
"$ref": "#/components/schemas/MessagesError"
}
401 · Request refused
application/json
{
"$ref": "#/components/schemas/MessagesError"
}
403 · Request refused
application/json
{
"$ref": "#/components/schemas/MessagesError"
}
404 · Request refused
application/json
{
"$ref": "#/components/schemas/MessagesError"
}
413 · Request refused
application/json
{
"$ref": "#/components/schemas/MessagesError"
}
429 · Request refused
application/json
{
"$ref": "#/components/schemas/MessagesError"
}