Token Counter
text.count_tokens
Overview
You pass text (or a file_ref) and pick an encoding — cl100k_base or o200k_base; we run the real tokenizer over it and return the exact token count, the encoding and library version we used, and, on request, the token ids themselves (the first 10,000 of them). A token count means nothing without naming the tokenizer, so we always name it.
LLMs cannot count their own tokens reliably. We use the exact tokenizer encodings so you know how much context a string will consume.
Reliability
VERIFIABLE and deterministic for a given tokenizer library version on this runtime — identical text and tokenizer always yield the same count. Counts may shift after a JTokkit upgrade (tokenizer_version is returned). Input validation (not retryable): unsupported tokenizer; missing text and file_ref.
Context footprint
Accepts inline text up to 1M chars or file_ref (up to 2 MB). Upload files via POST /v1/files/upload before passing file_ref. Replaces unreliable LLM self-estimation of token counts. A successful call costs 1 execution credit.
When to use it
Whenever you need to know how many tokens your text will use in an OpenAI model context window before sending it.
Do not use for non-OpenAI tokenizers or when you only need approximate word counts — use text.count_words instead.
Powered by JTokkit, an open-source tokenizer that reproduces OpenAI's tiktoken byte-pair encodings for exact context-window accounting.
Scope
Non-goals
- Does not tokenize for non-OpenAI models (Anthropic, Mistral, etc.)
- Does not estimate API costs — token pricing changes frequently
- Does not count words or characters (use text.count_words or text.count_characters)
Properties
Capabilities
Cost & billing
Flat rate per invocation
File handling
File limits
Constraints this skill applies to your input and generated files. The “Limited by” column shows the static source of each cap; none of these can be raised by upgrading your plan.
| Limit | Value | Limited by |
|---|---|---|
| Maximum size per input file | 1.9 MiB | Skill maximum |
How we handle your data
What this means
This skill may receive sensitive content, but it does not target sensitive data and returns only a structured non-sensitive result.
Squillify guarantees
- Runs inside Squillify
- This skill runs inside Squillify.
- Payloads are not sent to an external service by this skill.
- Squillify does not permanently store submitted payloads.
- Telemetry records metadata only, not submitted content.
- Submitted payloads are not used for training.
- Submitted payloads are not reviewed by humans.
- This skill does not target sensitive data.
- The response does not contain submitted content.
Your responsibility
Squillify does not determine whether submitted content is sensitive. Your application is responsible for deciding what data it is allowed to submit. Your application is responsible for securing the response.
Input schema
| Field | Type | Required | Description |
|---|---|---|---|
| text | string | No | Bounded inline text source. Required unless file_ref is provided. |
| file_ref | string | No | Tenant-scoped opaque text-file reference. Omit it to use the required inline text; never send both. |
| tokenizer | string | No | Tokenizer encoding; omit it for cl100k_base. |
| return_tokens | boolean | No | Whether token ids are returned; omit it for false. |
Output schema
| Field | Type | Required | Description |
|---|---|---|---|
| skill | string | Yes | Producing stable skill key. |
| count | integer | Yes | Counted tokenizer tokens. |
| unit | string | Yes | Measurement unit for the returned tokenizer-token total. |
| policy | string | Yes | Applied token-count policy. |
| tokenizer | string | Yes | Applied tokenizer encoding. |
| tokenizer_version | string | Yes | Pinned tokenizer-library version. |
| tokens | array | No | Bounded optional array of tokenizer integer ids in source order. The item shape is defined by the nested schema and the array contains from 0 through 2000000 items. |
| warnings | array | Yes | Bounded warning array containing from 0 through 10000 items, where each item is one non-fatal advisory string. |
API contract
POST /v1/executecurl -sS -X POST "$BASE/v1/execute" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"skillKey":"text.count_tokens","input":{"text":"You are a helpful assistant.","tokenizer":"cl100k_base"}}'import { Squillify } from "@squillify/sdk";
const sq = new Squillify({ apiKey: process.env.SQUILLIFY_API_KEY });
const { output } = await sq.execute("text.count_tokens", {"tokenizer":"cl100k_base","text":"You are a helpful assistant that summarizes technical documents into concise bullet points."});Errors
| Code | HTTP | Retryable | Description |
|---|---|---|---|
| VALIDATION_ERROR | 400 | No | The request payload failed schema validation. |
| UNAUTHORIZED | 401 | No | Missing or invalid API key. |
| SKILL_NOT_ACCESSIBLE | 403 | No | The API key is not granted access to this skill. |
| SKILL_NOT_AVAILABLE_FOR_PLAN | 403 | No | This skill is not included in your current plan. |
| PLAN_ELIGIBILITY_UNAVAILABLE | 503 | Yes | Plan eligibility could not be decided. Retry after backoff. |
| SKILL_NOT_FOUND | 404 | No | The requested skill or version does not exist. |
| TENANT_RATE_LIMITED | 429 | Yes | Request rate limit exceeded. Retry after backoff. |
| QUOTA_EXCEEDED | 429 | Yes | Plan quota exhausted. Retryable once the quota period resets. |
| EXECUTION_TIMEOUT | 504 | Yes | Execution exceeded the allowed time budget. |
Other limits
| Limit | Value |
|---|---|
| Recommended inline bytes | 32 KiB |
Limitations
- Does not tokenize for non-OpenAI models (Anthropic, Mistral, etc.)
- Does not estimate API costs — token pricing changes frequently
- Does not count words or characters (use text.count_words or text.count_characters)
- Word or character counting (use text.count_words or text.count_characters)
- Cost estimation that depends on frequently changing model pricing
- Token counting for non-OpenAI model families
How to call
POST /v1/execute (requires authentication)
{
"skillKey": "text.count_tokens",
"input": {
"tokenizer": "cl100k_base",
"text": "You are a helpful assistant that summarizes technical documents into concise bullet points."
}
}Examples
Count tokens in a system prompt
{
"tokenizer": "cl100k_base",
"text": "You are a helpful assistant that summarizes technical documents into concise bullet points."
}{
"tokenizer_version": "jtokkit-1.1.0",
"policy": "tokenizer_encoding",
"count": 14,
"skill": "text.count_tokens",
"unit": "token",
"tokenizer": "cl100k_base",
"warnings": []
}GPT-4o tokenizer encoding
{
"tokenizer": "o200k_base",
"text": "The quick brown fox jumps over the lazy dog."
}{
"tokenizer_version": "jtokkit-1.1.0",
"policy": "tokenizer_encoding",
"count": 10,
"skill": "text.count_tokens",
"unit": "token",
"tokenizer": "o200k_base",
"warnings": []
}Recommended use cases
- Pre-flight context-window budget checks before sending a prompt
- Validate prompt length against model limits
- Compare token counts across tokenizer encodings
Avoid for
- Word or character counting (use text.count_words or text.count_characters)
- Cost estimation that depends on frequently changing model pricing
- Token counting for non-OpenAI model families
Related skills
Composable with
Safety & privacy
- Runs without calling any external service.
- Your payloads are never stored permanently.
- Telemetry captures metadata only — never your payload contents.
- We never train models on your payloads.
- No human reviews your payloads.