From 49059181ea0452e160ec61135c29f9c177f19160 Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Tue, 21 Jul 2026 14:20:38 -0700 Subject: [PATCH] fix: add deprecation warnings to Imagen generate_images, edit_images, generate_videos (if using prompt/text/image args), LiveConnectConfig.GenerationConfig which will be removed in the next major version PiperOrigin-RevId: 951696435 --- google/genai/live.py | 4 +-- google/genai/models.py | 73 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/google/genai/live.py b/google/genai/live.py index 777df3a85..b9cf0c33e 100644 --- a/google/genai/live.py +++ b/google/genai/live.py @@ -1191,8 +1191,8 @@ async def _t_live_connect_config( if parameter_model_copy.generation_config is not None: warnings.warn( 'Setting `LiveConnectConfig.generation_config` is deprecated, ' - 'please set the fields on `LiveConnectConfig` directly. This will ' - 'become an error in a future version (not before Q3 2025)', + 'please set the fields on `LiveConnectConfig` directly. It will be ' + 'removed in the next major version (not before 7/31/2026).', DeprecationWarning, stacklevel=4, ) diff --git a/google/genai/models.py b/google/genai/models.py index 7a35a8b6c..63fefc803 100644 --- a/google/genai/models.py +++ b/google/genai/models.py @@ -21,6 +21,7 @@ import logging from typing import Any, AsyncIterator, Awaitable, Iterator, Optional, Union from urllib.parse import urlencode +import warnings from . import _api_module from . import _base_transformers as base_t @@ -6362,6 +6363,8 @@ def _generate_videos( self._api_client._verify_response(return_value) return return_value + _logged_generate_videos_deprecation_warning = False + def embed_content( self, *, @@ -6802,6 +6805,14 @@ def generate_content_stream( automatic_function_calling_history.append(func_call_content) automatic_function_calling_history.append(func_response_content) + @_common.experimental_warning( + 'The generate_images method is deprecated and will be removed in the ' + 'next major release (not before Jan. 1 2027). Please use the ' + 'generate_content method with image models instead. ' + 'See https://ai.google.dev/gemini-api/docs/deprecations#imagen-models' + ' and ' + 'https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/capabilities/image-generation#generate-images', + ) def generate_images( self, *, @@ -6857,6 +6868,12 @@ def generate_images( ) return response + @_common.experimental_warning( + 'The edit_image method is deprecated and will be removed in the next ' + 'major release (not before Jan. 1 2027). Please use the ' + 'generate_content method with image models instead. ' + 'See https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/capabilities/gemini-edit-images#edit-an-image', + ) def edit_image( self, *, @@ -7036,11 +7053,21 @@ def generate_videos( operation.result.generated_videos[0].video.uri ``` """ - if (prompt or image or video) and source: - raise ValueError( - 'Source and prompt/image/video are mutually exclusive.' - + ' Please only use source.' - ) + if prompt or image or video: + if source: + raise ValueError( + 'Source and prompt/image/video are mutually exclusive.' + + ' Please only use source.' + ) + if not Models._logged_generate_videos_deprecation_warning: + warnings.warn( + 'The generate_videos method with prompt/image/video arguments is' + ' deprecated and will be removed in a future major release (not' + ' before 2026-07-31). Please use the source argument instead.', + DeprecationWarning, + stacklevel=2, + ) + Models._logged_generate_videos_deprecation_warning = True # Gemini Developer API does not support video bytes. video_dct: dict[str, Any] = {} if not self._api_client.vertexai and video: @@ -8572,6 +8599,8 @@ async def _generate_videos( self._api_client._verify_response(return_value) return return_value + _logged_generate_videos_deprecation_warning = False + async def generate_content( self, *, @@ -9078,6 +9107,12 @@ async def stream_generator(): # type: ignore[no-untyped-def] return stream_generator() # type: ignore[no-untyped-call, no-any-return] + @_common.experimental_warning( + 'The edit_image method is deprecated and will be removed in the next ' + 'major release (not before Jan. 1 2027). Please use the ' + 'generate_content method with image models instead. ' + 'See https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/capabilities/gemini-edit-images#edit-an-image', + ) async def edit_image( self, *, @@ -9186,6 +9221,14 @@ async def list( config, ) + @_common.experimental_warning( + 'The generate_images method is deprecated and will be removed in the ' + 'next major release (not before Jan. 1 2027). Please use the ' + 'generate_content method with image models instead. ' + 'See https://ai.google.dev/gemini-api/docs/deprecations#imagen-models' + ' and ' + 'https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/capabilities/image-generation#generate-images', + ) async def generate_images( self, *, @@ -9364,11 +9407,21 @@ async def generate_videos( operation.result.generated_videos[0].video.uri ``` """ - if (prompt or image or video) and source: - raise ValueError( - 'Source and prompt/image/video are mutually exclusive.' - + ' Please only use source.' - ) + if prompt or image or video: + if source: + raise ValueError( + 'Source and prompt/image/video are mutually exclusive.' + + ' Please only use source.' + ) + if not AsyncModels._logged_generate_videos_deprecation_warning: + warnings.warn( + 'The generate_videos method with prompt/image/video arguments is' + ' deprecated and will be removed in a future major release (not' + ' before 2026-07-31). Please use the source argument instead.', + DeprecationWarning, + stacklevel=2, + ) + AsyncModels._logged_generate_videos_deprecation_warning = True # Gemini Developer API does not support video bytes. video_dct: dict[str, Any] = {} if not self._api_client.vertexai and video: