google-genai 1.24.0__tar.gz → 1.25.0__tar.gz

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 (41) hide show
  1. {google_genai-1.24.0/google_genai.egg-info → google_genai-1.25.0}/PKG-INFO +27 -3
  2. {google_genai-1.24.0 → google_genai-1.25.0}/README.md +26 -2
  3. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_api_client.py +11 -1
  4. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_common.py +6 -4
  5. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_replay_api_client.py +15 -8
  6. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_transformers.py +12 -6
  7. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/errors.py +2 -2
  8. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/live.py +14 -5
  9. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/tokens.py +8 -4
  10. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/types.py +17 -0
  11. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/version.py +1 -1
  12. {google_genai-1.24.0 → google_genai-1.25.0/google_genai.egg-info}/PKG-INFO +27 -3
  13. {google_genai-1.24.0 → google_genai-1.25.0}/pyproject.toml +1 -1
  14. {google_genai-1.24.0 → google_genai-1.25.0}/LICENSE +0 -0
  15. {google_genai-1.24.0 → google_genai-1.25.0}/MANIFEST.in +0 -0
  16. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/__init__.py +0 -0
  17. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_adapters.py +0 -0
  18. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_api_module.py +0 -0
  19. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_automatic_function_calling_util.py +0 -0
  20. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_base_url.py +0 -0
  21. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_extra_utils.py +0 -0
  22. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_live_converters.py +0 -0
  23. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_mcp_utils.py +0 -0
  24. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_test_api_client.py +0 -0
  25. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/_tokens_converters.py +0 -0
  26. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/batches.py +0 -0
  27. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/caches.py +0 -0
  28. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/chats.py +0 -0
  29. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/client.py +0 -0
  30. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/files.py +0 -0
  31. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/live_music.py +0 -0
  32. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/models.py +0 -0
  33. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/operations.py +0 -0
  34. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/pagers.py +0 -0
  35. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/py.typed +0 -0
  36. {google_genai-1.24.0 → google_genai-1.25.0}/google/genai/tunings.py +0 -0
  37. {google_genai-1.24.0 → google_genai-1.25.0}/google_genai.egg-info/SOURCES.txt +0 -0
  38. {google_genai-1.24.0 → google_genai-1.25.0}/google_genai.egg-info/dependency_links.txt +0 -0
  39. {google_genai-1.24.0 → google_genai-1.25.0}/google_genai.egg-info/requires.txt +0 -0
  40. {google_genai-1.24.0 → google_genai-1.25.0}/google_genai.egg-info/top_level.txt +0 -0
  41. {google_genai-1.24.0 → google_genai-1.25.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-genai
3
- Version: 1.24.0
3
+ Version: 1.25.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License: Apache-2.0
@@ -89,10 +89,13 @@ You can create a client by configuring the necessary environment variables.
89
89
  Configuration setup instructions depends on whether you're using the Gemini
90
90
  Developer API or the Gemini API in Vertex AI.
91
91
 
92
- **Gemini Developer API:** Set `GOOGLE_API_KEY` as shown below:
92
+ **Gemini Developer API:** Set the `GEMINI_API_KEY` or `GOOGLE_API_KEY`.
93
+ It will automatically be picked up by the client. It's recommended that you
94
+ set only one of those variables, but if both are set, `GOOGLE_API_KEY` takes
95
+ precedence.
93
96
 
94
97
  ```bash
95
- export GOOGLE_API_KEY='your-api-key'
98
+ export GEMINI_API_KEY='your-api-key'
96
99
  ```
97
100
 
98
101
  **Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`,
@@ -1633,3 +1636,24 @@ except errors.APIError as e:
1633
1636
  print(e.code) # 404
1634
1637
  print(e.message)
1635
1638
  ```
1639
+
1640
+ ## Extra Request Body
1641
+
1642
+ The `extra_body` field in `HttpOptions` accepts a dictionary of additional JSON
1643
+ properties to include in the request body. This can be used to access new or
1644
+ experimental backend features that are not yet formally supported in the SDK.
1645
+ The structure of the dictionary must match the backend API's request structure.
1646
+
1647
+ - VertexAI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
1648
+ - GeminiAPI backend API docs: https://ai.google.dev/api/rest
1649
+
1650
+ ```python
1651
+ response = client.models.generate_content(
1652
+ model="gemini-2.5-pro",
1653
+ contents="What is the weather in Boston? and how about Sunnyvale?",
1654
+ config=types.GenerateContentConfig(
1655
+ tools=[get_current_weather],
1656
+ http_options=types.HttpOptions(extra_body={'tool_config': {'function_calling_config': {'mode': 'COMPOSITIONAL'}}}),
1657
+ ),
1658
+ )
1659
+ ```
@@ -55,10 +55,13 @@ You can create a client by configuring the necessary environment variables.
55
55
  Configuration setup instructions depends on whether you're using the Gemini
56
56
  Developer API or the Gemini API in Vertex AI.
57
57
 
58
- **Gemini Developer API:** Set `GOOGLE_API_KEY` as shown below:
58
+ **Gemini Developer API:** Set the `GEMINI_API_KEY` or `GOOGLE_API_KEY`.
59
+ It will automatically be picked up by the client. It's recommended that you
60
+ set only one of those variables, but if both are set, `GOOGLE_API_KEY` takes
61
+ precedence.
59
62
 
60
63
  ```bash
61
- export GOOGLE_API_KEY='your-api-key'
64
+ export GEMINI_API_KEY='your-api-key'
62
65
  ```
63
66
 
64
67
  **Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`,
@@ -1599,3 +1602,24 @@ except errors.APIError as e:
1599
1602
  print(e.code) # 404
1600
1603
  print(e.message)
1601
1604
  ```
1605
+
1606
+ ## Extra Request Body
1607
+
1608
+ The `extra_body` field in `HttpOptions` accepts a dictionary of additional JSON
1609
+ properties to include in the request body. This can be used to access new or
1610
+ experimental backend features that are not yet formally supported in the SDK.
1611
+ The structure of the dictionary must match the backend API's request structure.
1612
+
1613
+ - VertexAI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
1614
+ - GeminiAPI backend API docs: https://ai.google.dev/api/rest
1615
+
1616
+ ```python
1617
+ response = client.models.generate_content(
1618
+ model="gemini-2.5-pro",
1619
+ contents="What is the weather in Boston? and how about Sunnyvale?",
1620
+ config=types.GenerateContentConfig(
1621
+ tools=[get_current_weather],
1622
+ http_options=types.HttpOptions(extra_body={'tool_config': {'function_calling_config': {'mode': 'COMPOSITIONAL'}}}),
1623
+ ),
1624
+ )
1625
+ ```
@@ -232,8 +232,18 @@ class HttpResponse:
232
232
  byte_stream: Union[Any, bytes] = None,
233
233
  session: Optional['aiohttp.ClientSession'] = None,
234
234
  ):
