Hi OP, Architectural Differences: google.generativeai - Low-Level API: Direct Model Access: This library provides a relatively direct mapping to the underlying Google generative model APIs. It exposes concepts like GenerationConfig, SafetySettings, and different model variants in a fairly ver… Answer from CincyAI on discuss.ai.google.dev
🌐
Google AI
discuss.ai.google.dev › gemini api
Google.generativeai vs python-genai - Gemini API - Google AI Developers Forum
December 13, 2024 - I see google has new API. GenAI (from google import genai) I am not sure, Is the GenAI will be replace google.generativeai or they will maintain both?
🌐
Google AI
discuss.ai.google.dev › gemini api
Need clarification about Google AI python packageS (google-genai vs google-generativeai) - Gemini API - Google AI Developers Forum
January 16, 2025 - The problem I encounter is the existence of two different Python packages offered by Google. First, there is the generative-ai-python (github: /google-gemini/generative-ai-python), installed as pip install -U google-generativeai and imported as import google.generativeai as genai. The README ...
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
node.js - Utilizing Gemini: Through Vertex AI or through Google/generative-ai? - Stack Overflow
I'm in the process of developing a chatbot application and I'm exploring options for integrating Gemini, a large language model (LLM). I'm considering whether to utilize Vertex AI (@google-cloud/ve... More on stackoverflow.com
🌐 stackoverflow.com
What are the differences between google-genai and google-generativeai? Which one can be used with a free API key from AI Studio?
Google Gen AI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications. - What are the differences between google-genai and google-generativeai? Which one can be used with a free API key from AI Studio? More on github.com
🌐 github.com
1
December 11, 2024
Clarify when to use google-generativeai vs google-cloud-aiplatform
This SDK is now deprecated, use the new unified Google GenAI SDK. - google-gemini/deprecated-generative-ai-python More on github.com
🌐 github.com
4
March 30, 2024
🌐
Google AI
discuss.ai.google.dev › gemini api
Confused about @google/generative-ai, @google/genai, and all hosted repos - Gemini API - Google AI Developers Forum
April 10, 2025 - This is is really hard for me to figure out because there are so many different repos names and different npm names and different python repo / pip names - and completely without any schema. I even tried to ask Gemini 2.5 pro and you made it so confusing that even gemini providing some misleading ...
🌐
Oreate AI
oreateai.com › blog › decoding-google-generative-ai-and-google-genai-whats-the-difference › 45fdb37dd6dbd9bd7a7fca19c6dff163
Decoding Google Generative AI and Google GenAI: What’s the Difference? - Oreate AI Blog
January 7, 2026 - On the other hand, when we talk about Google GenAI specifically, we're diving into a more focused subset within this broader framework. It encompasses Google's tailored applications and models designed explicitly for generative tasks across ...
🌐
Medium
medium.com › google-cloud › migrating-to-the-new-google-gen-ai-sdk-python-074d583c2350
Migrating to the new Google Gen AI SDK (Python) | by Maciej Strzelczyk | Google Cloud - Community | Medium
July 24, 2025 - For convenience, I will be calling the old libraries (aiplatform and generativeai) “first generation” and the new one (google-genai) “second generation”.
🌐
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!

Top answer
1 of 2
15

Gemini is a large language model as you specified. You can use it (via API calls) by calling either Google AI APIs or Vertex AI APIs.

If you are relatively new to Gemini and wants to explore the feature and build some prototype for your chatbot app, Google AI APIs (with Google AI Studio) is a fast way to get started. While your app and idea matures and you'd like to leverage more MLOps tools that streamline the usage, deployment, and monitoring of models, you can move to Google Cloud Vertex AI which provides Gemini APIs along with many other features. Basically, to help you productionize your app.

Depending on your app requirement and stages of your development, you can choose the path:

  • Start with Google AI Studio and migrate Gemini app to Vertex AI
  • Prototype and build with Vertex AI if you already have GCP established.

Pay attention to the Google AI vs. Vertex AI differences when making decision.

Update (2025):

Google released a new GenAI SDK that provides a unified interface to Gemini >2.0models through both the Gemini Developer API and the Gemini API on Vertex AI. With a few exceptions, code that runs on one platform will run on both. This means that you can prototype an application using the Gemini Developer API and then migrate the application to Vertex AI without rewriting your code.

Detail see here.

2 of 2
1

Updated answer in Aug 2025

Significant changes have been introduced in 2025. Google has released a new Google GenAI SDK, that allows to switch between Google Gemini and Gemini on Vertex AI.

Here is a code samples for your

Copyimport {GoogleGenAI} from '@google/genai';
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;

const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY});      # Using Google Gemini

async function main() {
  const response = await ai.models.generateContentStream({
    model: 'gemini-2.0-flash-001',
    contents: 'Write a 100-word poem.',
  });
  for await (const chunk of response) {
    console.log(chunk.text);
  }
}

main();

To change this code to use Gemini on Vertex

Copy
const ai = new GoogleGenAI({                               # Using Gemini on Vertex AI
    vertexai: true,
    project: 'your_project',
    location: 'your_location',
    apiVersion: 'v1'
});

Tip: If you are planning to use Gemini on Vertex AI, I recommend check Global Endpoint.

