google-genai 1.54.0__py3-none-any.whl → 1.56.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. google/genai/__init__.py +1 -0
  2. google/genai/_interactions/__init__.py +117 -0
  3. google/genai/_interactions/_base_client.py +2025 -0
  4. google/genai/_interactions/_client.py +511 -0
  5. google/genai/_interactions/_compat.py +234 -0
  6. google/genai/_interactions/_constants.py +29 -0
  7. google/genai/_interactions/_exceptions.py +122 -0
  8. google/genai/_interactions/_files.py +139 -0
  9. google/genai/_interactions/_models.py +873 -0
  10. google/genai/_interactions/_qs.py +165 -0
  11. google/genai/_interactions/_resource.py +58 -0
  12. google/genai/_interactions/_response.py +847 -0
  13. google/genai/_interactions/_streaming.py +354 -0
  14. google/genai/_interactions/_types.py +276 -0
  15. google/genai/_interactions/_utils/__init__.py +79 -0
  16. google/genai/_interactions/_utils/_compat.py +61 -0
  17. google/genai/_interactions/_utils/_datetime_parse.py +151 -0
  18. google/genai/_interactions/_utils/_logs.py +40 -0
  19. google/genai/_interactions/_utils/_proxy.py +80 -0
  20. google/genai/_interactions/_utils/_reflection.py +57 -0
  21. google/genai/_interactions/_utils/_resources_proxy.py +39 -0
  22. google/genai/_interactions/_utils/_streams.py +27 -0
  23. google/genai/_interactions/_utils/_sync.py +73 -0
  24. google/genai/_interactions/_utils/_transform.py +472 -0
  25. google/genai/_interactions/_utils/_typing.py +172 -0
  26. google/genai/_interactions/_utils/_utils.py +437 -0
  27. google/genai/_interactions/_version.py +18 -0
  28. google/genai/_interactions/py.typed +0 -0
  29. google/genai/_interactions/resources/__init__.py +34 -0
  30. google/genai/_interactions/resources/interactions.py +1350 -0
  31. google/genai/_interactions/types/__init__.py +109 -0
  32. google/genai/_interactions/types/allowed_tools.py +33 -0
  33. google/genai/_interactions/types/allowed_tools_param.py +35 -0
  34. google/genai/_interactions/types/annotation.py +42 -0
  35. google/genai/_interactions/types/annotation_param.py +42 -0
  36. google/genai/_interactions/types/audio_content.py +37 -0
  37. google/genai/_interactions/types/audio_content_param.py +44 -0
  38. google/genai/_interactions/types/audio_mime_type.py +25 -0
  39. google/genai/_interactions/types/audio_mime_type_param.py +27 -0
  40. google/genai/_interactions/types/code_execution_call_arguments.py +33 -0
  41. google/genai/_interactions/types/code_execution_call_arguments_param.py +32 -0
  42. google/genai/_interactions/types/code_execution_call_content.py +36 -0
  43. google/genai/_interactions/types/code_execution_call_content_param.py +36 -0
  44. google/genai/_interactions/types/code_execution_result_content.py +41 -0
  45. google/genai/_interactions/types/code_execution_result_content_param.py +40 -0
  46. google/genai/_interactions/types/content_delta.py +342 -0
  47. google/genai/_interactions/types/content_start.py +79 -0
  48. google/genai/_interactions/types/content_stop.py +35 -0
  49. google/genai/_interactions/types/deep_research_agent_config.py +32 -0
  50. google/genai/_interactions/types/deep_research_agent_config_param.py +31 -0
  51. google/genai/_interactions/types/document_content.py +37 -0
  52. google/genai/_interactions/types/document_content_param.py +44 -0
  53. google/genai/_interactions/types/document_mime_type.py +23 -0
  54. google/genai/_interactions/types/document_mime_type_param.py +25 -0
  55. google/genai/_interactions/types/dynamic_agent_config.py +43 -0
  56. google/genai/_interactions/types/dynamic_agent_config_param.py +32 -0
  57. google/genai/_interactions/types/error_event.py +46 -0
  58. google/genai/_interactions/types/file_search_result_content.py +45 -0
  59. google/genai/_interactions/types/file_search_result_content_param.py +45 -0
  60. google/genai/_interactions/types/function.py +38 -0
  61. google/genai/_interactions/types/function_call_content.py +38 -0
  62. google/genai/_interactions/types/function_call_content_param.py +38 -0
  63. google/genai/_interactions/types/function_param.py +37 -0
  64. google/genai/_interactions/types/function_result_content.py +51 -0
  65. google/genai/_interactions/types/function_result_content_param.py +53 -0
  66. google/genai/_interactions/types/generation_config.py +57 -0
  67. google/genai/_interactions/types/generation_config_param.py +59 -0
  68. google/genai/_interactions/types/google_search_call_arguments.py +29 -0
  69. google/genai/_interactions/types/google_search_call_arguments_param.py +31 -0
  70. google/genai/_interactions/types/google_search_call_content.py +36 -0
  71. google/genai/_interactions/types/google_search_call_content_param.py +36 -0
  72. google/genai/_interactions/types/google_search_result.py +35 -0
  73. google/genai/_interactions/types/google_search_result_content.py +42 -0
  74. google/genai/_interactions/types/google_search_result_content_param.py +43 -0
  75. google/genai/_interactions/types/google_search_result_param.py +35 -0
  76. google/genai/_interactions/types/image_content.py +40 -0
  77. google/genai/_interactions/types/image_content_param.py +47 -0
  78. google/genai/_interactions/types/image_mime_type.py +23 -0
  79. google/genai/_interactions/types/image_mime_type_param.py +25 -0
  80. google/genai/_interactions/types/interaction.py +165 -0
  81. google/genai/_interactions/types/interaction_create_params.py +212 -0
  82. google/genai/_interactions/types/interaction_event.py +37 -0
  83. google/genai/_interactions/types/interaction_get_params.py +46 -0
  84. google/genai/_interactions/types/interaction_sse_event.py +32 -0
  85. google/genai/_interactions/types/interaction_status_update.py +37 -0
  86. google/genai/_interactions/types/mcp_server_tool_call_content.py +41 -0
  87. google/genai/_interactions/types/mcp_server_tool_call_content_param.py +41 -0
  88. google/genai/_interactions/types/mcp_server_tool_result_content.py +51 -0
  89. google/genai/_interactions/types/mcp_server_tool_result_content_param.py +53 -0
  90. google/genai/_interactions/types/model.py +36 -0
  91. google/genai/_interactions/types/model_param.py +38 -0
  92. google/genai/_interactions/types/speech_config.py +35 -0
  93. google/genai/_interactions/types/speech_config_param.py +35 -0
  94. google/genai/_interactions/types/text_content.py +36 -0
  95. google/genai/_interactions/types/text_content_param.py +37 -0
  96. google/genai/_interactions/types/thinking_level.py +22 -0
  97. google/genai/_interactions/types/thought_content.py +40 -0
  98. google/genai/_interactions/types/thought_content_param.py +46 -0
  99. google/genai/_interactions/types/tool.py +100 -0
  100. google/genai/_interactions/types/tool_choice.py +26 -0
  101. google/genai/_interactions/types/tool_choice_config.py +28 -0
  102. google/genai/_interactions/types/tool_choice_config_param.py +29 -0
  103. google/genai/_interactions/types/tool_choice_param.py +28 -0
  104. google/genai/_interactions/types/tool_choice_type.py +22 -0
  105. google/genai/_interactions/types/tool_param.py +97 -0
  106. google/genai/_interactions/types/turn.py +76 -0
  107. google/genai/_interactions/types/turn_param.py +73 -0
  108. google/genai/_interactions/types/url_context_call_arguments.py +29 -0
  109. google/genai/_interactions/types/url_context_call_arguments_param.py +31 -0
  110. google/genai/_interactions/types/url_context_call_content.py +36 -0
  111. google/genai/_interactions/types/url_context_call_content_param.py +36 -0
  112. google/genai/_interactions/types/url_context_result.py +33 -0
  113. google/genai/_interactions/types/url_context_result_content.py +42 -0
  114. google/genai/_interactions/types/url_context_result_content_param.py +43 -0
  115. google/genai/_interactions/types/url_context_result_param.py +32 -0
  116. google/genai/_interactions/types/usage.py +106 -0
  117. google/genai/_interactions/types/usage_param.py +106 -0
  118. google/genai/_interactions/types/video_content.py +40 -0
  119. google/genai/_interactions/types/video_content_param.py +47 -0
  120. google/genai/_interactions/types/video_mime_type.py +36 -0
  121. google/genai/_interactions/types/video_mime_type_param.py +38 -0
  122. google/genai/_live_converters.py +33 -30
  123. google/genai/_tokens_converters.py +5 -0
  124. google/genai/batches.py +7 -0
  125. google/genai/client.py +226 -1
  126. google/genai/interactions.py +17 -0
  127. google/genai/live.py +4 -3
  128. google/genai/models.py +14 -29
  129. google/genai/tunings.py +1 -27
  130. google/genai/types.py +92 -22
  131. google/genai/version.py +1 -1
  132. {google_genai-1.54.0.dist-info → google_genai-1.56.0.dist-info}/METADATA +226 -22
  133. google_genai-1.56.0.dist-info/RECORD +162 -0
  134. google_genai-1.54.0.dist-info/RECORD +0 -41
  135. {google_genai-1.54.0.dist-info → google_genai-1.56.0.dist-info}/WHEEL +0 -0
  136. {google_genai-1.54.0.dist-info → google_genai-1.56.0.dist-info}/licenses/LICENSE +0 -0
  137. {google_genai-1.54.0.dist-info → google_genai-1.56.0.dist-info}/top_level.txt +0 -0
google/genai/types.py CHANGED
@@ -86,11 +86,6 @@ else:
86
86
 
87
87
  if typing.TYPE_CHECKING:
88
88
  import yaml
89
- else:
90
- try:
91
- import yaml
92
- except ImportError:
93
- yaml = None
94
89
 
95
90
  _is_httpx_imported = False
96
91
  if typing.TYPE_CHECKING:
@@ -267,14 +262,18 @@ class PhishBlockThreshold(_common.CaseInSensitiveEnum):
267
262
 
268
263
 
269
264
  class ThinkingLevel(_common.CaseInSensitiveEnum):
270
- """The level of thoughts tokens that the model should generate."""
265
+ """The number of thoughts tokens that the model should generate."""
271
266
 
272
267
  THINKING_LEVEL_UNSPECIFIED = 'THINKING_LEVEL_UNSPECIFIED'
273
- """Default value."""
268
+ """Unspecified thinking level."""
274
269
  LOW = 'LOW'
275
270
  """Low thinking level."""
271
+ MEDIUM = 'MEDIUM'
272
+ """Medium thinking level."""
276
273
  HIGH = 'HIGH'
277
274
  """High thinking level."""
275
+ MINIMAL = 'MINIMAL'
276
+ """MINIMAL thinking level."""
278
277
 
279
278
 
280
279
  class HarmCategory(_common.CaseInSensitiveEnum):
@@ -376,6 +375,10 @@ class FinishReason(_common.CaseInSensitiveEnum):
376
375
  """Image generation stopped because the generated images have prohibited content."""
377
376
  NO_IMAGE = 'NO_IMAGE'
378
377
  """The model was expected to generate an image, but none was generated."""
378
+ IMAGE_RECITATION = 'IMAGE_RECITATION'
379
+ """Image generation stopped because the generated image may be a recitation from a source."""
380
+ IMAGE_OTHER = 'IMAGE_OTHER'
381
+ """Image generation stopped for a reason not otherwise specified."""
379
382
 
380
383
 
381
384
  class HarmProbability(_common.CaseInSensitiveEnum):
@@ -573,6 +576,8 @@ class PartMediaResolutionLevel(_common.CaseInSensitiveEnum):
573
576
  """Media resolution set to medium."""
574
577
  MEDIA_RESOLUTION_HIGH = 'MEDIA_RESOLUTION_HIGH'
575
578
  """Media resolution set to high."""
579
+ MEDIA_RESOLUTION_ULTRA_HIGH = 'MEDIA_RESOLUTION_ULTRA_HIGH'
580
+ """Media resolution set to ultra high."""
576
581
 
577
582
 
578
583
  class ResourceScope(_common.CaseInSensitiveEnum):
@@ -857,6 +862,17 @@ class MediaModality(_common.CaseInSensitiveEnum):
857
862
  """Document, e.g. PDF."""
858
863
 
859
864
 
865
+ class VadSignalType(_common.CaseInSensitiveEnum):
866
+ """The type of the VAD signal."""
867
+
868
+ VAD_SIGNAL_TYPE_UNSPECIFIED = 'VAD_SIGNAL_TYPE_UNSPECIFIED'
869
+ """The default is VAD_SIGNAL_TYPE_UNSPECIFIED."""
870
+ VAD_SIGNAL_TYPE_SOS = 'VAD_SIGNAL_TYPE_SOS'
871
+ """Start of sentence signal."""
872
+ VAD_SIGNAL_TYPE_EOS = 'VAD_SIGNAL_TYPE_EOS'
873
+ """End of sentence signal."""
874
+
875
+
860
876
  class StartSensitivity(_common.CaseInSensitiveEnum):
861
877
  """Start of speech sensitivity."""
862
878
 
@@ -4469,24 +4485,19 @@ SpeakerVoiceConfigOrDict = Union[SpeakerVoiceConfig, SpeakerVoiceConfigDict]
4469
4485
 
4470
4486
 
4471
4487
  class MultiSpeakerVoiceConfig(_common.BaseModel):
4472
- """The configuration for the multi-speaker setup.
4473
-
4474
- This data type is not supported in Vertex AI.
4475
- """
4488
+ """Configuration for a multi-speaker text-to-speech request."""
4476
4489
 
4477
4490
  speaker_voice_configs: Optional[list[SpeakerVoiceConfig]] = Field(
4478
- default=None, description="""Required. All the enabled speaker voices."""
4491
+ default=None,
4492
+ description="""Required. A list of configurations for the voices of the speakers. Exactly two speaker voice configurations must be provided.""",
4479
4493
  )
4480
4494
 
4481
4495
 
4482
4496
  class MultiSpeakerVoiceConfigDict(TypedDict, total=False):
4483
- """The configuration for the multi-speaker setup.
4484
-
4485
- This data type is not supported in Vertex AI.
4486
- """
4497
+ """Configuration for a multi-speaker text-to-speech request."""
4487
4498
 
4488
4499
  speaker_voice_configs: Optional[list[SpeakerVoiceConfigDict]]
4489
- """Required. All the enabled speaker voices."""
4500
+ """Required. A list of configurations for the voices of the speakers. Exactly two speaker voice configurations must be provided."""
4490
4501
 
4491
4502
 
4492
4503
  MultiSpeakerVoiceConfigOrDict = Union[
@@ -4506,7 +4517,7 @@ class SpeechConfig(_common.BaseModel):
4506
4517
  )
