COUNT_TOKENS

functiondeferredAI & ML

docs.snowflake.com ↗

String & binary functions

Notice This page is provided for backward compatibility. For new use cases, start with AI_COUNT_TOKENS, which is the canonical surface going forward. This legacy function will be deprecated by the end of 2026. Returns the number of tokens in a prompt for the large language model or the task-specific function specified in the argument. This function does not support fine-tuned models.

Syntax

SNOWFLAKE.CORTEX.COUNT_TOKENS( <model_name> , <input_text> )

Parameters

NameRequiredDescription
model_namerequiredName of the model you want to base the token count on. See supported models.
input_textrequiredInput text to count the tokens in.

Returns

Returns an INT , INTEGER , BIGINT , SMALLINT , TINYINT , BYTEINT type that is the number of tokens in the input text based on the model or function specified.

Usage notes

Legal notices

Refer to Snowflake AI and ML.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.