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?')] )
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 - Pydantic model types are available in the types module. The client.models module exposes model inferencing and model getters. See the 'Create a client' section above to initialize a client. response = client.models.generate_content( model='gemini-3.5-flash', contents='Why is the sky blue?' ) print(response.text) from google.genai import types response = client.models.generate_content( model='gemini-3.1-flash-image', contents='A cartoon infographic for flying sneakers', config=types.GenerateContentConfig( response_modalities=["IMAGE"], image_config=types.ImageConfig( aspect_ratio="9:16", ), ), ) for part in response.parts: if part.inline_data: generated_image = part.as_image() generated_image.show()
Starred by 3.8K users
Forked by 929 users
Languages Python
Videos
10:12
#04 Getting Started With Gemini API in Python | Handson Tutorial ...
12:07
Gemini API with Python - Getting Started Tutorial - YouTube
05:47
Google Gen AI SDK in Python made easy - New Unified API for Google ...
Getting Started With Google Gemini AI Python Library | Step-By-Step ...
GitHub
github.com › googleapis › python-genai › blob › main › codegen_instructions.md
python-genai/codegen_instructions.md at main · googleapis/python-genai
from google import genai from google.genai import types # Define a function that the model can call (to access external information) def get_current_weather(city: str) -> str: """Returns the current weather in a given city.
Author googleapis
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)
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 - The genai.NewClient function created a client, but generative model operations were typically called on a separate GenerativeModel instance obtained from this client. Other services might have been accessed via distinct packages or patterns. import ( "github.com/google/generative-ai-go/genai" "github.com/google/generative-ai-go/genai/fileman" // For files "google.golang.org/api/option" ) client, err := genai.NewClient(ctx, option.WithAPIKey("GEMINI_API_KEY")) fileClient, err := fileman.NewClient(ctx, option.WithAPIKey("GEMINI_API_KEY")) // Get a model instance, then call methods on it model := client.GenerativeModel("gemini-3.5-flash") resp, err := model.GenerateContent(...) cs := model.StartChat() // Call methods on separate client objects for other services uploadedFile, err := fileClient.UploadFile(...)
PyPI
pypi.org › project › google-genai
google-genai · PyPI
2 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'} )
» pip install google-genai
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. caching module · 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
GitHub
github.com › google-gemini › generative-ai-python › blob › main › google › generativeai › types › generation_types.py
deprecated-generative-ai-python/google/generativeai/types/generation_types.py at main · google-gemini/deprecated-generative-ai-python
This SDK is now deprecated, use the new unified Google GenAI SDK. - deprecated-generative-ai-python/google/generativeai/types/generation_types.py at main · google-gemini/deprecated-generative-ai-python
Author google-gemini
GitHub
raw.githubusercontent.com › googleapis › python-genai › refs › heads › main › README.md
Google Gen AI SDK
We recommend using our Code Generation instructions [`codegen_instructions.md`](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features. Copy and paste the instructions into your development environment to provide the model with the necessary context. ## Installation ```sh pip install google-genai ``` <small>With `uv`:</small> ```sh uv pip install google-genai ``` ## Imports ```python from google import genai from google.genai import types ``` ## Create a client Please run one of the following code blocks to create a client for different services ([Gemini Developer API](https://ai.google.dev/gemini-api/docs) or [Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/overview)).
Instructor
python.useinstructor.com › integrations › genai
Structured outputs with Google's genai SDK - Instructor
from instructor.processing.multimodal import Image from pydantic import BaseModel, Field import instructor from google.genai import Client class ImageDescription(BaseModel): objects: list[str] = Field(..., description="The objects in the image") scene: str = Field(..., description="The scene of the image") colors: list[str] = Field(..., description="The colors in the image") client = instructor.from_provider("google/gemini-2.5-flash") url = "https://raw.githubusercontent.com/instructor-ai/instructor/main/tests/assets/image.jpg" # Multiple ways to load an image: response = client.create( respon
GitHub
github.com › googleapis › java-genai
GitHub - googleapis/java-genai: Google Gen AI Java SDK provides an interface for developers to integrate Google's generative models into their Java applications. · GitHub
May 5, 2026 - package <your package name>; import com.google.common.collect.ImmutableList; import com.google.genai.Client; import com.google.genai.types.Content; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Part; public class GenerateContentWithImageInput { public static void main(String[] args) { // Instantiate the client using Gemini Enterprise Agent Platform API. The client gets the project and // location from the environment variables `GOOGLE_CLOUD_PROJECT` and // `GOOGLE_CLOUD_LOCATION`. Client client = Client.builder().enterprise(true).build(); // Construct a m
Starred by 377 users
Forked by 115 users
Languages Java
Go Packages
pkg.go.dev › github.com › google › generative-ai-go › genai
genai package - github.com/google/generative-ai-go/genai - Go Packages
May 2, 2025 - The embedding generated from the input content. Embedding *ContentEmbedding } EmbedContentResponse is the response to an `EmbedContentRequest`. type EmbeddingBatch struct { // contains filtered or unexported fields } An EmbeddingBatch holds a collection of embedding requests. ... package main import ( "context" "fmt" "log" "os" "github.com/google/generative-ai-go/genai" "google.golang.org/api/option" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY"))) if err != nil { log.Fatal(err) } defer client.Close() em := client.EmbeddingModel("embedding-001") b := em.NewBatch().
GitHub
github.com › google-gemini › genai-processors
GitHub - google-gemini/genai-processors: GenAI Processors is a lightweight Python library that enables efficient, parallel content processing. · GitHub
from typing import AsyncIterable from genai_processors import content_api from genai_processors import processor class EchoProcessor(processor.Processor): # The PRODUCER interface (for the processor author): # Takes a robust ProcessorStream as input, and yields part types.
Starred by 2.1K users
Forked by 215 users
Languages Python 77.7% | Jupyter Notebook 14.0% | HTML 8.3%
GitHub
github.com › googleapis › python-genai › issues › 106
[genai-module][models] Support automatic function calling in generate_content_stream · Issue #106 · googleapis/python-genai
January 9, 2025 - Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design. ... import os from google import genai from google.genai import types from google.genai.types import ( GoogleSearch, ) client = genai.Client(api_key=os.environ["GEMINI_API_KEY"]) def search(query: str) -> str: return query # mytools = [{"google_search": GoogleSearch()}] mytools = [search] generation_config = types.GenerateContentConfig( temperature=1, top_p=0.95, top_k=40, max_output_tokens=8192, tools=mytools, ) params = { "model": "gemini-2.0-flash-exp", "config": generation_config, "contents": "Search something about hongkong", } for chunk in client.models.generate_content_stream(**params): print(chunk.text)
Author googleapis
GitHub
github.com › GoogleCloudPlatform › generative-ai › blob › main › gemini › getting-started › intro_genai_sdk.ipynb
generative-ai/gemini/getting-started/intro_genai_sdk.ipynb at main · GoogleCloudPlatform/generative-ai
"cell_type": "code", "execution_count": null, "metadata": { "id": "qgdSpVmDbdQ9" }, "outputs": [], "source": [ "import datetime\n", "\n", "from google import genai\n", "from google.genai.types import (\n", " CreateBatchJobConfig,\n", " CreateCachedContentConfig,\n", " EmbedContentConfig,\n", " FunctionDeclaration,\n", " GenerateContentConfig,\n", " HarmBlockThreshold,\n", " HarmCategory,\n", " Part,\n", " SafetySetting,\n",
Author GoogleCloudPlatform
GitHub
googleapis.github.io › js-genai
@google/genai
If you are not redirected automatically, click here to go to the release version docs
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 for TypeScript and JavaScript is available on npm and GitHub: ... # Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_C...
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
GitHub
github.com › googleapis › python-genai › blob › main › google › genai › live.py
python-genai/google/genai/live.py at main · googleapis/python-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'; ·
Author googleapis