Class GoogleGenAiUsage

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

public class GoogleGenAiUsage extends 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(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

      @Nullable public 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

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

      @Nullable public 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

      @Nullable public 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

      @Nullable public 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

      @Nullable public 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

      @Nullable public 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

      @Nullable public 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 DefaultUsage