File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -357,8 +357,9 @@ def api_client(self) -> Client:
357357 if self .model .startswith ('projects/' ):
358358 kwargs ['enterprise' ] = True
359359
360- if self .client_kwargs :
361- kwargs .update (self .client_kwargs )
360+ client_kwargs = getattr (self , 'client_kwargs' , None )
361+ if client_kwargs :
362+ kwargs .update (client_kwargs )
362363
363364 return Client (** kwargs )
364365
@@ -405,8 +406,9 @@ def _live_api_client(self) -> Client:
405406 if self .model .startswith ('projects/' ):
406407 kwargs ['enterprise' ] = True
407408
408- if self .client_kwargs :
409- kwargs .update (self .client_kwargs )
409+ client_kwargs = getattr (self , 'client_kwargs' , None )
410+ if client_kwargs :
411+ kwargs .update (client_kwargs )
410412
411413 return Client (** kwargs )
412414
Original file line number Diff line number Diff line change @@ -242,6 +242,20 @@ def test_gemini_repr_excludes_client_kwargs():
242242 assert "client_kwargs" not in repr_str
243243
244244
245+ def test_gemini_api_client_when_client_kwargs_missing_from_dict ():
246+ model = Gemini (model = "gemini-2.5-flash" )
247+ model .__dict__ .pop ("client_kwargs" , None )
248+ assert "client_kwargs" not in model .__dict__
249+
250+ with mock .patch ("google.genai.Client" , autospec = True ) as mock_client :
251+ _ = model .api_client
252+ mock_client .assert_called_once ()
253+
254+ with mock .patch ("google.genai.Client" , autospec = True ) as mock_client :
255+ _ = model ._live_api_client
256+ mock_client .assert_called_once ()
257+
258+
245259def test_client_version_header ():
246260 model = Gemini (model = "gemini-2.5-flash" )
247261 client = model .api_client
You can’t perform that action at this time.
0 commit comments