@@ -62,6 +62,8 @@ pub struct AIClient {
6262 pub ( crate ) stream_options : StreamOptions ,
6363 pub ( crate ) model_reasoning_preset : Option < ReasoningPresetDescriptor > ,
6464 pub ( crate ) selected_reasoning_preset : Option < ReasoningPresetDescriptor > ,
65+ #[ cfg( feature = "subscription-auth" ) ]
66+ subscription_provider : Option < crate :: subscription_auth:: SubscriptionProvider > ,
6567}
6668
6769impl AIClient {
@@ -95,6 +97,31 @@ impl AIClient {
9597 stream_options,
9698 model_reasoning_preset : None ,
9799 selected_reasoning_preset : None ,
100+ #[ cfg( feature = "subscription-auth" ) ]
101+ subscription_provider : None ,
102+ }
103+ }
104+
105+ /// Enable provider policy only after resolving an explicit subscription login.
106+ /// This runtime identity is not inferred from URLs or serialized in AIConfig.
107+ #[ cfg( feature = "subscription-auth" ) ]
108+ pub fn with_subscription_provider (
109+ mut self ,
110+ provider : crate :: subscription_auth:: SubscriptionProvider ,
111+ ) -> Self {
112+ self . subscription_provider = Some ( provider) ;
113+ self
114+ }
115+
116+ /// Explicit subscription identity; ordinary API-key clients return None.
117+ pub fn subscription_provider_key ( & self ) -> Option < & ' static str > {
118+ #[ cfg( feature = "subscription-auth" ) ]
119+ {
120+ self . subscription_provider . map ( |provider| provider. key ( ) )
121+ }
122+ #[ cfg( not( feature = "subscription-auth" ) ) ]
123+ {
124+ None
98125 }
99126 }
100127
@@ -196,15 +223,9 @@ impl AIClient {
196223 /// Clone this client with a different max output token limit while
197224 /// reusing the HTTP client.
198225 pub fn with_max_tokens ( & self , max_tokens : Option < u32 > ) -> Self {
199- let mut config = self . config . clone ( ) ;
200- config. max_tokens = max_tokens;
201- Self {
202- client : self . client . clone ( ) ,
203- config,
204- stream_options : self . stream_options . clone ( ) ,
205- model_reasoning_preset : self . model_reasoning_preset . clone ( ) ,
206- selected_reasoning_preset : self . selected_reasoning_preset . clone ( ) ,
207- }
226+ let mut cloned = self . clone ( ) ;
227+ cloned. config . max_tokens = max_tokens;
228+ cloned
208229 }
209230
210231 pub async fn send_message_stream (
@@ -366,6 +387,8 @@ impl AIClient {
366387 trace : Option < ModelExchangeTraceConfig > ,
367388 max_attempts : usize ,
368389 ) -> Result < GeminiResponse > {
390+ let request_context =
391+ crate :: providers:: shared:: prepare_request_context ( self , request_context) ;
369392 for attempt in 0 ..max_attempts {
370393 let stream_response = match self
371394 . send_message_stream_with_extra_body_and_max_attempts (
0 commit comments