To install from PyPI, run pip install google-generativeai. Obtain an API key from AI Studio, then configure it here.

Also, your import statement is wrong. You did import google.generative as genai but it should be import google.generativeai as genai. See PyPi.

Answer from Uchenna Adubasim on Stack Overflow
🌐
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). As part of that process, we took all of the feedback from this SDK and what developers like about other SDKs in the ecosystem to create the Google Gen AI SDK.
      » pip install google-generativeai
    
Published   Dec 16, 2025
Version   0.8.6
🌐
Google AI
discuss.ai.google.dev › gemini api
Import google.generativeai as genai - Gemini API - Google AI Developers Forum
January 22, 2025 - I am using this library in Python. I want this library to connect to AI through a proxy How should I set it up? I tried this: os.environ[‘HTTP_PROXY’] = ‘socks5://127.0.0.1:7890’ os.environ[‘HTTPS_PROXY’] = ‘socks5://127.0.0.1:7890’ But it didn’t work.
🌐
GitHub
github.com › google-gemini › generative-ai-python › blob › main › docs › api › google › generativeai.md
deprecated-generative-ai-python/docs/api/google/generativeai.md at main · google-gemini/deprecated-generative-ai-python
Use genai.GenerativeModel to access the API: import google.generativeai as genai import os genai.configure(api_key=os.environ['API_KEY']) model = genai.GenerativeModel(model_name='gemini-1.5-flash') response = model.generate_content('Teach me ...
Author   google-gemini
🌐
GitHub
github.com › googleapis › python-genai
GitHub - googleapis/python-genai: Google Gen AI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications. · GitHub
1 month ago - from google import genai # Only run this block for Agent Platform client = genai.Client( enterprise=True, project='your-project-id', location='global' )
Starred by 3.8K users
Forked by 929 users
Languages   Python
🌐
PyPI
pypi.org › project › google-genai
google-genai · PyPI
2 weeks ago - from google import genai # Only run this block for Agent Platform client = genai.Client( enterprise=True, project='your-project-id', location='global' )
      » pip install google-genai
    
Published   Jun 24, 2026
Version   2.10.0
Find elsewhere
🌐
GitHub
github.com › google-gemini › deprecated-generative-ai-python › issues › 606
ModuleNotFoundError: No module named 'google.generativeai' · Issue #606 · google-gemini/deprecated-generative-ai-python
October 17, 2024 - Description of the bug: Using the following code: import os import google.generativeai as genai I tried every method there was. I even did: pip install google-generativeai pip install -U google-gen...
Author   google-gemini
🌐
npm
npmjs.com › package › @google › genai
google/genai
1 week ago - For quicker, more responsive API interactions use the generateContentStream method which yields chunks as they're generated: import {GoogleGenAI} from '@google/genai'; const GEMINI_API_KEY = process.env.GEMINI_API_KEY; const ai = new ...
      » npm install @google/genai
    
Published   Jun 24, 2026
Version   2.10.0
🌐
Priyanshu
priyanshu.com.np › home › how to set up and use google generative ai in python
How to Set Up and Use Google Generative AI in Python - Priyanshu
July 11, 2024 - import google.generativeai as genai import os from dotenv import load_dotenv # Load API key from .env file load_dotenv() google_api_key = os.getenv('API_KEY') # Configure the Generative AI model genai.configure(api_key=google_api_key)
🌐
Medium
medium.com › @pragyaruhela05 › getting-started-with-google-generative-ai-using-the-gen-ai-sdk-a520e7820e93
🚀 Getting Started with Google Generative AI Using the Gen AI SDK | by Pragya R | Medium
May 10, 2025 - import google.generativeai as genai · genai.configure(api_key="YOUR_API_KEY") This key allows the SDK to access Google’s Generative AI models on your behalf.
🌐
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
>>> import google.generativeai as genai >>> import PIL.Image >>> genai.configure(api_key='YOUR_API_KEY') >>> model = genai.GenerativeModel('models/gemini-1.5-flash') >>> result = model.generate_content('Tell me a story about a magic backpack') >>> result.text "In the quaint little town of Lakeside, there lived a young girl named Lily..."
Author   google-gemini
🌐
Instructor
python.useinstructor.com › integrations › google
Google Gemini Tutorial: Structured Outputs with Instructor - Instructor
import instructor import google.generativeai as genai client = instructor.from_provider( "google/gemini-2.5-flash", mode=instructor.Mode.JSON, ) import instructor # Option 1: Using from_provider (recommended) client = instructor.from_provider("google/gemini-2.5-flash") # Option 2: Using from_genai ...
🌐
GitHub
googleapis.github.io › python-genai
Google Gen AI SDK documentation
from google.genai import types contents = types.Part.from_uri( file_uri: 'gs://generativeai-downloads/images/scones.jpg', mime_type: 'image/jpeg', ) The SDK converts all non function call parts into a content with a user role.
🌐
GitHub
github.com › googleapis › python-genai › blob › main › codegen_instructions.md
python-genai/codegen_instructions.md at main · googleapis/python-genai
Do not try to adjust thinking budgets for other models (such as gemini-2.0-flash or gemini-2.0-pro), otherwise it will cause syntax errors. Use system instructions to guide model's behavior. from google import genai from google.genai import types client = genai.Client() response = client.models.generate_content( model='gemini-3-flash-preview', contents='Explain quantum physics.', config=types.GenerateContentConfig( system_instruction='You are a pirate', ) ) print(response.text)
Author   googleapis
🌐
GitHub
github.com › langchain-ai › langchain-google › issues › 729
Move from `import google.generativeai as genai` to `import google as genai` · Issue #729 · langchain-ai/langchain-google
February 9, 2025 - Change the default Google library from google-generativeai to google-genai. Also the import statement import google.generativeai as genai should be changed to import google as genai to support new advanced features such as system instructions ...
Author   langchain-ai
🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › google gen ai sdk
Google Gen AI SDK | Gemini Enterprise Agent Platform | Google Cloud Documentation
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True · import ( "context" "fmt" "io" "google.golang.org/genai" ) // generateWithText shows how to generate text using a text prompt.
🌐
DEV Community
dev.to › soytuber › google-generativeai-google-genai-migration-guide-29gl
google-generativeai google-genai Migration Guide - DEV Community
March 24, 2026 - The google.generativeai package has been deprecated. Migration to the new google-genai SDK is recommended. Developers should migrate as soon as possible. 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 · pip install --upgrade google-genai · # 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 ·
🌐
Anaconda.org
anaconda.org › conda-forge › google-generativeai
google-generativeai - conda-forge | Anaconda.org
Install google-generativeai with Anaconda.org. The Gemini API Python SDK enables developers to use Google's state-of-the-art generative AI models to build AI-powered features and applications.