Content is loading…
Count tokens against OpenAI tokenizers (cl100k, o200k, p50k, r50k).
count_gpt_tokens#tokens#tokenizer#tiktoken#gpt#context windowCalculates the token count for a string using OpenAI tokenizers. Accepts a text string and an optional encoding parameter (e.g., cl100k_base or o200k_base). Returns an integer representing the total token count to help manage context limits and API costs.
| Name | Type | Required | Description |
|---|---|---|---|
text | string | required | The text to tokenize and count |
encoding | enum ("cl100k_base" | "o200k_base" | "p50k_base" | "r50k_base") | optional | Tokenizer encoding. Default cl100k_base. o200k_base is for GPT-4o. |
{
"text": "Hello, world!",
"encoding": "o200k_base"
}curl -X POST https://toolsy.my/api/mcp \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "count_gpt_tokens",
"arguments": {
"text": "Hello, world!",
"encoding": "o200k_base"
}
}
}'Generate a free API key or set up an OAuth connector for Claude.ai.