4507
4518
  multi_speaker_voice_config: Optional[MultiSpeakerVoiceConfig] = Field(
4508
4519
  default=None,
4509
- description="""Optional. The configuration for the multi-speaker setup. It is mutually exclusive with the voice_config field. This field is not supported in Vertex AI.""",
4520
+ description="""The configuration for a multi-speaker text-to-speech request. This field is mutually exclusive with `voice_config`.""",
4510
4521
  )
4511
4522
 
4512
4523
 
@@ -4519,7 +4530,7 @@ class SpeechConfigDict(TypedDict, total=False):
4519
4530
  """Optional. Language code (ISO 639. e.g. en-US) for the speech synthesization."""
4520
4531
 
4521
4532
  multi_speaker_voice_config: Optional[MultiSpeakerVoiceConfigDict]
4522
- """Optional. The configuration for the multi-speaker setup. It is mutually exclusive with the voice_config field. This field is not supported in Vertex AI."""
4533
+ """The configuration for a multi-speaker text-to-speech request. This field is mutually exclusive with `voice_config`."""
4523
4534
 
4524
4535
 
4525
4536
  SpeechConfigOrDict = Union[SpeechConfig, SpeechConfigDict]
@@ -4599,7 +4610,7 @@ class ThinkingConfig(_common.BaseModel):
4599
4610
  )
4600
4611
  thinking_level: Optional[ThinkingLevel] = Field(
4601
4612
  default=None,
4602
- description="""Optional. The level of thoughts tokens that the model should generate.""",
4613
+ description="""Optional. The number of thoughts tokens that the model should generate.""",
4603
4614
  )
4604
4615
 
4605
4616
 
@@ -4615,7 +4626,7 @@ class ThinkingConfigDict(TypedDict, total=False):
4615
4626
  """
4616
4627
 
4617
4628
  thinking_level: Optional[ThinkingLevel]
4618
- """Optional. The level of thoughts tokens that the model should generate."""
4629
+ """Optional. The number of thoughts tokens that the model should generate."""
4619
4630
 
4620
4631
 
4621
4632
  ThinkingConfigOrDict = Union[ThinkingConfig, ThinkingConfigDict]
@@ -5165,6 +5176,12 @@ class GenerateContentConfig(_common.BaseModel):
5165
5176
  description="""The image generation configuration.
5166
5177
  """,
5167
5178
  )
5179
+ enable_enhanced_civic_answers: Optional[bool] = Field(
5180
+ default=None,
5181
+ description="""Enables enhanced civic answers. It may not be available for all
5182
+ models. This field is not supported in Vertex AI.
5183
+ """,
5184
+ )
5168
5185
 
5169
5186
  @pydantic.field_validator('response_schema', mode='before')
5170
5187
  @classmethod
@@ -5370,6 +5387,11 @@ class GenerateContentConfigDict(TypedDict, total=False):
5370
5387
  """The image generation configuration.
5371
5388
  """
5372
5389
 
5390
+ enable_enhanced_civic_answers: Optional[bool]
5391
+ """Enables enhanced civic answers. It may not be available for all
5392
+ models. This field is not supported in Vertex AI.
5393
+ """
5394
+
5373
5395
 
5374
5396
  GenerateContentConfigOrDict = Union[
5375
5397
  GenerateContentConfig, GenerateContentConfigDict
@@ -10619,7 +10641,9 @@ class Metric(_common.BaseModel):
10619
10641
  Raises:
10620
10642
  ImportError: If the pyyaml library is not installed.
10621
10643
  """
10622
- if yaml is None:
10644
+ try:
10645
+ import yaml
10646
+ except ImportError:
10623
10647
  raise ImportError(
10624
10648
  'YAML serialization requires the pyyaml library. Please install'
10625
10649
  " it using 'pip install google-cloud-aiplatform[evaluation]'."
@@ -16218,6 +16242,24 @@ LiveServerSessionResumptionUpdateOrDict = Union[
16218
16242
  ]
16219
16243
 
16220
16244
 
16245
+ class VoiceActivityDetectionSignal(_common.BaseModel):
16246
+
16247
+ vad_signal_type: Optional[VadSignalType] = Field(
16248
+ default=None, description="""The type of the VAD signal."""
16249
+ )
16250
+
16251
+
16252
+ class VoiceActivityDetectionSignalDict(TypedDict, total=False):
16253
+
16254
+ vad_signal_type: Optional[VadSignalType]
16255
+ """The type of the VAD signal."""
16256
+
16257
+
16258
+ VoiceActivityDetectionSignalOrDict = Union[
16259
+ VoiceActivityDetectionSignal, VoiceActivityDetectionSignalDict
16260
+ ]
16261
+
16262
+
16221
16263
  class LiveServerMessage(_common.BaseModel):
16222
16264
  """Response message for API call."""
16223
16265
 
@@ -16249,6 +16291,9 @@ class LiveServerMessage(_common.BaseModel):
16249
16291
  description="""Update of the session resumption state.""",
16250
16292
  )
16251
16293
  )
16294
+ voice_activity_detection_signal: Optional[VoiceActivityDetectionSignal] = (
16295
+ Field(default=None, description="""Voice activity detection signal.""")
16296
+ )
16252
16297
 
