@@ -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
@@ -32,6 +35,9 @@ public struct GenerateContentResponse: Sendable {
32
35
/// The breakdown, by modality, of how many tokens are consumed by the prompt
33
36
public let promptTokensDetails : [ ModalityTokenCount ]
34
37
38
+ /// The breakdown, by modality, of how many tokens are consumed by the cachedContent
39
+ public let cacheTokensDetails : [ ModalityTokenCount ]
40
+
35
41
/// The breakdown, by modality, of how many tokens are consumed by the candidates
36
42
public let candidatesTokensDetails : [ ModalityTokenCount ]
37
43
}
@@ -329,20 +335,25 @@ extension GenerateContentResponse: Decodable {
329
335
extension GenerateContentResponse . UsageMetadata : Decodable {
330
336
enum CodingKeys : CodingKey {
331
337
case promptTokenCount
338
+ case cacheContentTokenCount
332
339
case candidatesTokenCount
333
340
case totalTokenCount
334
341
case promptTokensDetails
342
+ case cacheTokensDetails
335
343
case candidatesTokensDetails
336
344
}
337
345
338
346
public init ( from decoder: any Decoder ) throws {
339
347
let container = try decoder. container ( keyedBy: CodingKeys . self)
340
348
promptTokenCount = try container. decodeIfPresent ( Int . self, forKey: . promptTokenCount) ?? 0
349
+ cachedContentTokenCount = try container. decodeIfPresent ( Int . self, forKey: . cacheContentTokenCount) ?? 0
341
350
candidatesTokenCount =
342
351
try container. decodeIfPresent ( Int . self, forKey: . candidatesTokenCount) ?? 0
343
352
totalTokenCount = try container. decodeIfPresent ( Int . self, forKey: . totalTokenCount) ?? 0
344
353
promptTokensDetails =
345
354
try container. decodeIfPresent ( [ ModalityTokenCount ] . self, forKey: . promptTokensDetails) ?? [ ]
355
+ cacheTokensDetails =
356
+ try container. decodeIfPresent ( [ ModalityTokenCount ] . self, forKey: . cacheTokensDetails) ?? [ ]
346
357
candidatesTokensDetails = try container. decodeIfPresent (
347
358
[ ModalityTokenCount ] . self,
348
359
forKey: . candidatesTokensDetails
0 commit comments