openai.encode

Returns the tokenized representation of a text.

This function doesn’t call the API, encoding is performed locally.

Syntax

encode(encoding, text, specialTokens?)

Parameters

Return value

An array of numbers representing the encoded text.

Bugs

Since OpenAI tokenizers don’t have a formal specification, the current encoder may differ from the one used by OpenAI in some cases.

Examples

openai.encode("cl100k_base", "hello world")
[15339, 1917]

See also

External resources