If you have legacy code, port it
google-generativeai reached EOL in November 2025. It still installs and runs in many cases, but Google is no longer fixing bugs, and as model APIs evolve the legacy SDK silently rots. The migration is mechanical and worth doing in one sitting.
The shape changed
Six things change between the SDKs:
| Aspect | Legacy (google-generativeai) | New (google-genai) |
|---|---|---|
| Package | google-generativeai | google-genai |
| Import | import google.generativeai as genai | from google import genai |
| Init | genai.configure(api_key=...) | genai.Client(api_key=...) |
| Model object | genai.GenerativeModel('...') | (none — pass model= per call) |
| Generate | model.generate_content(text) | client.models.generate_content(model=..., contents=...) |
| Stream | stream=True kwarg | generate_content_stream() |
| Async | generate_content_async() | client.aio.models.generate_content() |
| Chat | model.start_chat() | client.chats.create(model=...) |
| Vertex | Separate vertexai pkg | Client(vertexai=True) |
Migration order that actually works
- Pin
google-genaiinrequirements.txtalongside the legacy one — they coexist. - Add a new module that exports
get_client() -> genai.Client. - Migrate one call site at a time: replace
model.generate_content(text)withclient.models.generate_content(model=..., contents=text). - Delete the legacy
configure()call after the last call site is ported. - Drop the legacy package from requirements.