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 Summary
ConstructorsConstructorDescriptionGoogleGenAiUsage(Integer promptTokens, Integer completionTokens, Integer totalTokens, @Nullable Integer thoughtsTokenCount, @Nullable Integer cachedContentTokenCount, @Nullable Integer toolUsePromptTokenCount, @Nullable List<GoogleGenAiModalityTokenCount> promptTokensDetails, @Nullable List<GoogleGenAiModalityTokenCount> candidatesTokensDetails, @Nullable List<GoogleGenAiModalityTokenCount> cacheTokensDetails, @Nullable List<GoogleGenAiModalityTokenCount> toolUsePromptTokensDetails, @Nullable GoogleGenAiTrafficType trafficType, @Nullable com.google.genai.types.GenerateContentResponseUsageMetadata nativeUsage) Creates a new GoogleGenAiUsage instance with all extended metadata. -
Method Summary
Modifier and TypeMethodDescriptionstatic GoogleGenAiUsagefrom(@Nullable com.google.genai.types.GenerateContentResponseUsageMetadata usageMetadata) Creates a GoogleGenAiUsage instance from the Google GenAI SDK response metadata.@Nullable IntegerReturns the number of tokens in the cached content.@Nullable Long@Nullable List<GoogleGenAiModalityTokenCount>Returns the list of modalities of the cached content in the request input.@Nullable List<GoogleGenAiModalityTokenCount>Returns the list of modalities that were returned in the response.@Nullable List<GoogleGenAiModalityTokenCount>Returns the list of modalities that were processed in the request input.@Nullable IntegerReturns the number of tokens present in thoughts output for thinking-enabled models.@Nullable IntegerReturns the number of tokens present in tool-use prompts.@Nullable List<GoogleGenAiModalityTokenCount>Returns the list of modalities that were processed for tool-use request inputs.@Nullable GoogleGenAiTrafficTypeReturns the traffic type showing whether a request consumes Pay-As-You-Go or Provisioned Throughput quota.toString()Methods inherited from class org.springframework.ai.chat.metadata.DefaultUsage
equals, fromJson, getCacheWriteInputTokens, getCompletionTokens, getNativeUsage, getPromptTokens, getTotalTokens, hashCode
-
Constructor Details
-
GoogleGenAiUsage
public GoogleGenAiUsage(Integer promptTokens, Integer completionTokens, Integer totalTokens, @Nullable Integer thoughtsTokenCount, @Nullable Integer cachedContentTokenCount, @Nullable Integer toolUsePromptTokenCount, @Nullable List<GoogleGenAiModalityTokenCount> promptTokensDetails, @Nullable List<GoogleGenAiModalityTokenCount> candidatesTokensDetails, @Nullable List<GoogleGenAiModalityTokenCount> cacheTokensDetails, @Nullable List<GoogleGenAiModalityTokenCount> toolUsePromptTokensDetails, @Nullable GoogleGenAiTrafficType trafficType, @Nullable com.google.genai.types.GenerateContentResponseUsageMetadata nativeUsage) Creates a new GoogleGenAiUsage instance with all extended metadata.
-
-
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
Returns the number of tokens present in thoughts output for thinking-enabled models.- Returns:
- the thoughts token count, or null if not available
-
getCachedContentTokenCount
Returns the number of tokens in the cached content.- Returns:
- the cached content token count, or null if not available
-
getCacheReadInputTokens
- Specified by:
getCacheReadInputTokensin interfaceorg.springframework.ai.chat.metadata.Usage- Overrides:
getCacheReadInputTokensin classorg.springframework.ai.chat.metadata.DefaultUsage
-
getToolUsePromptTokenCount
Returns the number of tokens present in tool-use prompts.- Returns:
- the tool-use prompt token count, or null if not available
-
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
Returns the list of modalities that were returned in the response.- Returns:
- the candidates tokens details by modality, or null if not available
-
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
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
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
- Overrides:
toStringin classorg.springframework.ai.chat.metadata.DefaultUsage
-