Skip to main content

token_counts

Creates, updates, deletes, gets or lists a token_counts resource.

Overview

Nametoken_counts
TypeResource
Idgemini.models.token_counts

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
cachedContentTokenCountinteger (int32)Number of tokens in the cached part of the prompt (the cached content).
cacheTokensDetailsarrayOutput only. List of modalities that were processed in the cached content.
promptTokensDetailsarrayOutput only. List of modalities that were processed in the request input.
totalTokensinteger (int32)The number of tokens that the `Model` tokenizes the `prompt` into. Always non-negative.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
count_tokensselectmodelsIdgenerateContentRequest, contentsRuns a model's tokenizer on input Content and returns the token count. Refer to the tokens guide to learn more about tokens.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
modelsIdstring
contentsarrayOptional. The input given to the model as a prompt. This field is ignored when generate_content_request is set.
generateContentRequestobjectRequest to generate a completion from the model.

SELECT examples

Runs a model's tokenizer on input Content and returns the token count. Refer to the tokens guide to learn more about tokens.

SELECT
cacheTokensDetails,
cachedContentTokenCount,
promptTokensDetails,
totalTokens
FROM gemini.models.token_counts
WHERE modelsId = '{{ modelsId }}' -- required
AND generateContentRequest = '{{ generateContentRequest }}'
AND contents = '{{ contents }}'
;