@@ -23,6 +23,9 @@ public struct GenerateContentResponse: Sendable {
23
23
/// The number of tokens in the request prompt.
24
24
public let promptTokenCount : Int
25
25
26
+ /// Number of tokens in the cached part of the prompt (the cached content)
27
+ public let cachedContentTokenCount : Int
28
+
26
29
/// The total number of tokens across the generated response candidates.
27
30
public let candidatesTokenCount : Int
28
31
@@ -42,6 +45,9 @@ public struct GenerateContentResponse: Sendable {
42
45
/// The breakdown, by modality, of how many tokens are consumed by the prompt
43
46
public let promptTokensDetails : [ ModalityTokenCount ]
44
47
48
+ /// The breakdown, by modality, of how many tokens are consumed by the cachedContent
49
+ public let cacheTokensDetails : [ ModalityTokenCount ]
50
+
45
51
/// The breakdown, by modality, of how many tokens are consumed by the candidates
46
52
public let candidatesTokensDetails : [ ModalityTokenCount ]
47
53
}
@@ -339,22 +345,27 @@ extension GenerateContentResponse: Decodable {
339
345
extension GenerateContentResponse . UsageMetadata : Decodable {
340
346
enum CodingKeys : CodingKey {
341
347
case promptTokenCount
348
+ case cacheContentTokenCount
342
349
case candidatesTokenCount
343
350
case thoughtsTokenCount
344
351
case totalTokenCount
345
352
case promptTokensDetails
353
+ case cacheTokensDetails
346
354
case candidatesTokensDetails
347
355
}
348
356
349
357
public init ( from decoder: any Decoder ) throws {
350
358
let container = try decoder. container ( keyedBy: CodingKeys . self)
351
359
promptTokenCount = try container. decodeIfPresent ( Int . self, forKey: . promptTokenCount) ?? 0
360
+ cachedContentTokenCount = try container. decodeIfPresent ( Int . self, forKey: . cacheContentTokenCount) ?? 0
352
361
candidatesTokenCount =
353
362
try container. decodeIfPresent ( Int . self, forKey: . candidatesTokenCount) ?? 0
354
363
thoughtsTokenCount = try container. decodeIfPresent ( Int . self, forKey: . thoughtsTokenCount) ?? 0
355
364
totalTokenCount = try container. decodeIfPresent ( Int . self, forKey: . totalTokenCount) ?? 0
356
365
promptTokensDetails =
357
366
try container. decodeIfPresent ( [ ModalityTokenCount ] . self, forKey: . promptTokensDetails) ?? [ ]
367
+ cacheTokensDetails =
368
+ try container. decodeIfPresent ( [ ModalityTokenCount ] . self, forKey: . cacheTokensDetails) ?? [ ]
358
369
candidatesTokensDetails = try container. decodeIfPresent (
359
370
[ ModalityTokenCount ] . self,
360
371
forKey: . candidatesTokensDetails
0 commit comments