Skip to main content
Convert text into an array of token IDs using OpenAI’s tokenization algorithm. This is useful for counting tokens to estimate API costs, stay within model limits, and understand how your text is processed.

Samples

Tokenize text

Convert a string into tokens:
Returns:

Count tokens

Determine how many tokens a text will use:
Returns:

Check token count before API call

Ensure your text fits within model limits:

Arguments

Returns

INT[]: An array of token IDs representing the input text.