CountTokensResponse

Response message for PredictionService.CountTokens.

Fields
totalTokens integer

The total number of tokens counted across all instances from the request.

totalBillableCharacters integer

The total number of billable characters counted across all instances from the request.

promptTokensDetails[] object (ModalityTokenCount)

Output only. List of modalities that were processed in the request input.

JSON representation
{
  "totalTokens": integer,
  "totalBillableCharacters": integer,
  "promptTokensDetails": [
    {
      object (ModalityTokenCount)
    }
  ]
}

ModalityTokenCount

Represents a breakdown of token usage by modality.

This message is used in [CountTokensResponse][google.cloud.aiplatform.master.CountTokensResponse] and GenerateContentResponse.UsageMetadata to provide a detailed view of how many tokens are used by each modality (e.g., text, image, video) in a request. This is particularly useful for multimodal models, allowing you to track and manage token consumption for billing and quota purposes.

Fields
modality enum (Modality)

The modality that this token count applies to.

tokenCount integer

The number of tokens counted for this modality.

JSON representation
{
  "modality": enum (Modality),
  "tokenCount": integer
}

Modality

The modality of a Part of a Content message. A modality is the type of media, such as an image or a video. It is used to categorize the content of a Part for token counting purposes.

Enums
MODALITY_UNSPECIFIED When a modality is not specified, it is treated as TEXT.
TEXT The Part contains plain text.
IMAGE The Part contains an image.
VIDEO The Part contains a video.
AUDIO The Part contains audio.
DOCUMENT The Part contains a document, such as a PDF.