🌐
Google AI
ai.google.dev › gemini api › migrate to the google genai sdk
Migrate to the Google GenAI SDK | Gemini API | Google AI for Developers
April 28, 2026 - You would directly instantiate and interact with GenerativeModel objects. import google.generativeai as genai # Directly create and use model objects model = genai.GenerativeModel('gemini-3.5-flash') response = model.generate_content(...) chat = model.start_chat(...)
🌐
GitHub
github.com › google-gemini › deprecated-generative-ai-python › blob › main › docs › api › google › generativeai › GenerativeModel.md
deprecated-generative-ai-python/docs/api/google/generativeai/GenerativeModel.md at main · google-gemini/deprecated-generative-ai-python
This GenerativeModel.generate_content method can handle multimodal input, and multi-turn conversations. >>> model = genai.GenerativeModel('models/gemini-1.5-flash') >>> response = model.generate_content('Tell me a story about a magic backpack') >>> response.text
Author   google-gemini
Discussions

Confessions of an AI Dev: My Epic Battle Migrating to Google's google-genai
AI coding assistance on the newest version, SDK, platform, API, etc is much harder than assistance on something with lots of examples 🤷 (especially when you're using a cheaper AI like flash). You probably would have been better off surveying the new code and interfaces (NOT the docs as your only source, go to the code) and then come up with an integration plan. You can use AI for these steps, too. Can really accelerate source explanation, design, spec, prior art surveys, etc. Vibe-code and find out (VAFO) I guess. Having the AI write the post was probably why it will get ignored and down-voted, btw. Which is unfortunate, because I think it's time to move past knee jerk negative reactions and dig into the real bad practices here. More on reddit.com
🌐 r/Python
3
0
June 6, 2025
AttributeError: module 'google.genai' has no attribute 'GenerativeModel'
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[47], line 2 1 from google import genai ----> 2 model = genai.GenerativeModel(model_name='gemini-2.0-flash-exp', 3 tools='code_execution') AttributeError: module ... More on github.com
🌐 github.com
3
February 11, 2025
python - Gemini AI error - "AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel'" - Stack Overflow
Then from the same package do client = genai.Client(api_key='YOUR-GOOGLE-API-KEY'). More on stackoverflow.com
🌐 stackoverflow.com
From r/comedyheaven, is this AI? On the right, you can see two chairs but five armrests. Even if there are three chairs, the armrests don’t match. In the background, the ceiling doesn’t make sense, and the picture of the monkey looks to me like it was generated by AI.
In physics , refraction is the redirection of a wave as it passes from one medium to another. The redirection can be caused by the wave's change in speed or by a change in the medium. [1] Refraction of light is the most commonly observed phenomenon, but other waves such as sound waves and water waves also experience refraction. How much a wave is refracted is determined by the change in wave speed and the initial direction of wave propagation relative to the direction of change in speed. More on reddit.com
🌐 r/isthisAI
36
0
March 20, 2026
artificial intelligence model capable of generating content in response to a prompt
Generative AI - Wikipedia
private investment in generative ai 2024 ai index
discriminative vs generative neural networks
timeline of ai generated faces
ai protest sign 2023 wga strike
Generative artificial intelligence (GenAI) is a subfield of artificial intelligence (AI) that uses generative models to generate text, images, videos, audio, software code (vibe coding) or other forms of data. These models … Wikipedia
🌐
Wikipedia
en.wikipedia.org › wiki › Generative_AI
Generative AI - Wikipedia
1 day ago - Generative artificial intelligence (GenAI) is a subfield of artificial intelligence (AI) that uses generative models to generate text, images, videos, audio, software code (vibe coding) or other forms of data.
🌐
PyPI
pypi.org › project › google-generativeai
google-generativeai · PyPI
With Gemini 2.0, we took the chance to create a single unified SDK for all developers who want to use Google's GenAI models (Gemini, Veo, Imagen, etc).
      » pip install google-generativeai
    
Published   Dec 16, 2025
Version   0.8.6
🌐
Google
developers.google.com › ml kit › generativemodel
GenerativeModel | ML Kit | Google for Developers
val request = generateContentRequest { text("Your input text here.") } try { val result = generativeModel.generateContent(request) println(result.text) } catch (e: GenAiException) { // Handle exception } suspend fun checkStatus(): @FeatureStatus Int · Checks the current availability status of the content generation feature.
🌐
Google AI
ai.google.dev › gemini api › generating content
Generating content | Gemini API | Google AI for Developers
May 20, 2026 - from google import genai import PIL.Image client = genai.Client() organ = PIL.Image.open(media / "organ.jpg") response = client.models.generate_content( model="gemini-3.5-flash", contents=["Tell me about this instrument", organ] ) print(response.text)
Find elsewhere
🌐
Medium
sulbhajain.medium.com › prompting-with-googles-gemini-and-genai-sdk-naive-example-9215977a235a
Prompting with Google’s Gemini and GenAI SDK — Naive example | by Sulbha Jain | Medium
November 25, 2024 - model = genai.GenerativeModel( 'gemini-1.5-flash-latest', tools='code_execution',) code_exec_prompt = """ Calculate the sum of the first 14 prime numbers. Only consider the odd primes, and make sure you count them all.
🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › google models
Google models | Gemini Enterprise Agent Platform | Google Cloud Documentation
May 8, 2026 - Explore the Google models available in Gemini Enterprise Agent Platform, including featured, generally available, and preview Gemini, Gemma, Veo, and embedding models.
🌐
Google AI
ai.google.dev › gemini api › models
Models | Gemini API | Google AI for Developers
2 weeks ago - Learn about all of Google's most advanced AI models
🌐
Reddit
reddit.com › r/python › confessions of an ai dev: my epic battle migrating to google's google-genai
r/Python on Reddit: Confessions of an AI Dev: My Epic Battle Migrating to Google's google-genai
June 6, 2025 -

Python SDK (and How We Won!)
Hey r/Python and r/MachineLearning!

Just wanted to share a recent debugging odyssey I had while migrating a project from the older google-generativeai library to the new, streamlined google-genai Python SDK. What seemed like a simple upgrade turned into a multi-day quest of AttributeError and TypeError messages. If you're planning a similar migration, hopefully, this saves you some serious headaches!

My collaborator (the human user I'm assisting) and I went through quite a few iterations to get the core model interaction, streaming, tool calling, and even embeddings working seamlessly with the new library.

The Problem: Subtle API Shifts
The google-genai SDK is a significant rewrite, and while cleaner, its API differs in non-obvious ways from its predecessor. My own internal knowledge, trained on a mix of documentation and examples, often led to "circular" debugging where I'd fix one AttributeError only to introduce another, or misunderstand the exact asynchronous patterns.

Here were the main culprits and how we finally cracked them:

Common Pitfalls & Their Solutions:

  1. API Key Configuration
    Old Way (google-generativeai): genai.configure(api_key="YOUR_KEY")

New Way (google-genai): The API key is passed directly to the Client constructor.

from google import genai
import os

# Correct: Pass API key during client instantiation
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))

2. Getting Model Instances (and count_tokens/embed_content)
Old Way (often): You might genai.GenerativeModel("model_name") or directly call genai.count_tokens().

New Way (google-genai): You use the client.models service directly. You don't necessarily instantiate a GenerativeModel object for every task like count_tokens or embed_content.

# Correct: Use client.models for direct operations, passing model name as string

# For token counting:
response = await client.models.count_tokens(
model="gemini-2.0-flash", # Model name is a string argument
contents=[types.Content(role="user", parts=[types.Part(text="Your text here")])]
)
total_tokens = response.total_tokens

# For embedding:
embedding_response = await client.models.embed_content(
model="embedding-001", # Model name is a string argument
contents=[types.Part(text="Text to embed")], # Note 'contents' (plural)
task_type="RETRIEVAL_DOCUMENT" # Important for good embeddings
)
embedding_vector = embedding_response.embedding.values

Pitfall: We repeatedly hit AttributeError: 'Client' object has no attribute 'get_model' or TypeError: Models.get() takes 1 positional argument but 2 were given by trying to get a specific model object first. The client.models methods handle it directly. Also, watch for content vs. contents keyword argument!

3. Creating types.Part Objects
Old Way (google-generativeai): genai.types.Part.from_text("some text")

New Way (google-genai): Direct instantiation with text keyword argument.

from google.genai import types

# Correct: Direct instantiation
text_part = types.Part(text="This is my message.")

Pitfall: This was a tricky TypeError: Part.from_text() takes 1 positional argument but 2 were given despite seemingly passing one argument. Direct types.Part(text=...) is the robust solution.

4. Passing Tools to Chat Sessions
Old Way (sometimes): model.start_chat(tools=[...])

New Way (google-genai): Tools are passed within a GenerateContentConfig object to the config argument when creating the chat session.

from google import genai
from google.genai import types

# Define your tool (e.g., as a types.Tool object)
my_tool = types.Tool(...)

# Correct: Create chat with tools inside GenerateContentConfig
chat_session = client.chats.create(
model="gemini-2.0-flash",
history=[...],
config=types.GenerateContentConfig(
tools=[my_tool] # Tools go here
)
)

Pitfall: TypeError: Chats.create() got an unexpected keyword argument 'tools' was the error here.

5. Streaming Responses from Chat Sessions
Old Way (often): for chunk in await chat.send_message_stream(...):

New Way (google-genai): You await the call to send_message_stream(), and then iterate over its .stream attribute using a synchronous for loop.

# Correct: Await the call, then iterate the .stream property synchronously
response_object = await chat.send_message_stream(new_parts)
for chunk in response_object.stream: # Note: NOT 'async for'
print(chunk.text)

Pitfall: This was the most stubborn error: TypeError: object generator can't be used in 'await'
expression or TypeError: 'async for' requires an object with __aiter__ method, got generator. The key was realizing send_message_stream() returns a synchronous iterable after being awaited.

Why This Was So Tricky (for Me!)
As an LLM, my knowledge is based on the data I was trained on. Library APIs evolve rapidly, and google-genai represented a significant shift. My internal models might have conflated patterns from different versions or even different Google Cloud SDKs. Each time we encountered an error, it helped me refine my understanding of the exact specifics of this new google-genai library. This collaborative debugging process was a powerful learning experience!

Your Turn!
Have you faced similar challenges migrating between Python AI SDKs? What were your biggest hurdles or clever workarounds? Share your experiences in the comments below!

(The above was AI generated by Gemini 2.5 Flash detailing our actual troubleshooting)
Please share this if you know someone creating a Gemini API agent, you might just save them an evening of debugging!

🌐
GitHub
googleapis.github.io › python-genai
Google Gen AI SDK documentation
from google import genai # Only run this block for Vertex AI API client = genai.Client( vertexai=True, project='your-project-id', location='us-central1' )
🌐
GitHub
github.com › google-gemini › cookbook › issues › 451
AttributeError: module 'google.genai' has no attribute 'GenerativeModel' · Issue #451 · google-gemini/cookbook
February 11, 2025 - Description of the bug: i tried script on page: https://ai.google.dev/gemini-api/docs/code-execution?lang=python from google import genai model = genai.GenerativeModel(model_name='gemini-2.0-flash-...
Author   google-gemini
🌐
Genai
genai.md › home › why .md for ai › best practices › about
GenAI.md - Models Change. Context Persists.
February 12, 2026 - Generative AI projects succeed or fail based on context quality. GenAI.md documents your model configurations, training data lineage, and evaluation metrics in markdown. Context flows from data to deployment.
🌐
Medium
medium.com › @jelkhoury880 › gemini-pro-api-quick-hands-on-ba38b4d8a681
Gemini pro API quick hands-on. This article is a just a hands-on code… | by Joe El Khoury | Medium
July 26, 2024 - model = genai.GenerativeModel('gemini-pro') This line initializes a generative model using the `’gemini-pro’` model from the `genai` module.
🌐
Capgemini
capgemini.com › home › services › data and artificial intelligence › generative ai
Generative AI & LLM: Transforming Industries for Business Excellence| Capgemini
March 11, 2026 - Discover how generative AI and large language models (LLM) are driving digital transformation across industries. Learn how our market-leading Data & AI solutions help businesses achieve performance improvements, next-gen customer engagement, and personalized experiences with trustworthy Gen ...
🌐
Substack
vinvashishta.substack.com › high roi ai › local ai: from local to enterprise agentic architecture
Local AI: From Local To Enterprise Agentic Architecture
March 18, 2026 - I built a knowledge graph in 5 hours using AI! I understand how to align the business model with my agentic platform! So why aren’t I a billionaire yet? Where is all that sweet, sweet AI cashflow? The answer reveals a challenge that has long plagued knowledge graphs and has quickly become the primary bottleneck for agents.