Token Truncator
text.truncate_to_tokens
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
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
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. |
| maxTokens | integer | Yes | Maximum returned tokens, including zero. |
| tokenizer | string | No | Tokenizer encoding; omit it for cl100k_base. |
| direction | string | No | Retained end; omit it for KEEP_START. |
Output schema
| Field | Type | Required | Description |
|---|---|---|---|
| skill | string | Yes | Producing stable skill key. |
| text | string | Yes | Returned text within the requested token budget. |
| outputStorage | string | Yes | Applied inline output storage mode. |
| tokenizer | string | Yes | Applied tokenizer encoding. |
| tokenizer_version | string | Yes | Pinned tokenizer-library version. |
| direction | string | Yes | Applied retained end. |
| requestedMaxTokens | integer | Yes | Requested token ceiling. |
| originalTokenCount | integer | Yes | Original input token count. |
| resultTokenCount | integer | Yes | Returned text token count. |
| removedTokenCount | integer | Yes | Removed token count. |
| truncated | boolean | Yes | Whether any token was removed. |
| boundaryAdjusted | boolean | Yes | Whether a character-safe cut stopped below the budget. |
| boundaryTokensDropped | integer | Yes | Additional boundary-safety token reduction. |
| 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.truncate_to_tokens","input":{"text":"Hello world","tokenizer":"o200k_base","maxTokens":4000,"direction":"KEEP_END"}}'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
| 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 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)
{
"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
{
"text": "The quick brown fox jumps over the lazy dog.",
"maxTokens": 4,
"tokenizer": "cl100k_base",
"direction": "KEEP_START"
}{
"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
}Already within budget (no truncation)
{
"text": "Hello world",
"maxTokens": 100,
"tokenizer": "cl100k_base",
"direction": "KEEP_START"
}{
"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
}Recommended use cases
- 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)
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.