235
+ if isinstance(headers, dict):
236
+ self.headers = headers
237
+ elif isinstance(headers, httpx.Headers):
238
+ self.headers = {
239
+ key: ', '.join(headers.get_list(key))
240
+ for key in headers.keys()}
241
+ elif type(headers).__name__ == 'CIMultiDictProxy':
242
+ self.headers = {
243
+ key: ', '.join(headers.getall(key))
244
+ for key in headers.keys()}
245
+
235
246
  self.status_code: int = 200
236
- self.headers = headers
237
247
  self.response_stream = response_stream
238
248
  self.byte_stream = byte_stream
239
249
  self._session = session
@@ -29,11 +29,13 @@ import warnings
29
29
  import pydantic
30
30
  from pydantic import alias_generators
31
31
 
32
- from . import _api_client
33
- from . import errors
34
-
35
32
  logger = logging.getLogger('google_genai._common')
36
33
 
34
+
35
+ class ExperimentalWarning(Warning):
36
+ """Warning for experimental features."""
37
+
38
+
37
39
  def set_value_by_path(data: Optional[dict[Any, Any]], keys: list[str], value: Any) -> None:
38
40
  """Examples:
39
41
 
@@ -540,7 +542,7 @@ def experimental_warning(message: str) -> Callable[[Callable[..., Any]], Callabl
540
542
  warning_done = True
541
543
  warnings.warn(
542
544
  message=message,
543
- category=errors.ExperimentalWarning,
545
+ category=ExperimentalWarning,
544
546
  stacklevel=2,
545
547
  )
546
548
  return func(*args, **kwargs)
@@ -200,6 +200,12 @@ def _debug_print(message: str) -> None:
200
200
  )
201
201
 
202
202
 
203
+ def pop_undeterministic_headers(headers: dict[str, str]) -> None:
204
+ """Remove headers that are not deterministic."""
205
+ headers.pop('Date', None) # pytype: disable=attribute-error
206
+ headers.pop('Server-Timing', None) # pytype: disable=attribute-error
207
+
208
+
203
209
  class ReplayRequest(BaseModel):
204
210
  """Represents a single request in a replay."""
205
211
 
@@ -219,10 +225,7 @@ class ReplayResponse(BaseModel):
219
225
  sdk_response_segments: list[dict[str, object]]
220
226
 
221
227
  def model_post_init(self, __context: Any) -> None:
222
- # Remove headers that are not deterministic so the replay files don't change
223
- # every time they are recorded.
224
- self.headers.pop('Date', None)
225
- self.headers.pop('Server-Timing', None)
228
+ pop_undeterministic_headers(self.headers)
226
229
 
227
230
 
228
231
  class ReplayInteraction(BaseModel):
@@ -447,11 +450,15 @@ class ReplayApiClient(BaseApiClient):
447
450
  if self._should_update_replay():
448
451
  if isinstance(response_model, list):
449
452
  response_model = response_model[0]
450
- if (
451
- response_model
452
- and getattr(response_model, 'sdk_http_response', None) is not None
453
+ sdk_response_response = getattr(response_model, 'sdk_http_response', None)
454
+ if response_model and (
455
+ sdk_response_response is not None
453
456
  ):
454
- response_model.sdk_http_response.headers.pop('Date', None) # type: ignore[attr-defined]
457
+ headers = getattr(
458
+ sdk_response_response, 'headers', None
459
+ )
460
+ if headers:
461
+ pop_undeterministic_headers(headers)
455
462
  interaction.response.sdk_response_segments.append(
456
463
  response_model.model_dump(exclude_none=True)
457
464
  )
@@ -625,17 +625,22 @@ def _raise_for_unsupported_schema_type(origin: Any) -> None:
625
625
 
626
626
 
627
627
  def _raise_for_unsupported_mldev_properties(
628
- schema: Any, client: _api_client.BaseApiClient
628
+ schema: Any, client: Optional[_api_client.BaseApiClient]
629
629
  ) -> None:
630
- if not client.vertexai and (
631
- schema.get('additionalProperties') or schema.get('additional_properties')
630
+ if (
631
+ client
632
+ and not client.vertexai
633
+ and (
634
+ schema.get('additionalProperties')
635
+ or schema.get('additional_properties')
636
+ )
632
637
  ):
633
638
  raise ValueError('additionalProperties is not supported in the Gemini API.')
634
639
 
635
640
 
636
641
  def process_schema(
637
642
  schema: dict[str, Any],
638
- client: _api_client.BaseApiClient,
643
+ client: Optional[_api_client.BaseApiClient],
639
644
  defs: Optional[dict[str, Any]] = None,
640
645
  *,
641
646
  order_properties: bool = True,
@@ -785,7 +790,7 @@ def process_schema(
785
790
 
786
791
 
787
792
  def _process_enum(
788
- enum: EnumMeta, client: _api_client.BaseApiClient
793
+ enum: EnumMeta, client: Optional[_api_client.BaseApiClient]
789
794
  ) -> types.Schema:
790
795
  is_integer_enum = False
791
796
 
@@ -823,7 +828,8 @@ def _is_type_dict_str_any(
823
828
 
824
829
 
825
830
  def t_schema(
826
- client: _api_client.BaseApiClient, origin: Union[types.SchemaUnionDict, Any]
831
+ client: Optional[_api_client.BaseApiClient],
832
+ origin: Union[types.SchemaUnionDict, Any],
827
833
  ) -> Optional[types.Schema]:
828
834
  if not origin:
829
835
  return None
@@ -18,6 +18,7 @@
18
18
  from typing import Any, Optional, TYPE_CHECKING, Union
19
19
  import httpx
20
20
  import json
21
+ from . import _common
21
22
 
22
23
 
23
24
  if TYPE_CHECKING:
@@ -185,5 +186,4 @@ class FunctionInvocationError(ValueError):
185
186
  pass
186
187
 
187
188
 
188
- class ExperimentalWarning(Warning):
189
- """Warning for experimental features."""
189
+ ExperimentalWarning = _common.ExperimentalWarning
@@ -196,7 +196,7 @@ class AsyncSession:
196
196
  if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI'):
197
197
  MODEL_NAME = 'gemini-2.0-flash-live-preview-04-09'
198
198
  else:
199
- MODEL_NAME = 'gemini-2.0-flash-live-001';
199
+ MODEL_NAME = 'gemini-live-2.5-flash-preview';
200
200
 
201
201
  client = genai.Client()
202
202
  async with client.aio.live.connect(
@@ -267,7 +267,7 @@ class AsyncSession:
267
267
  if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI'):
268
268
  MODEL_NAME = 'gemini-2.0-flash-live-preview-04-09'
269
269
  else:
270
- MODEL_NAME = 'gemini-2.0-flash-live-001';
270
+ MODEL_NAME = 'gemini-live-2.5-flash-preview';
271
271
 
272
272
 
273
273
  client = genai.Client()
@@ -361,7 +361,7 @@ class AsyncSession:
361
361
  if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI'):
362
362
  MODEL_NAME = 'gemini-2.0-flash-live-preview-04-09'
363
363
  else:
364
- MODEL_NAME = 'gemini-2.0-flash-live-001';
364
+ MODEL_NAME = 'gemini-live-2.5-flash-preview';
365
365
 
366
366
  client = genai.Client()
367
367
 
@@ -372,7 +372,7 @@ class AsyncSession:
372
372
  }
373
373
 
374
374
  async with client.aio.live.connect(
375
- model='models/gemini-2.0-flash-live-001',
375
+ model='models/gemini-live-2.5-flash-preview',
376
376
  config=config
377
377
  ) as session:
378
378
  prompt = "Turn on the lights please"
@@ -940,7 +940,16 @@ class AsyncLive(_api_module.BaseModule):
940
940
  )
941
941
  method = 'BidiGenerateContentConstrained'
942
942
  key_name = 'access_token'
943
-
943
+ if version != 'v1alpha':
944
+ warnings.warn(
945
+ message=(
946
+ "The SDK's ephemeral token support is in v1alpha only."
947
+ 'Please use client = genai.Client(api_key=token.name, '
948
+ 'http_options=types.HttpOptions(api_version="v1alpha"))'
949
+ ' before session connection.'
950
+ ),
951
+ category=errors.ExperimentalWarning,
952
+ )
944
953
  uri = f'{base_url}/ws/google.ai.generativelanguage.{version}.GenerativeService.{method}?{key_name}={api_key}'
945
954
  headers = self._api_client._http_options.headers
946
955
 
@@ -166,7 +166,7 @@ class Tokens(_api_module.BaseModule):
166
166
  config=types.CreateAuthTokenConfig(
167
167
  uses=10,
168
168
  live_constrained_parameters=types.LiveEphemeralParameters(
169
- model='gemini-2.0-flash-live-001',
169
+ model='gemini-live-2.5-flash-preview',
170
170
  config=types.LiveConnectConfig(
171
171
  system_instruction='You are an LLM called Gemini.'
172
172
  ),
@@ -202,7 +202,7 @@ class Tokens(_api_module.BaseModule):
202
202
  config=types.CreateAuthTokenConfig(
203
203
  uses=10,
204
204
  live_constrained_parameters=types.LiveEphemeralParameters(
205
- model='gemini-2.0-flash-live-001',
205
+ model='gemini-live-2.5-flash-preview',
206
206
  config=types.LiveConnectConfig(
207
207
  system_instruction='You are an LLM called Gemini.'
208
208
  ),
@@ -284,7 +284,7 @@ class AsyncTokens(_api_module.BaseModule):
284
284
  async def create(
285
285
  self, *, config: Optional[types.CreateAuthTokenConfigOrDict] = None
286
286
  ) -> types.AuthToken:
287
- """Creates an auth token asynchronously.
287
+ """Creates an auth token asynchronously. Support in v1alpha only.
288
288
 
289
289
  Args:
290
290
  config (CreateAuthTokenConfig): Optional configuration for the request.
@@ -292,12 +292,16 @@ class AsyncTokens(_api_module.BaseModule):
292
292
  Usage:
293
293
 
294
294
  .. code-block:: python
295
+ client = genai.Client(
296
+ api_key=API_KEY,
297
+ http_options=types.HttpOptions(api_version='v1alpha'),
298
+ )
295
299
 
296
300
  auth_token = await client.aio.tokens.create(
297
301
  config=types.CreateAuthTokenConfig(
298
302
  uses=10,
299
303
  live_constrained_parameters=types.LiveEphemeralParameters(
300
- model='gemini-2.0-flash-live-001',
304
+ model='gemini-live-2.5-flash-preview',
301
305
  config=types.LiveConnectConfig(
302
306
  system_instruction='You are an LLM called Gemini.'
303
307
  ),
@@ -480,10 +480,21 @@ class ImagePromptLanguage(_common.CaseInSensitiveEnum):
480
480
  """Enum that specifies the language of the text in the prompt."""
481
481
 
482
482
  auto = 'auto'
483
+ """Auto-detect the language."""
483
484
  en = 'en'
485
+ """English"""
484
486
  ja = 'ja'
487
+ """Japanese"""
485
488
  ko = 'ko'
489
+ """Korean"""
486
490
  hi = 'hi'
491
+ """Hindi"""
492
+ zh = 'zh'
493
+ """Chinese"""
494
+ pt = 'pt'
495
+ """Portuguese"""
496
+ es = 'es'
497
+ """Spanish"""
487
498
 
488
499
 
489
500
  class MaskReferenceMode(_common.CaseInSensitiveEnum):
@@ -5242,6 +5253,12 @@ class GenerateContentResponse(_common.BaseModel):
5242
5253
  response_schema = _common.get_value_by_path(
5243
5254
  kwargs, ['config', 'response_schema']
5244
5255
  )
5256
+ # Handles response_json_schema. Backend will throw error if both
5257
+ # response_schema and response_json_schema are set.
5258
+ if response_schema is None:
5259
+ response_schema = _common.get_value_by_path(
5260
+ kwargs, ['config', 'response_json_schema']
5261
+ )
5245
5262
  if (
5246
5263
  inspect.isclass(response_schema)
5247
5264
  and not (
@@ -13,4 +13,4 @@
13
13
  # limitations under the License.
14
14
  #
15
15
 
16
- __version__ = '1.24.0' # x-release-please-version
16
+ __version__ = '1.25.0' # x-release-please-version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-genai
3
- Version: 1.24.0
3
+ Version: 1.25.0
4
4
  Summary: GenAI Python SDK
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License: Apache-2.0
@@ -89,10 +89,13 @@ You can create a client by configuring the necessary environment variables.
89
89
  Configuration setup instructions depends on whether you're using the Gemini
90
90
  Developer API or the Gemini API in Vertex AI.
91
91
 
92
- **Gemini Developer API:** Set `GOOGLE_API_KEY` as shown below:
92
+ **Gemini Developer API:** Set the `GEMINI_API_KEY` or `GOOGLE_API_KEY`.
93
+ It will automatically be picked up by the client. It's recommended that you
94
+ set only one of those variables, but if both are set, `GOOGLE_API_KEY` takes
95
+ precedence.
93
96
 
94
97
  ```bash
95
- export GOOGLE_API_KEY='your-api-key'
98
+ export GEMINI_API_KEY='your-api-key'
96
99
  ```
97
100
 
98
101
  **Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`,
@@ -1633,3 +1636,24 @@ except errors.APIError as e:
1633
1636
  print(e.code) # 404
1634
1637
  print(e.message)
1635
1638
  ```
1639
+
1640
+ ## Extra Request Body
1641
+
1642
+ The `extra_body` field in `HttpOptions` accepts a dictionary of additional JSON
1643
+ properties to include in the request body. This can be used to access new or
1644
+ experimental backend features that are not yet formally supported in the SDK.
1645
+ The structure of the dictionary must match the backend API's request structure.
1646
+
1647
+ - VertexAI backend API docs: https://cloud.google.com/vertex-ai/docs/reference/rest
1648
+ - GeminiAPI backend API docs: https://ai.google.dev/api/rest
1649
+
1650
+ ```python
1651
+ response = client.models.generate_content(
1652
+ model="gemini-2.5-pro",
1653
+ contents="What is the weather in Boston? and how about Sunnyvale?",
1654
+ config=types.GenerateContentConfig(
1655
+ tools=[get_current_weather],
1656
+ http_options=types.HttpOptions(extra_body={'tool_config': {'function_calling_config': {'mode': 'COMPOSITIONAL'}}}),
1657
+ ),
1658
+ )
1659
+ ```
@@ -3,7 +3,7 @@ requires = ["setuptools", "wheel", "twine>=6.1.0", "packaging>=24.2", "pkginfo>=
3
3
 
4
4
  [project]
5
5
  name = "google-genai"
6
- version = "1.24.0"
6
+ version = "1.25.0"
7
7
  description = "GenAI Python SDK"
8
8
  readme = "README.md"
9
9
  license = {text = "Apache-2.0"}
File without changes
File without changes
File without changes