Samples
Tokenize text
Convert a string into tokens:Count tokens
Determine how many tokens a text will use:Check token count before API call
Ensure your text fits within model limits:Arguments
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
model | TEXT | - | ✔ | The OpenAI model to tokenize for (e.g., text-embedding-ada-002, gpt-4o) |
text_input | TEXT | - | ✔ | The text to convert into tokens |
Returns
INT[]: An array of token IDs representing the input text.
Related functions
openai_detokenize(): convert tokens back into textopenai_embed(): generate embeddings from text or tokensopenai_chat_complete(): use tokens for completion