Skip to main content
The TokenChunker splits text into chunks based on token count, ensuring each chunk stays within specified token limits.

API Reference

To use the TokenChunker via the API, check out the API reference documentation.

Installation

TokenChunker is included in the base installation of Chonkie.
If you would like to use custom tokenizers in JavaScript, please install the @chonkiejs/token library

Initialization

Parameters

Union[str, Any]
default:"character"
Tokenizer to use. Can be a string identifier (“character”, “word”, “byte”, “gpt2”, etc.) or a tokenizer instance
int
default:"2048"
Maximum number of tokens per chunk
Union[int, float]
default:"0"
Number or percentage of overlapping tokens between chunks

Basic Usage

Examples

Batch processing is only supported in Python
Custom tokenizers are only supported in Python. See the Installation section for JavaScript tokenizer support.
The callable interface is only supported in Python

Supported Tokenizers

Changing tokenizer backend is only supported on Python
TokenChunker supports multiple tokenizer backends:
  • TikToken (Recommended)
  • AutoTikTokenizer
  • Hugging Face Tokenizers
  • Transformers

Return Type

TokenChunker returns chunks as Chunk objects.