To make this code more portable, you also set required config in Environment Variables. Check: https://www.npmjs.com/package/@google/genai or https://github.com/googleapis/js-genai

Find elsewhere
🌐
GitHub
github.com › googleapis › python-genai › issues › 3
What are the differences between google-genai and google-generativeai? Which one can be used with a free API key from AI Studio? · Issue #3 · googleapis/python-genai
December 11, 2024 - Google Gen AI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications. - What are the differences between google-genai and google-generativeai? Which one can be used with a free API key from AI Studio?
Author   googleapis
🌐
GitHub
github.com › google › generative-ai-python › issues › 266
google-gemini/deprecated-generative-ai-python
March 30, 2024 - This SDK is now deprecated, use the new unified Google GenAI SDK. - google-gemini/deprecated-generative-ai-python
Author   google-gemini
🌐
Reddit
reddit.com › r/geminiai › gemini 2.5 pro doesn't know how to use its own google-genai python api?
r/GeminiAI on Reddit: Gemini 2.5 Pro doesn't know how to use its own google-genai Python API?
April 8, 2025 -

Has anyone else noticed that Gemini (2.5 Pro) apparently doesn't know how to use the google-genai Python API, which is the recommended python module from Google for interacting with the Gemini API. (All the AI Studio docs refer to google-genai).

This isn't consistent with the stated training cut off date of March 2025 and seems like a bit of an embarrassing limitation. The training cut off implies that it could have at least been trained on google-genai v1.3.

What's more, the model seemed to gas light me as I tried to clarify that `google-genai` is a different module from `google-generativeai` and even if I enabled search grounding and provided a link to the pypi module it still recalled older knowledge about a 0.5 release and "politely" told me that, no, `google-genai` is not a thing.

If I copied the full releases.xml RSS feed for the module I could convince Gemini that the module is actively maintained and version 1.3 exists, but from its generated code it clearly doesn't know anything about the API changes compared to google-generativeai.

Up-to-date knowledge about the latest APIs does seem to be a general limitation when trying to use models like Gemini for programming.

🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › google gen ai sdk
Google Gen AI SDK | Gemini Enterprise Agent Platform | Google Cloud Documentation
The Google Gen AI SDK provides a unified interface to Gemini models through both the Gemini Developer API and the Gemini API on Gemini Enterprise Agent Platform.
🌐
LangChain
python.langchain.com › api_reference › google_genai
langchain_google_genai | LangChain Reference
As of langchain-google-genai 4.0.0, this package uses the consolidated google-genai SDK instead of the legacy google-ai-generativelanguage SDK.
🌐
GitHub
github.com › google-gemini › deprecated-generative-ai-python › issues › 266
Clarify when to use google-generativeai vs google-cloud- ...
March 30, 2024 - This SDK is now deprecated, use the new unified Google GenAI SDK. - google-gemini/deprecated-generative-ai-python
Author   google-gemini
🌐
Reddit
reddit.com › r/homeassistant › google generative ai - which model is used?
r/homeassistant on Reddit: Google Generative AI - Which Model is Used?
February 23, 2025 -

I thought I'd seen in the github code that the default Gemini model used for the Google Generative AI Integration was version 2, yet in my Cloud console, it shows the events being logged under gemini-1.5-flash?

Is there a way of forcing it to use the version 2?

I ask because I'm getting constant quota exceeded messages which are incorrect (happens even after being reinstated) and I'm wondering if its to do with the gemini model version.

🌐
npm
npmjs.com › package › @google › genai
google/genai
1 week ago - import {GoogleGenAI} from '@google/genai'; const GEMINI_API_KEY = process.env.GEMINI_API_KEY; const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY}); async function main() { const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Why is the sky blue?', }); console.log(response.text); } main();
      » npm install @google/genai
    
Published   Jun 24, 2026
Version   2.10.0
🌐
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
🌐
LangChain Forum
forum.langchain.com › oss product help
Upgrade Google Generative AI SDK integration from @google/generative-ai to @google/genai - LangChain - LangChain Forum
November 5, 2025 - The current integration of the Google Generative AI SDK in LangChain.js (via @google/generative-ai or equivalent) is tracking a library that is now deprecated. According to Google’s documentation: The legacy library @google/generative-ai is flagged as end-of-life.
🌐
Google AI
discuss.ai.google.dev › gemini api
Difference between SDKs generative-ai-go vs go-genai - Gemini API - Google AI Developers Forum
January 11, 2025 - Hi there! Anyone knows what is the plan for both of these SDKs? Is it expected that both will be maintained in the nearest future? What is the recommended one maybe? Cheers! This one was around for some time: GitHub - google/generative-ai-go: Go SDK for Google Generative AI This one was added recently: GitHub - googleapis/go-genai: Google Gen AI Go SDK provides an interface for developers to integrate Google's generative models into their Go applications.
🌐
LinkedIn
linkedin.com › pulse › what-difference-between-google-generative-ai-gemini-studio-sanoja-1kume
What is the difference between Google Generative AI Gemini and Google AI Studio From Gemini
February 12, 2025 - Google AI Gemini and Google AI Studio are related but distinct entities within the Google ecosystem, primarily focusing on different aspects of AI model development and interaction. Here's a breakdown of their key differences: Google Generative AI Gemini: This refers to the family of large language