16253
16298
  @property
16254
16299
  def text(self) -> Optional[str]:
@@ -16345,6 +16390,9 @@ class LiveServerMessageDict(TypedDict, total=False):
16345
16390
  session_resumption_update: Optional[LiveServerSessionResumptionUpdateDict]
16346
16391
  """Update of the session resumption state."""
16347
16392
 
16393
+ voice_activity_detection_signal: Optional[VoiceActivityDetectionSignalDict]
16394
+ """Voice activity detection signal."""
16395
+
16348
16396
 
16349
16397
  LiveServerMessageOrDict = Union[LiveServerMessage, LiveServerMessageDict]
16350
16398
 
@@ -16634,6 +16682,12 @@ class LiveClientSetup(_common.BaseModel):
16634
16682
  description="""Configures the proactivity of the model. This allows the model to respond proactively to
16635
16683
  the input and to ignore irrelevant input.""",
16636
16684
  )
16685
+ explicit_vad_signal: Optional[bool] = Field(
16686
+ default=None,
16687
+ description="""Configures the explicit VAD signal. If enabled, the client will send
16688
+ vad_signal to indicate the start and end of speech. This allows the server
16689
+ to process the audio more efficiently.""",
16690
+ )
16637
16691
 
16638
16692
 
16639
16693
  class LiveClientSetupDict(TypedDict, total=False):
@@ -16685,6 +16739,11 @@ class LiveClientSetupDict(TypedDict, total=False):
16685
16739
  """Configures the proactivity of the model. This allows the model to respond proactively to
16686
16740
  the input and to ignore irrelevant input."""
16687
16741
 
16742
+ explicit_vad_signal: Optional[bool]
16743
+ """Configures the explicit VAD signal. If enabled, the client will send
16744
+ vad_signal to indicate the start and end of speech. This allows the server
16745
+ to process the audio more efficiently."""
16746
+
16688
16747
 
16689
16748
  LiveClientSetupOrDict = Union[LiveClientSetup, LiveClientSetupDict]
16690
16749
 
@@ -17169,6 +17228,12 @@ If included the server will send SessionResumptionUpdate messages.""",
17169
17228
  description="""Configures the proactivity of the model. This allows the model to respond proactively to
17170
17229
  the input and to ignore irrelevant input.""",
17171
17230
  )
17231
+ explicit_vad_signal: Optional[bool] = Field(
17232
+ default=None,
17233
+ description="""Configures the explicit VAD signal. If enabled, the client will send
17234
+ vad_signal to indicate the start and end of speech. This allows the server
17235
+ to process the audio more efficiently.""",
17236
+ )
17172
17237
 
17173
17238
 
17174
17239
  class LiveConnectConfigDict(TypedDict, total=False):
@@ -17271,6 +17336,11 @@ If included the server will send SessionResumptionUpdate messages."""
17271
17336
  """Configures the proactivity of the model. This allows the model to respond proactively to
17272
17337
  the input and to ignore irrelevant input."""
17273
17338
 
17339
+ explicit_vad_signal: Optional[bool]
17340
+ """Configures the explicit VAD signal. If enabled, the client will send
17341
+ vad_signal to indicate the start and end of speech. This allows the server
17342
+ to process the audio more efficiently."""
17343
+
17274
17344
 
17275
17345
  LiveConnectConfigOrDict = Union[LiveConnectConfig, LiveConnectConfigDict]
17276
17346
 
google/genai/version.py CHANGED
@@ -13,4 +13,4 @@
13
13
  # limitations under the License.
14
14
  #
15
15
 
16
- __version__ = '1.54.0' # x-release-please-version
16
+ __version__ = '1.56.0' # x-release-please-version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-genai
3
- Version: 1.54.0
3
+ Version: 1.56.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License-Expression: Apache-2.0
@@ -20,13 +20,15 @@ Requires-Python: >=3.10
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: anyio<5.0.0,>=4.8.0
23
- Requires-Dist: google-auth[requests]<3.0.0,>=2.14.1
23
+ Requires-Dist: google-auth[requests]<3.0.0,>=2.45.0
24
24
  Requires-Dist: httpx<1.0.0,>=0.28.1
25
25
  Requires-Dist: pydantic<3.0.0,>=2.9.0
26
26
  Requires-Dist: requests<3.0.0,>=2.28.1
27
27
  Requires-Dist: tenacity<9.2.0,>=8.2.3
28
28
  Requires-Dist: websockets<15.1.0,>=13.0.0
29
29
  Requires-Dist: typing-extensions<5.0.0,>=4.11.0
30
+ Requires-Dist: distro<2,>=1.7.0
31
+ Requires-Dist: sniffio
30
32
  Provides-Extra: aiohttp
31
33
  Requires-Dist: aiohttp<3.13.3; extra == "aiohttp"
32
34
  Provides-Extra: local-tokenizer
@@ -55,11 +57,7 @@ APIs.
55
57
 
56
58
  Generative models are often unaware of recent API and SDK updates and may suggest outdated or legacy code.
57
59
 
