Class ModalityTokenCount

java.lang.Object
com.google.genai.JsonSerializable
com.google.genai.types.ModalityTokenCount

public abstract class ModalityTokenCount extends JsonSerializable
Represents a breakdown of token usage by modality. This message is used in 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.
  • Constructor Details

    • ModalityTokenCount

      public ModalityTokenCount()
  • Method Details

    • modality

      public abstract Optional<MediaModality> modality()
      The modality that this token count applies to.
    • tokenCount

      public abstract Optional<Integer> tokenCount()
      The number of tokens counted for this modality.
    • builder

      public static ModalityTokenCount.Builder builder()
      Instantiates a builder for ModalityTokenCount.
    • toBuilder

      public abstract ModalityTokenCount.Builder toBuilder()
      Creates a builder with the same values as this instance.
    • fromJson

      public static ModalityTokenCount fromJson(String jsonString)
      Deserializes a JSON string to a ModalityTokenCount object.