UsageMetadata
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public struct UsageMetadata : Sendable
extension GenerateContentResponse.UsageMetadata: Decodable
Token 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 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
thinkingBudget
set 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]
-
Declaration
Swift
public init(from decoder: any Decoder) throws