
google-generativeai google-genai Migration Guide
What Happened The google.generativeai package has been deprecated. Migration to the new google-genai SDK is recommended. Developers should migrate as soon as possible. Features of the New google-genai SDK Integrated interface with Gemini 2.5 Pro/Flash models Support for context caching Automatic loading of authentication via the GOOGLE_GENAI_API_KEY environment variable Specific Migration Steps Environment Setup pip install --upgrade google-genai Changing Imports # Old Code (Deprecated) import google.generativeai as genai genai . configure ( api_key = " your-key " ) # New Code from google import genai client = genai . Client () # Automatically loads GOOGLE_GENAI_API_KEY Rewriting generate_content # Old Code model = genai . GenerativeModel ( " gemini-2.5-pro " ) response = model . generate_content ( " Hello " ) # New Code from google.genai import types response = client . models . generate_content ( model = " gemini-2.5-pro " , contents = " Hello " , config = types . GenerateContentConf
Continue reading on Dev.to Python
Opens in a new tab




