skip to content
superbot.gg

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_…).

Operation id countMessageTokens in Gateway.

Request body

application/json, required.

An Anthropic Messages body; only messages is read.

  • model string required

Body reference: Anthropic count tokens reference.

Response 200

The estimate.

application/json: TokenCount.

  • input_tokens integer required

Errors

StatusCodeWhat to change
400invalid_request

A parameter or body field is invalid; param names it and issues lists every problem.

401unauthorized

Send a live caller key or session as Authorization: Bearer … or x-api-key. No key yet: create one at /account/api, or sign a user in at /auth.md.

403insufficient_scope

The key lacks the scope in required_scopes; mint a key that holds it.

view .mdopenapi
Request

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())
Response

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"