58
- We recommend using our Code Generation instructions [codegen_instructions.md](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features.
59
-
60
- Copy and paste the instructions from [this file](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md)
61
- into your development environment to provide the model with the necessary
62
- context
60
+ We recommend using our Code Generation instructions [`codegen_instructions.md`](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features. Copy and paste the instructions into your development environment to provide the model with the necessary context.
63
61
 
64
62
  ## Installation
65
63
 
@@ -172,7 +170,7 @@ client = genai.Client()
172
170
  ## Close a client
173
171
 
174
172
  Explicitly close the sync client to ensure that resources, such as the
175
- underlying HTTP connections, are properly cleaned up and closed.
173
+ underlying HTTP connections, are properly cleaned up and closed.
176
174
 
177
175
  ```python
178
176
  from google.genai import Client
@@ -213,7 +211,7 @@ await aclient.aclose()
213
211
  ## Client context managers
214
212
 
215
213
  By using the sync client context manager, it will close the underlying
216
- sync client when exiting the with block and avoid httpx "client has been closed" error like [issues#1763](https://github.com/googleapis/python-genai/issues/1763).
214
+ sync client when exiting the with block and avoid httpx "client has been closed" error like [issues#1763](https://github.com/googleapis/python-genai/issues/1763).
217
215
 
218
216
  ```python
219
217
  from google.genai import Client
@@ -284,7 +282,7 @@ client = genai.Client(
284
282
  By default we use httpx for both sync and async client implementations. In order
285
283
  to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
286
284
  SDK we configure `trust_env=True` to match with the default behavior of httpx.
287
- Additional args of `aiohttp.ClientSession.request()` ([see _RequestOptions args](https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170)) can be passed
285
+ Additional args of `aiohttp.ClientSession.request()` ([see `_RequestOptions` args](https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170)) can be passed
288
286
  through the following way:
289
287
 
290
288
  ```python
@@ -299,7 +297,7 @@ client=Client(..., http_options=http_options)
299
297
 
300
298
  Both httpx and aiohttp libraries use `urllib.request.getproxies` from
301
299
  environment variables. Before client initialization, you may set proxy (and
302
- optional SSL_CERT_FILE) by setting the environment variables:
300
+ optional `SSL_CERT_FILE`) by setting the environment variables:
303
301
 
304
302
  ```bash
305
303
  export HTTPS_PROXY='http://username:password@proxy_uri:port'
@@ -322,7 +320,7 @@ client=Client(..., http_options=http_options)
322
320
  ### Custom base url
323
321
 
324
322
  In some cases you might need a custom base url (for example, API gateway proxy
325
- server) and bypass some authentication checks for project, location, or API key.
323
+ server) and bypass some authentication checks for project, location, or API key.
326
324
  You may pass the custom base url like this:
327
325
 
328
326
  ```python
@@ -381,7 +379,8 @@ for part in response.parts:
381
379
  ```
382
380
 
383
381
  #### with uploaded file (Gemini Developer API only)
384
- download the file in console.
382
+
383
+ Download the file in console.
385
384
 
386
385
  ```sh
387
386
  !wget -q https://storage.googleapis.com/generativeai-downloads/data/a11.txt
@@ -399,11 +398,13 @@ print(response.text)
399
398
  ```
400
399
 
401
400
  #### How to structure `contents` argument for `generate_content`
401
+
402
402
  The SDK always converts the inputs to the `contents` argument into
403
403
  `list[types.Content]`.
404
404
  The following shows some common ways to provide your inputs.
405
405
 
406
406
  ##### Provide a `list[types.Content]`
407
+
407
408
  This is the canonical way to provide contents, SDK will not do any conversion.
408
409
 
409
410
  ##### Provide a `types.Content` instance
@@ -449,7 +450,7 @@ The SDK will assume this is a text part, and it converts this into the following
449
450
  Where a `types.UserContent` is a subclass of `types.Content`, it sets the
450
451
  `role` field to be `user`.
451
452
 
452
- ##### Provide a list of string
453
+ ##### Provide a list of strings
453
454
 
454
455
  ```python
455
456
  contents=['Why is the sky blue?', 'Why is the cloud white?']
@@ -518,7 +519,7 @@ contents = [
518
519
  ]
519
520
  ```
520
521
 
521
- The SDK converts a list of function call parts to the a content with a `model` role:
522
+ The SDK converts a list of function call parts to a content with a `model` role:
522
523
 
523
524
  ```python
524
525
  [
@@ -710,7 +711,9 @@ response = client.models.generate_content(
710
711
 
711
712
  print(response.text)
712
713
  ```
714
+
713
715
  #### Disabling automatic function calling
716
+
714
717
  If you pass in a python function as a tool directly, and do not want
715
718
  automatic function calling, you can disable automatic function calling
716
719
  as follows:
@@ -942,7 +945,9 @@ including by giving examples of expected JSON output. If you do, the generated
942
945
  output might be lower in quality.
943
946
 
944
947
  #### JSON Schema support
948
+
945
949
  Schemas can be provided as standard JSON schema.
950
+
946
951
  ```python
947
952
  user_profile = {
948
953
  'properties': {
@@ -1069,7 +1074,7 @@ print(response.text)
1069
1074
 
1070
1075
  #### JSON Response
1071
1076
 
1072
- You can also set response_mime_type to 'application/json', the response will be
1077
+ You can also set `response_mime_type` to `'application/json'`, the response will be
1073
1078
  identical but in quotes.
1074
1079
 
1075
1080
  ```python
@@ -1559,6 +1564,205 @@ response = client.models.generate_content(
1559
1564
  print(response.text)
1560
1565
  ```
1561
1566
 
1567
+ ## Interactions (Preview)
1568
+
1569
+ > **Warning:** The Interactions API is in **Beta**. This is a preview of an experimental feature. Features and schemas are subject to **breaking changes**.
1570
+
1571
+ The Interactions API is a unified interface for interacting with Gemini models and agents. It simplifies state management, tool orchestration, and long-running tasks.
1572
+
1573
+ See the [documentation site](https://ai.google.dev/gemini-api/docs/interactions) for more details.
1574
+
1575
+ ### Basic Interaction
1576
+
1577
+ ```python
1578
+ interaction = client.interactions.create(
1579
+ model='gemini-2.5-flash',
1580
+ input='Tell me a short joke about programming.'
1581
+ )
1582
+ print(interaction.outputs[-1].text)
1583
+
1584
+ ```
1585
+
1586
+ ### Stateful Conversation
1587
+
1588
+ The Interactions API supports server-side state management. You can continue a conversation by referencing the `previous_interaction_id`.
1589
+
1590
+ ```python
1591
+ # 1. First turn
1592
+ interaction1 = client.interactions.create(
1593
+ model='gemini-2.5-flash',
1594
+ input='Hi, my name is Amir.'
1595
+ )
1596
+ print(f"Model: {interaction1.outputs[-1].text}")
1597
+
1598
+ # 2. Second turn (passing previous_interaction_id)
1599
+ interaction2 = client.interactions.create(
1600
+ model='gemini-2.5-flash',
1601
+ input='What is my name?',
1602
+ previous_interaction_id=interaction1.id
1603
+ )
1604
+ print(f"Model: {interaction2.outputs[-1].text}")
1605
+
1606
+ ```
1607
+
1608
+ ### Agents (Deep Research)
1609
+
1610
+ You can use specialized agents like `deep-research-pro-preview-12-2025` for complex tasks.
1611
+
1612
+ ```python
1613
+ import time
1614
+
1615
+ # 1. Start the Deep Research Agent
1616
+ initial_interaction = client.interactions.create(
1617
+ input='Research the history of the Google TPUs with a focus on 2025 and 2026.',
1618
+ agent='deep-research-pro-preview-12-2025',
1619
+ background=True
1620
+ )
1621
+ print(f"Research started. Interaction ID: {initial_interaction.id}")
1622
+
1623
+ # 2. Poll for results
1624
+ while True:
1625
+ interaction = client.interactions.get(id=initial_interaction.id)
1626
+ print(f"Status: {interaction.status}")
1627
+
1628
+ if interaction.status == "completed":
1629
+ print("\nFinal Report:\n", interaction.outputs[-1].text)
1630
+ break
1631
+ elif interaction.status in ["failed", "cancelled"]:
1632
+ print(f"Failed with status: {interaction.status}")
1633
+ break
1634
+
1635
+ time.sleep(10)
1636
+
1637
+ ```
1638
+
1639
+ ### Multimodal Input
1640
+
1641
+ You can provide multimodal data (text, images, audio, etc.) in the input list.
1642
+
1643
+ ```python
1644
+ import base64
1645
+
1646
+ # Assuming you have an image loaded as bytes
1647
+ # base64_image = ...
1648
+
1649
+ interaction = client.interactions.create(
1650
+ model='gemini-2.5-flash',
1651
+ input=[
1652
+ {'type': 'text', 'text': 'Describe the image.'},
1653
+ {'type': 'image', 'data': base64_image, 'mime_type': 'image/png'}
1654
+ ]
1655
+ )
1656
+ print(interaction.outputs[-1].text)
1657
+
1658
+ ```
1659
+
1660
+ ### Function Calling
1661
+
1662
+ You can define custom functions for the model to use. The Interactions API handles the tool selection, and you provide the execution result back to the model.
1663
+
1664
+ ```python
1665
+ # 1. Define the tool
1666
+ def get_weather(location: str):
1667
+ """Gets the weather for a given location."""
1668
+ return f"The weather in {location} is sunny."
1669
+
1670
+ weather_tool = {
1671
+ 'type': 'function',
1672
+ 'name': 'get_weather',
1673
+ 'description': 'Gets the weather for a given location.',
1674
+ 'parameters': {
1675
+ 'type': 'object',
1676
+ 'properties': {
1677
+ 'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}
1678
+ },
1679
+ 'required': ['location']
1680
+ }
1681
+ }
1682
+
1683
+ # 2. Send the request with tools
1684
+ interaction = client.interactions.create(
1685
+ model='gemini-2.5-flash',
1686
+ input='What is the weather in Mountain View, CA?',
1687
+ tools=[weather_tool]
1688
+ )
1689
+
1690
+ # 3. Handle the tool call
1691
+ for output in interaction.outputs:
1692
+ if output.type == 'function_call':
1693
+ print(f"Tool Call: {output.name}({output.arguments})")
1694
+
1695
+ # Execute your actual function here
1696
+ result = get_weather(**output.arguments)
1697
+
1698
+ # Send result back to the model
1699
+ interaction = client.interactions.create(
1700
+ model='gemini-2.5-flash',
1701
+ previous_interaction_id=interaction.id,
1702
+ input=[{
1703
+ 'type': 'function_result',
1704
+ 'name': output.name,
1705
+ 'call_id': output.id,
1706
+ 'result': result
1707
+ }]
1708
+ )
1709
+ print(f"Response: {interaction.outputs[-1].text}")
1710
+
1711
+ ```
1712
+
1713
+ ### Built-in Tools
1714
+ You can also use Google's built-in tools, such as **Google Search** or **Code Execution**.
1715
+
1716
+ #### Grounding with Google Search
1717
+
1718
+ ```python
1719
+ interaction = client.interactions.create(
1720
+ model='gemini-2.5-flash',
1721
+ input='Who won the last Super Bowl?',
1722
+ tools=[{'type': 'google_search'}]
1723
+ )
1724
+
1725
+ # Find the text output (not the GoogleSearchResultContent)
1726
+ text_output = next((o for o in interaction.outputs if o.type == 'text'), None)
1727
+ if text_output:
1728
+ print(text_output.text)
1729
+
1730
+ ```
1731
+
1732
+ #### Code Execution
1733
+
1734
+ ```python
1735
+ interaction = client.interactions.create(
1736
+ model='gemini-2.5-flash',
1737
+ input='Calculate the 50th Fibonacci number.',
1738
+ tools=[{'type': 'code_execution'}]
1739
+ )
1740
+ print(interaction.outputs[-1].text)
1741
+
1742
+ ```
1743
+
1744
+ ### Multimodal Output
1745
+
1746
+ The Interactions API can generate multimodal outputs, such as images. You must specify the `response_modalities`.
1747
+
1748
+ ```python
1749
+ import base64
1750
+
1751
+ interaction = client.interactions.create(
1752
+ model='gemini-3-pro-image-preview',
1753
+ input='Generate an image of a futuristic city.',
1754
+ response_modalities=['IMAGE']
1755
+ )
1756
+
1757
+ for output in interaction.outputs:
1758
+ if output.type == 'image':
1759
+ print(f"Generated image with mime_type: {output.mime_type}")
1760
+ # Save the image
1761
+ with open("generated_city.png", "wb") as f:
1762
+ f.write(base64.b64decode(output.data))
1763
+
1764
+ ```
1765
+
1562
1766
  ## Tunings
1563
1767
 
1564
1768
  `client.tunings` contains tuning job APIs and supports supervised fine
@@ -1754,13 +1958,14 @@ job
1754
1958
  ```
1755
1959
 
1756
1960
  In order to create a batch job with file name. Need to upload a json file.
1757
- For example myrequests.json:
1961
+ For example `myrequests.json`:
1758
1962
 
1759
- ```
1963
+ ```json
1760
1964
  {"key":"request_1", "request": {"contents": [{"parts": [{"text":
1761
1965
  "Explain how AI works in a few words"}]}], "generation_config": {"response_modalities": ["TEXT"]}}}
1762
1966
  {"key":"request_2", "request": {"contents": [{"parts": [{"text": "Explain how Crypto works in a few words"}]}]}}
1763
1967
  ```
1968
+
1764
1969
  Then upload the file.
1765
1970
 
1766
1971
  ```python
@@ -1777,7 +1982,6 @@ batch_job = client.batches.create(
1777
1982
  )
1778
1983
  ```
1779
1984
 
1780
-
1781
1985
  ```python
1782
1986
  # Get a job by name
1783
1987
  job = client.batches.get(name=job.name)
@@ -1848,7 +2052,7 @@ delete_job
1848
2052
 
1849
2053
  ## Error Handling
1850
2054
 
1851
- To handle errors raised by the model service, the SDK provides this [APIError](https://github.com/googleapis/python-genai/blob/main/google/genai/errors.py) class.
2055
+ To handle errors raised by the model service, the SDK provides this [`APIError`](https://github.com/googleapis/python-genai/blob/main/google/genai/errors.py) class.
1852
2056
 
1853
2057
  ```python
1854
2058
  from google.genai import errors
@@ -1870,8 +2074,8 @@ properties to include in the request body. This can be used to access new or
1870
2074
  experimental backend features that are not yet formally supported in the SDK.
1871
2075
  The structure of the dictionary must match the backend API's request structure.
1872
2076
 
1873
- - VertexAI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
1874
- - GeminiAPI backend API docs: https://ai.google.dev/api/rest
2077
+ - Vertex AI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
2078
+ - Gemini API backend API docs: https://ai.google.dev/api/rest
1875
2079
 
1876
2080
  ```python
1877
2081
  response = client.models.generate_content(