Skip to main content

Squillify development is paused indefinitely. Read why, and discover what this experiment achieved. Read the story

MicroSkills Reference

Token Counter

text.count_tokens

ProductionEngine wrapper (Class A)Deterministicverifiablefastv1.0.0
File inputNo network

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

Note
Counts LLM tokens in your text using real OpenAI-compatible encodings (cl100k_base for GPT-4, o200k_base for GPT-4o) via JTokkit.

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

IdempotentRetry safeStreaming supportedFile input supportedRequires external service

Capabilities

analysistext-processing

Cost & billing

Flat rate per invocation

MetercallsBillable onsuccessCost per call1 credit

File handling

Accepts file_refProduces file_refMax input976.6 KBMax file size1.9 MB

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.

LimitValueLimited by
Maximum size per input file1.9 MiBSkill maximum

How we handle your data

Sensitive input, safe output
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.

Read the Microskill Data Handling Policy

Input schema

FieldTypeRequiredDescription
textstringNoBounded inline text source. Required unless file_ref is provided.
file_refstringNoTenant-scoped opaque text-file reference. Omit it to use the required inline text; never send both.
tokenizerstringNoTokenizer encoding; omit it for cl100k_base.
return_tokensbooleanNoWhether token ids are returned; omit it for false.

Output schema

FieldTypeRequiredDescription
skillstringYesProducing stable skill key.
countintegerYesCounted tokenizer tokens.
unitstringYesMeasurement unit for the returned tokenizer-token total.
policystringYesApplied token-count policy.
tokenizerstringYesApplied tokenizer encoding.
tokenizer_versionstringYesPinned tokenizer-library version.
tokensarrayNoBounded 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.
warningsarrayYesBounded warning array containing from 0 through 10000 items, where each item is one non-fatal advisory string.

API contract

POST /v1/execute
curl
curl -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"}}'
Integrations
TypeScript SDK
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

CodeHTTPRetryableDescription
VALIDATION_ERROR400NoThe request payload failed schema validation.
UNAUTHORIZED401NoMissing or invalid API key.
SKILL_NOT_ACCESSIBLE403NoThe API key is not granted access to this skill.
SKILL_NOT_AVAILABLE_FOR_PLAN403NoThis skill is not included in your current plan.
PLAN_ELIGIBILITY_UNAVAILABLE503YesPlan eligibility could not be decided. Retry after backoff.
SKILL_NOT_FOUND404NoThe requested skill or version does not exist.
TENANT_RATE_LIMITED429YesRequest rate limit exceeded. Retry after backoff.
QUOTA_EXCEEDED429YesPlan quota exhausted. Retryable once the quota period resets.
EXECUTION_TIMEOUT504YesExecution exceeded the allowed time budget.

Other limits

LimitValue
Recommended inline bytes32 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)

Request bodyjson
{
  "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

Inputjson
{
  "tokenizer": "cl100k_base",
  "text": "You are a helpful assistant that summarizes technical documents into concise bullet points."
}
Expected outputjson
{
  "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

Inputjson
{
  "tokenizer": "o200k_base",
  "text": "The quick brown fox jumps over the lazy dog."
}
Expected outputjson
{
  "tokenizer_version": "jtokkit-1.1.0",
  "policy": "tokenizer_encoding",
  "count": 10,
  "skill": "text.count_tokens",
  "unit": "token",
  "tokenizer": "o200k_base",
  "warnings": []
}
  • 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

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.

Tags

textanalysisstatistics