UsageMetadata
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public struct UsageMetadata : Sendableextension GenerateContentResponse.UsageMetadata: DecodableToken usage metadata for processing the generate content request.
-
The number of tokens in the request prompt.
Declaration
Swift
public let promptTokenCount: Int -
The total number of tokens across the generated response candidates.
Declaration
Swift
public let candidatesTokenCount: Int -
The number of tokens used by tools.
Declaration
Swift
public let toolUsePromptTokenCount: Int -
The number of tokens used by the model’s internal “thinking” process.
For models that support thinking (like Gemini 2.5 Pro and Flash), this represents the actual number of tokens consumed for reasoning before the model generated a response. For models that do not support thinking, this value will be
0.When thinking is used, this count will be less than or equal to the
thinkingBudgetset in theThinkingConfig.Declaration
Swift
public let thoughtsTokenCount: Int -
The total number of tokens in both the request and response.
Declaration
Swift
public let totalTokenCount: Int -
The breakdown, by modality, of how many tokens are consumed by the prompt.
Declaration
Swift
public let promptTokensDetails: [ModalityTokenCount] -
The breakdown, by modality, of how many tokens are consumed by the candidates
Declaration
Swift
public let candidatesTokensDetails: [ModalityTokenCount] -
The breakdown, by modality, of how many tokens were consumed by the tools used to process the request.
Declaration
Swift
public let toolUsePromptTokensDetails: [ModalityTokenCount]
-
Declaration
Swift
public init(from decoder: any Decoder) throws