countTokens

fun countTokens(inputJson: CountTokensRequest, model: String = "gemini-2.0-flash-lite"): TotalTokens

Counts the number of tokens in the provided text using a specified model.

Return

A TotalTokens object containing the total number of tokens.

Parameters

inputJson

The request object containing the text to analyze.

model

The model to use for counting tokens, default is "gemini-2.0-flash-lite".