@@ -23,6 +23,9 @@ public struct GenerateContentResponse: Sendable {
2323 /// The number of tokens in the request prompt.
2424 public let promptTokenCount: Int
2525
26+ /// Number of tokens in the cached part of the prompt (the cached content)
27+ public let cachedContentTokenCount: Int
28+
2629 /// The total number of tokens across the generated response candidates.
2730 public let candidatesTokenCount: Int
2831
@@ -32,6 +35,9 @@ public struct GenerateContentResponse: Sendable {
3235 /// The breakdown, by modality, of how many tokens are consumed by the prompt
3336 public let promptTokensDetails: [ModalityTokenCount]
3437
38+ /// The breakdown, by modality, of how many tokens are consumed by the cachedContent
39+ public let cacheTokensDetails: [ModalityTokenCount]
40+
3541 /// The breakdown, by modality, of how many tokens are consumed by the candidates
3642 public let candidatesTokensDetails: [ModalityTokenCount]
3743 }
@@ -329,20 +335,25 @@ extension GenerateContentResponse: Decodable {
329335extension GenerateContentResponse.UsageMetadata: Decodable {
330336 enum CodingKeys: CodingKey {
331337 case promptTokenCount
338+ case cacheContentTokenCount
332339 case candidatesTokenCount
333340 case totalTokenCount
334341 case promptTokensDetails
342+ case cacheTokensDetails
335343 case candidatesTokensDetails
336344 }
337345
338346 public init(from decoder: any Decoder) throws {
339347 let container = try decoder.container(keyedBy: CodingKeys.self)
340348 promptTokenCount = try container.decodeIfPresent(Int.self, forKey: .promptTokenCount) ?? 0
349+ cachedContentTokenCount = try container.decodeIfPresent(Int.self, forKey: .cacheContentTokenCount) ?? 0
341350 candidatesTokenCount =
342351 try container.decodeIfPresent(Int.self, forKey: .candidatesTokenCount) ?? 0
343352 totalTokenCount = try container.decodeIfPresent(Int.self, forKey: .totalTokenCount) ?? 0
344353 promptTokensDetails =
345354 try container.decodeIfPresent([ModalityTokenCount].self, forKey: .promptTokensDetails) ?? []
355+ cacheTokensDetails =
356+ try container.decodeIfPresent([ModalityTokenCount].self, forKey: .cacheTokensDetails) ?? []
346357 candidatesTokensDetails = try container.decodeIfPresent(
347358 [ModalityTokenCount].self,
348359 forKey: .candidatesTokensDetails
0 commit comments