Tools / tokens.count
Token counter
tokens.count
Exact token count for the OpenAI o200k_base and cl100k_base encodings, computed offline.
DataLaunch set1 unit per callnot cachedMCP: tokens_countv1.0.0
When to use it
Use to estimate prompt size or cost for OpenAI models. Counts are exact for the named encoding. Anthropic and Google tokenizers differ and are not supported yet.
Input
| Field | Type | Description |
|---|---|---|
text * | string (1+ chars, ≤ 200000 chars) | Text to tokenize, up to 200,000 characters. |
encoding | one of o200k_base, cl100k_base | o200k_base for GPT-4o and later. cl100k_base for GPT-4 and GPT-3.5. Default: "o200k_base". |
* required
Output
Returns data with: tokens, characters, encoding, exact (true for supported encodings).
Request
curl -X POST https://agentops.tools/v1/tokens.count \
-H 'content-type: application/json' \
-d '{"text":"Hello, world!"}'Over MCP the tool is named tokens_count. Over A2A its skill id is tokens.count. Same input, same envelope.
Try it
Counts against your rate limit.
Sources
Tokenization by js-tiktoken (MIT), using OpenAI encodings