Class UsageMetadata

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

public abstract class UsageMetadata extends JsonSerializable
Usage metadata about response(s).
  • Constructor Details

    • UsageMetadata

      public UsageMetadata()
  • Method Details

    • promptTokenCount

      public abstract Optional<Integer> promptTokenCount()
      Number of tokens in the prompt. When `cached_content` is set, this is still the total effective prompt size meaning this includes the number of tokens in the cached content.
    • cachedContentTokenCount

      public abstract Optional<Integer> cachedContentTokenCount()
      Number of tokens in the cached part of the prompt (the cached content).
    • responseTokenCount

      public abstract Optional<Integer> responseTokenCount()
      Total number of tokens across all the generated response candidates.
    • toolUsePromptTokenCount

      public abstract Optional<Integer> toolUsePromptTokenCount()
      Number of tokens present in tool-use prompt(s).
    • thoughtsTokenCount

      public abstract Optional<Integer> thoughtsTokenCount()
      Number of tokens of thoughts for thinking models.
    • totalTokenCount

      public abstract Optional<Integer> totalTokenCount()
      Total token count for prompt, response candidates, and tool-use prompts(if present).
    • promptTokensDetails

      public abstract Optional<List<ModalityTokenCount>> promptTokensDetails()
      List of modalities that were processed in the request input.
    • cacheTokensDetails

      public abstract Optional<List<ModalityTokenCount>> cacheTokensDetails()
      List of modalities that were processed in the cache input.
    • responseTokensDetails

      public abstract Optional<List<ModalityTokenCount>> responseTokensDetails()
      List of modalities that were returned in the response.
    • toolUsePromptTokensDetails

      public abstract Optional<List<ModalityTokenCount>> toolUsePromptTokensDetails()
      List of modalities that were processed in the tool-use prompt.
    • trafficType

      public abstract Optional<TrafficType> trafficType()
      Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned Throughput quota.
    • builder

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

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

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