computeTokens

suspend fun computeTokens(model: String, contents: List<Content>, config: ComputeTokensConfig? = null): ComputeTokensResponse

Computes the number of tokens for the given List object.

This method is not supported by the Gemini Developer API.

Return

A ComputeTokensResponse object containing the token information.

Parameters

model

The model to use for computing tokens.

contents

The List to compute tokens for.

config

Optional configuration for computing tokens.

Throws

if called with a non-Gemini Enterprise Agent Platform (previously known as Vertex AI) client.


suspend fun computeTokens(model: String, content: Content, config: ComputeTokensConfig? = null): ComputeTokensResponse

Computes the number of tokens for the provided Content object.

This method is not supported by the Gemini Developer API.

Return

A ComputeTokensResponse object containing the token information.

Parameters

model

The model to use for computing tokens.

content

The Content object to compute tokens for.

config

Optional configuration for computing tokens.

Throws

if called with a non-Gemini Enterprise Agent Platform (previously known as Vertex AI) client.


suspend fun computeTokens(model: String, text: String, config: ComputeTokensConfig? = null): ComputeTokensResponse

Computes the number of tokens for the provided text string.

This method is not supported by the Gemini Developer API.

Return

A ComputeTokensResponse object containing the token information.

Parameters

model

The model to use for computing tokens.

text

The text string to compute tokens for.

config

Optional configuration for computing tokens.

Throws

if called with a non-Gemini Enterprise Agent Platform (previously known as Vertex AI) client.