Estimate input tokens
Part of Gateway, 7 operations. The overview covers keys, scopes and errors.
POST /v1/messages/count_tokens
A local estimate (characters / 4). No upstream call and no charge.
Any live caller key (Authorization: Bearer sbc_… or x-api-key: sbc_…).
Request body
An Anthropic Messages body; only messages is read.
modelstring required
Body reference: Anthropic count tokens reference.
Response 200
The estimate.
input_tokensinteger required
Errors
| Status | Code | What to change |
|---|---|---|
| 400 | invalid_request | A parameter or body field is invalid; |
| 401 | unauthorized | Send a live caller key or session as |
| 403 | insufficient_scope | The key lacks the scope in |
curl
curl -sS -X POST "https://superbot.gg/v1/messages/count_tokens" \
-H "Authorization: Bearer $SUPERBOT_API_KEY" \
-H "content-type: application/json" \
-d '{"model":"superbot"}'JavaScript
const res = await fetch(`https://superbot.gg/v1/messages/count_tokens`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SUPERBOT_API_KEY}`,
'content-type': 'application/json',
},
body: JSON.stringify({"model":"superbot"}),
});
console.log(res.status, await res.json());Python
import os
import requests
res = requests.request(
"POST",
"https://superbot.gg/v1/messages/count_tokens",
headers={
"Authorization": f"Bearer {os.environ['SUPERBOT_API_KEY']}",
"content-type": "application/json",
},
json={"model":"superbot"},
)
print(res.status_code, res.json())200 The estimate.
{
"input_tokens": 0
}400 The body is not JSON.
"string"401 Missing, malformed or unknown key. A 401 that carries `x-superbot-error-origin: vendor` is your vendor credential’s refusal, not the gateway’s.
"string"403 The key is revoked.
"string"No operation matches this filter.