🌐
PyPI
pypi.org › project › google-genai
google-genai · PyPI
2 weeks ago - Where a types.ModelContent is a subclass of types.Content, the role field in types.ModelContent is fixed to be model. from google.genai import types contents = [ types.Part.from_function_call( name='get_weather_by_location', args={'location': 'Boston'} ), types.Part.from_function_call( name='get_weather_by_location', args={'location': 'New York'} ), ]
      » pip install google-genai
    
Published   Jun 24, 2026
Version   2.10.0
🌐
GitHub
googleapis.github.io › python-genai
Google Gen AI SDK documentation
The SDK always converts the inputs to the contents argument into list[types.Content]. The following shows some common ways to provide your inputs. This is the canonical way to provide contents, SDK will not do any conversion. from google.genai import types contents = types.Content( role='user', parts=[types.Part.from_text(text='Why is the sky blue?')] )
🌐
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 - Config arguments can be specified as either Python dictionaries or Config classes in the google.genai.types namespace. For utility and uniformity, all definitions within the types module are pydantic classes. from google import genai from google.genai import types client = genai.Client() response = client.models.generate_content( model='gemini-3.5-flash', contents='Tell me a story in 100 words.', config=types.GenerateContentConfig( system_instruction='you are a story teller for kids under 5 years old', max_output_tokens= 400, top_k= 2, top_p= 0.5, temperature= 0.5, response_mime_type= 'application/json', stop_sequences= ['\n'], seed=42, ), )
🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › google gen ai sdk
Google Gen AI SDK | Gemini Enterprise Agent Platform | Google Cloud Documentation
from google import genai from google.genai.types import HttpOptions client = genai.Client(http_options=HttpOptions(api_version="v1")) response = client.models.generate_content( model="gemini-3.5-flash", contents="How does AI work?", ) ...
🌐
GitHub
googleapis.github.io › python-genai › genai.html
Submodules - Google Gen AI SDK documentation
import google.genai from google.genai import types import os if os.environ.get('GOOGLE_GENAI_USE_ENTERPRISE'): MODEL_NAME = 'gemini-2.0-flash-live-preview-04-09' else: MODEL_NAME = 'gemini-live-2.5-flash-preview'; client = genai.Client() async with client.aio.live.connect( model=MODEL_NAME, config={"response_modalities": ["TEXT"]} ) as session: await session.send_client_content( turns=types.Content( role='user', parts=[types.Part(text="Hello world!")])) async for msg in session.receive(): if msg.text: print(msg.text)
🌐
GitHub
github.com › googleapis › python-genai › blob › main › codegen_instructions.md
python-genai/codegen_instructions.md at main · googleapis/python-genai
You can also set temperature or max_output_tokens within types.GenerateContentConfig Avoid setting max_output_tokens, topP, topK unless explicitly requested by the user. Avoid setting safety configurations unless explicitly requested by the user. If explicitly asked for by the user, here is a sample API: from google import genai from google.genai import types from PIL import Image client = genai.Client() img = Image.open('/path/to/img') response = client.models.generate_content( model='gemini-2.0-flash', contents=['Do these look store-bought or homemade?', img], config=types.GenerateContentConfig( safety_settings=[ types.SafetySetting( category=types.HarmCategory.HARM_CATEGORY_HATE_SPEECH, threshold=types.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, ), ] ) ) print(response.text)
Author   googleapis
🌐
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
4 weeks ago - Where a types.UserContent is a subclass of types.Content, the role field in types.UserContent is fixed to be user. from google.genai import types contents = types.Part.from_function_call( name='get_weather_by_location', args={'location': 'Boston'} )
Starred by 3.8K users
Forked by 929 users
Languages   Python
🌐
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 - With the new SDK, the library does everything for you, provided you define your function using type annotations and you write its docstring (like we always do for every function, right? 😉). from google.genai import types def get_current_weather(location: str) -> str: """Returns the current weather.
🌐
Google AI
discuss.ai.google.dev › gemini api
From google import genai from google.genai import types client = genai.Client(api_key="GEMINI_API_KEY") response = client.models.generate_content( model="gemini-2.0-flash-exp", contents=( "Generate a story about a cute baby turtle in a 3 - Gemini API - Google AI Developers Forum
March 17, 2025 - from google import genai from google.genai import types client = genai.Client(api_key=“GEMINI_API_KEY”) response = client.models.generate_content( model=“gemini-2.0-flash-exp”, contents=( "Generate a story about a cute baby turtle in a 3d digital art style.
🌐
npm
npmjs.com › package › @google › genai
google/genai
1 week ago - import {GoogleGenAI, FunctionCallingConfigMode, FunctionDeclaration, Type} from '@google/genai'; const GEMINI_API_KEY = process.env.GEMINI_API_KEY; async function main() { const controlLightDeclaration: FunctionDeclaration = { name: 'controlLight', parametersJsonSchema: { type: 'object', properties:{ brightness: { type:'number', }, colorTemperature: { type:'string', }, }, required: ['brightness', 'colorTemperature'], }, }; const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY}); const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Dim the lights so the room feels cozy and warm.', config: { toolConfig: { functionCallingConfig: { // Force it to call any function mode: FunctionCallingConfigMode.ANY, allowedFunctionNames: ['controlLight'], } }, tools: [{functionDeclarations: [controlLightDeclaration]}] } }); console.log(response.functionCalls); } main();
      » npm install @google/genai
    
Published   Jun 24, 2026
Version   2.10.0
Find elsewhere
🌐
GitHub
github.com › google-gemini › generative-ai-python › issues › 686
Documentation is missing for Search Grounding with DynamicRetrievalConfig in the new SDK. · Issue #686 · google-gemini/deprecated-generative-ai-python
February 18, 2025 - from google import genai from google.genai import types client = genai.Client(api_key="GEMINI_API_KEY") response = client.models.generate_content( model='gemini-2.0-flash', contents="Who won Wimbledon this year?", config=types.GenerateContentConfig( tools=[types.Tool( google_search=types.GoogleSearchRetrieval( dynamic_retrieval_config=types.DynamicRetrievalConfig( dynamic_threshold=0.6)) )] ) ) print(response)
Author   google-gemini
🌐
Analytics Vidhya
analyticsvidhya.com › home › google gen ai python sdk: a complete guide
Google Gen AI Python SDK: A Complete Guide
August 17, 2025 - The genai module creates a client used for API interaction, while the types module has data structures and classes that serve as helpers used to build requests and configure request parameters. You will create an instance of the client for each interaction with the Google generative AI models. You will instantiate the client with different methods depending on the API you are using. For the Gemini Developer API, you can instantiate the client by passing along your API key: client = genai.Client(api_key='YOUR_GEMINI_API_KEY')
🌐
Instructor
python.useinstructor.com › integrations › genai
Structured outputs with Google's genai SDK - Instructor
PDFWithGenaiFile.from_new_genai_file( "./invoice.pdf", retry_delay=1, # Time to wait before checking if file is ready to use max_retries=20 # Number of times to check before throwing an error ), This makes it easier for you to work with the Gemini files API. You can use this in a normal chat completion as seen below · from instructor.processing.multimodal import PDFWithGenaiFile from pydantic import BaseModel import instructor from google.genai import Client class Receipt(BaseModel): total: int items: list[str] client = instructor.from_provider("google/gemini-2.5-flash") url = "https://raw.gi
🌐
DEV Community
dev.to › ranand12 › googles-unified-genai-sdk-a-hands-on-guide-2n2d
Google's Unified Gen AI SDK: A Hands-on Guide - DEV Community
March 11, 2025 - from google import genai from google.genai import types PROJECT_ID = userdata.get('PROJECT_ID') LOCATION = userdata.get('LOCATION') # Create a client instance using Vertex AI in Google Cloud client = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION) response = client.models.generate_content( model='gemini-2.0-flash', contents='Create a short bedtime story for a 3 year old using unicorns and rainbows', config = types.GenerateContentConfig( max_output_tokens=200, temperature = 0.1) ) display(Markdown(response.text)) System instructions help define the persona of your client inst
🌐
Phil Schmid
philschmid.de › gemma-4-gemini-api
How to use Gemma 4 with the Gemini API and Google AI Studio
April 7, 2026 - from google import genai from google.genai import types client = genai.Client() response = client.models.generate_content( model="gemma-4-31b-it", config=types.GenerateContentConfig( system_instruction="You are a wise Kyoto tea master.
🌐
DEV Community
dev.to › soytuber › google-generativeai-google-genai-migration-guide-29gl
google-generativeai google-genai Migration Guide - DEV Community
March 24, 2026 - # Old Code (hanrei-db.py) import google.generativeai as genai model = genai.GenerativeModel(model_name="gemini-2.5-pro") response = model.generate_content("この判例を要約してください") # New Code (After Migration) from google import genai from google.genai import types client = genai.Client() response = client.models.generate_content( model="gemini-2.5-pro", contents="この判例を要約してください", config=types.GenerateContentConfig(temperature=0.1) )
🌐
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
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 about how an LLM works') print(response.text) See the python quickstart for more details. ... protos module: This module provides low level access to the ProtoBuffer "Message" classes used by the API. types module: A collection of type definitions used throughout the library.
Author   google-gemini
🌐
Google AI
ai.google.dev › gemini api › generating content
Generating content | Gemini API | Google AI for Developers
May 20, 2026 - from google import genai from google.genai import types client = genai.Client() document = client.files.upload(file=media / "a11.txt") model_name = "gemini-3.5-flash" cache = client.caches.create( model=model_name, config=types.CreateCachedContentConfig( contents=[document], system_instruction="You are an expert analyzing transcripts.", ), ) print(cache) response = client.models.generate_content( model=model_name, contents="Please summarize this transcript", config=types.GenerateContentConfig(cached_content=cache.name), ) print(response.text)
🌐
GitHub
github.com › google-gemini › deprecated-generative-ai-python › issues › 736
ImportError: 'Content'/'Part' from 'google.generativeai.types' with Python 3.12.3 and google-generativeai 0.8.5 · Issue #736 · google-gemini/deprecated-generative-ai-python
June 6, 2025 - import os import google.generativeai as genai import logging from google.generativeai.types import Content, Part # This line causes the ImportError logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') def run_test(): try: api_key = os.getenv("GEMINI_API_KEY") if not api_key: logging.error("GEMINI_API_KEY environment variable not set.
Author   google-gemini