countTokens

suspend fun countTokens(model: String, contents: List<Content>, config: CountTokensConfig? = null): CountTokensResponse

Counts the number of tokens in the given List object.

Return

A CountTokensResponse object containing the token count.

Parameters

model

The model to use for counting tokens.

contents

The List to count tokens for.

config

Optional configuration for counting tokens.


suspend fun countTokens(model: String, content: Content, config: CountTokensConfig? = null): CountTokensResponse

Counts the number of tokens in the provided Content object.

Return

A CountTokensResponse object containing the token count.

Parameters

model

The model to use for counting tokens.

content

The Content object to count tokens for.

config

Optional configuration for counting tokens.


suspend fun countTokens(model: String, text: String, config: CountTokensConfig? = null): CountTokensResponse

Counts the number of tokens in the provided text string.

Return

A CountTokensResponse object containing the token count.

Parameters

model

The model to use for counting tokens.

text

The text string to count tokens for.

config

Optional configuration for counting tokens.