Skip to main content

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

MicroSkills Reference

Token Truncator

text.truncate_to_tokens

ProductionBounded custom (Class B)Deterministicverifiablefastv1.0.0
File inputNo network

Overview

Truncates text so its token count does not exceed maxTokens, using a specified tokenizer encoding (cl100k_base, o200k_base). The returned text is decoded from a token slice whose boundary is proven by roundtrip (encode of the returned text equals the returned slice), so it is never mid-character and never over budget. direction is KEEP_START (keep the beginning) or KEEP_END (keep the end). Because a boundary token may be dropped to stay on a valid boundary, resultTokenCount can be < maxTokens. Accepts file input via file_ref — no need to extract file content first.

Naive token slicing can split a multi-byte character — we prove the boundary by roundtrip so your truncated text never lands mid-character and never exceeds the budget.

Reliability

VERIFIABLE on this deployment — returned text always re-encodes to the returned token slice and resultTokenCount is always <= requestedMaxTokens. Boundary may drop tokens below the budget to stay valid. Tokenizer version is reported and may shift after a library upgrade. Input validation (not retryable): unsupported tokenizer; maxTokens out of range; missing maxTokens.

Context footprint

Accepts inline text up to 1M chars or file input via file_ref (up to 2 MB). Output is inline only in this version. A successful call costs 1 execution credit.

When to use it

When you must fit text into a model context window for a specific OpenAI tokenizer encoding.

Do not use for semantic summarization, character/word truncation, or non-OpenAI tokenizers.

Powered by JTokkit, an open-source tokenizer reproducing OpenAI's tiktoken byte-pair encodings, with a Squillify roundtrip-proven boundary on top.

Scope

Note
Truncates plain text to a token budget on a roundtrip-proven token/UTF-8 boundary using jtokkit encodings (cl100k_base/o200k_base), keeping either the start or the end.

Non-goals

  • Does not summarize or rewrite text — it only cuts on a token boundary
  • Does not tokenize for non-OpenAI models
  • Does not chunk text (use text.chunk_by_tokens) or count tokens (use text.count_tokens)

Properties

IdempotentRetry safeStreaming supportedFile input supportedRequires external service

Capabilities

data-transformationtext-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.
maxTokensintegerYesMaximum returned tokens, including zero.
tokenizerstringNoTokenizer encoding; omit it for cl100k_base.
directionstringNoRetained end; omit it for KEEP_START.

Output schema

FieldTypeRequiredDescription
skillstringYesProducing stable skill key.
textstringYesReturned text within the requested token budget.
outputStoragestringYesApplied inline output storage mode.
tokenizerstringYesApplied tokenizer encoding.
tokenizer_versionstringYesPinned tokenizer-library version.
directionstringYesApplied retained end.
requestedMaxTokensintegerYesRequested token ceiling.
originalTokenCountintegerYesOriginal input token count.
resultTokenCountintegerYesReturned text token count.
removedTokenCountintegerYesRemoved token count.
truncatedbooleanYesWhether any token was removed.
boundaryAdjustedbooleanYesWhether a character-safe cut stopped below the budget.
boundaryTokensDroppedintegerYesAdditional boundary-safety token reduction.
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.truncate_to_tokens","input":{"text":"Hello world","tokenizer":"o200k_base","maxTokens":4000,"direction":"KEEP_END"}}'
Integrations
TypeScript SDK
import { Squillify } from "@squillify/sdk";

const sq = new Squillify({ apiKey: process.env.SQUILLIFY_API_KEY });

const { output } = await sq.execute("text.truncate_to_tokens", {"text":"The quick brown fox jumps over the lazy dog.","maxTokens":4,"tokenizer":"cl100k_base","direction":"KEEP_START"});

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 summarize or rewrite text — it only cuts on a token boundary
  • Does not tokenize for non-OpenAI models
  • Does not chunk text (use text.chunk_by_tokens) or count tokens (use text.count_tokens)
  • Semantic truncation that needs understanding
  • Truncation by characters or words (use character/word skills)

How to call

POST /v1/execute (requires authentication)

Request bodyjson
{
  "skillKey": "text.truncate_to_tokens",
  "input": {
    "text": "The quick brown fox jumps over the lazy dog.",
    "maxTokens": 4,
    "tokenizer": "cl100k_base",
    "direction": "KEEP_START"
  }
}

Examples

Truncate keeping the start

Inputjson
{
  "text": "The quick brown fox jumps over the lazy dog.",
  "maxTokens": 4,
  "tokenizer": "cl100k_base",
  "direction": "KEEP_START"
}
Expected outputjson
{
  "removedTokenCount": 6,
  "tokenizer": "cl100k_base",
  "boundaryAdjusted": false,
  "boundaryTokensDropped": 0,
  "warnings": [],
  "requestedMaxTokens": 4,
  "originalTokenCount": 10,
  "skill": "text.truncate_to_tokens",
  "tokenizer_version": "jtokkit-1.1.0",
  "text": "The quick brown fox",
  "outputStorage": "INLINE",
  "direction": "KEEP_START",
  "resultTokenCount": 4,
  "truncated": true
}
Tip
Keeps the first 4 tokens; the returned text re-encodes exactly to those tokens

Already within budget (no truncation)

Inputjson
{
  "text": "Hello world",
  "maxTokens": 100,
  "tokenizer": "cl100k_base",
  "direction": "KEEP_START"
}
Expected outputjson
{
  "removedTokenCount": 0,
  "tokenizer": "cl100k_base",
  "boundaryAdjusted": false,
  "boundaryTokensDropped": 0,
  "warnings": [],
  "requestedMaxTokens": 100,
  "originalTokenCount": 2,
  "skill": "text.truncate_to_tokens",
  "tokenizer_version": "jtokkit-1.1.0",
  "text": "Hello world",
  "outputStorage": "INLINE",
  "direction": "KEEP_START",
  "resultTokenCount": 2,
  "truncated": false
}
Tip
Input is under the budget, so the text is returned unchanged
  • Fit a document into a model context window before a call
  • Cap retrieved context to a token budget
  • Keep the most recent text within a token limit (KEEP_END)

Avoid for

  • Semantic truncation that needs understanding
  • Truncation by characters or words (use character/word 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.

Tags

transformationtext