Class GoogleGenAiUsage

java.lang.Object
org.springframework.ai.chat.metadata.DefaultUsage
org.springframework.ai.google.genai.metadata.GoogleGenAiUsage
All Implemented Interfaces:
org.springframework.ai.chat.metadata.Usage

public class GoogleGenAiUsage extends org.springframework.ai.chat.metadata.DefaultUsage
Extended usage metadata for Google GenAI responses that includes thinking tokens, cached content, tool-use tokens, and modality breakdowns.
Since:
1.1.0
Author:
Dan Dobrin
  • Constructor Details

  • Method Details

    • from

      public static GoogleGenAiUsage from(@Nullable com.google.genai.types.GenerateContentResponseUsageMetadata usageMetadata)
      Creates a GoogleGenAiUsage instance from the Google GenAI SDK response metadata.
      Parameters:
      usageMetadata - the usage metadata from the Google GenAI SDK
      Returns:
      a new GoogleGenAiUsage instance with all available metadata
    • getThoughtsTokenCount

      public @Nullable Integer getThoughtsTokenCount()
      Returns the number of tokens present in thoughts output for thinking-enabled models.
      Returns:
      the thoughts token count, or null if not available
    • getCachedContentTokenCount

      public @Nullable Integer getCachedContentTokenCount()
      Returns the number of tokens in the cached content.
      Returns:
      the cached content token count, or null if not available
    • getCacheReadInputTokens

      public @Nullable Long getCacheReadInputTokens()
      Specified by:
      getCacheReadInputTokens in interface org.springframework.ai.chat.metadata.Usage
      Overrides:
      getCacheReadInputTokens in class org.springframework.ai.chat.metadata.DefaultUsage
    • getToolUsePromptTokenCount

      public @Nullable Integer getToolUsePromptTokenCount()
      Returns the number of tokens present in tool-use prompts.
      Returns:
      the tool-use prompt token count, or null if not available
    • getPromptTokensDetails

      public @Nullable List<GoogleGenAiModalityTokenCount> getPromptTokensDetails()
      Returns the list of modalities that were processed in the request input.
      Returns:
      the prompt tokens details by modality, or null if not available
    • getCandidatesTokensDetails

      public @Nullable List<GoogleGenAiModalityTokenCount> getCandidatesTokensDetails()
      Returns the list of modalities that were returned in the response.
      Returns:
      the candidates tokens details by modality, or null if not available
    • getCacheTokensDetails

      public @Nullable List<GoogleGenAiModalityTokenCount> getCacheTokensDetails()
      Returns the list of modalities of the cached content in the request input.
      Returns:
      the cache tokens details by modality, or null if not available
    • getToolUsePromptTokensDetails

      public @Nullable List<GoogleGenAiModalityTokenCount> getToolUsePromptTokensDetails()
      Returns the list of modalities that were processed for tool-use request inputs.
      Returns:
      the tool-use prompt tokens details by modality, or null if not available
    • getTrafficType

      public @Nullable GoogleGenAiTrafficType getTrafficType()
      Returns the traffic type showing whether a request consumes Pay-As-You-Go or Provisioned Throughput quota.
      Returns:
      the traffic type, or null if not available
    • toString

      public String toString()
      Overrides:
      toString in class org.springframework.ai.chat.metadata.DefaultUsage