@@ -26,6 +26,9 @@ public struct GenerateContentResponse: Sendable {
2626    /// The total number of tokens across the generated response candidates.
2727    public  let  candidatesTokenCount :  Int 
2828
29+     /// The number of tokens used by tools.
30+     public  let  toolUsePromptTokenCount :  Int 
31+ 
2932    /// The number of tokens used by the model's internal "thinking" process.
3033    ///
3134    /// For models that support thinking (like Gemini 2.5 Pro and Flash), this represents the actual
@@ -39,11 +42,15 @@ public struct GenerateContentResponse: Sendable {
3942    /// The total number of tokens in both the request and response.
4043    public  let  totalTokenCount :  Int 
4144
42-     /// The breakdown, by modality, of how many tokens are consumed by the prompt
45+     /// The breakdown, by modality, of how many tokens are consumed by the prompt. 
4346    public  let  promptTokensDetails :  [ ModalityTokenCount ] 
4447
4548    /// The breakdown, by modality, of how many tokens are consumed by the candidates
4649    public  let  candidatesTokensDetails :  [ ModalityTokenCount ] 
50+ 
51+     /// The breakdown, by modality, of how many tokens were consumed by the tools used to process
52+     /// the request.
53+     public  let  toolUsePromptTokensDetails :  [ ModalityTokenCount ] 
4754  } 
4855
4956  /// A list of candidate response content, ordered from best to worst.
@@ -154,14 +161,19 @@ public struct Candidate: Sendable {
154161
155162  public  let  groundingMetadata :  GroundingMetadata ? 
156163
164+   /// Metadata related to the ``URLContext`` tool.
165+   public  let  urlContextMetadata :  URLContextMetadata ? 
166+ 
157167  /// Initializer for SwiftUI previews or tests.
158168  public  init ( content:  ModelContent ,  safetyRatings:  [ SafetyRating ] ,  finishReason:  FinishReason ? , 
159-               citationMetadata:  CitationMetadata ? ,  groundingMetadata:  GroundingMetadata ? =  nil )  { 
169+               citationMetadata:  CitationMetadata ? ,  groundingMetadata:  GroundingMetadata ? =  nil , 
170+               urlContextMetadata:  URLContextMetadata ? =  nil )  { 
160171    self . content =  content
161172    self . safetyRatings =  safetyRatings
162173    self . finishReason =  finishReason
163174    self . citationMetadata =  citationMetadata
164175    self . groundingMetadata =  groundingMetadata
176+     self . urlContextMetadata =  urlContextMetadata
165177  } 
166178
167179  // Returns `true` if the candidate contains no information that a developer could use.
@@ -469,17 +481,21 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
469481  enum  CodingKeys :  CodingKey  { 
470482    case  promptTokenCount
471483    case  candidatesTokenCount
484+     case  toolUsePromptTokenCount
472485    case  thoughtsTokenCount
473486    case  totalTokenCount
474487    case  promptTokensDetails
475488    case  candidatesTokensDetails
489+     case  toolUsePromptTokensDetails
476490  } 
477491
478492  public  init ( from decoder:  any  Decoder )  throws  { 
479493    let  container  =  try . container ( keyedBy:  CodingKeys . self) 
480494    promptTokenCount =  try . decodeIfPresent ( Int . self,  forKey:  . promptTokenCount)  ??  0 
481495    candidatesTokenCount = 
482496      try . decodeIfPresent ( Int . self,  forKey:  . candidatesTokenCount)  ??  0 
497+     toolUsePromptTokenCount = 
498+       try . decodeIfPresent ( Int . self,  forKey:  . toolUsePromptTokenCount)  ??  0 
483499    thoughtsTokenCount =  try . decodeIfPresent ( Int . self,  forKey:  . thoughtsTokenCount)  ??  0 
484500    totalTokenCount =  try . decodeIfPresent ( Int . self,  forKey:  . totalTokenCount)  ??  0 
485501    promptTokensDetails = 
@@ -488,6 +504,9 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
488504      [ ModalityTokenCount ] . self, 
489505      forKey:  . candidatesTokensDetails
490506    )  ??  [ ] 
507+     toolUsePromptTokensDetails =  try . decodeIfPresent ( 
508+       [ ModalityTokenCount ] . self,  forKey:  . toolUsePromptTokensDetails
509+     )  ??  [ ] 
491510  } 
492511} 
493512
@@ -499,6 +518,7 @@ extension Candidate: Decodable {
499518    case  finishReason
500519    case  citationMetadata
501520    case  groundingMetadata
521+     case  urlContextMetadata
502522  } 
503523
504524  /// Initializes a response from a decoder. Used for decoding server responses; not for public
@@ -540,6 +560,14 @@ extension Candidate: Decodable {
540560      GroundingMetadata . self, 
541561      forKey:  . groundingMetadata
542562    ) 
563+ 
564+     if  let  urlContextMetadata = 
565+       try . decodeIfPresent ( URLContextMetadata . self,  forKey:  . urlContextMetadata) , 
566+       !urlContextMetadata. urlMetadata. isEmpty { 
567+       self . urlContextMetadata =  urlContextMetadata
568+     }  else  { 
569+       urlContextMetadata =  nil 
570+     } 
543571  } 
544572} 
545573
0 commit comments