Skip to main content
Version: 1.25

Count Tokens

Audience: Citizen Developer

Skill Prerequisites: Tokens

This action counts the number of tokens for an OpenAI model.

Typical Use Cases

  • Calculate the number of tokens in a text string for OpenAI API usage

Don't use it to

  • Count words or characters in a string (use other string manipulation methods instead)

None

Input Parameter Reference

ParameterDescriptionSupports TokensDefaultRequired
ModelThe name of the OpenAI model. Choose from the list of available models. Can contain tokens.Yesempty stringNo
ContentThe text for which you want to count the tokens. Can contain tokens.Yesempty stringNo

Output Parameters Reference

ParameterDescription
Store Token CountThe token count for the provided text and model.

Examples

1. Count tokens for GPT-3.5-turbo model (DRAFT)

Count the number of tokens in a text string for the GPT-3.5-turbo model and store the result in a token named "TokenCount".

{
"Action": "OpenAi.CountTokens",
"Parameters": {
"ModelName": "gpt-3.5-turbo",
"Content": "This is a sample text string.",
"StoreTokenCount": "TokenCount"
}
}

For example, you can import this JSON content into a workflow using the "Import Actions" button.