🌐
GitHub
googleapis.github.io › python-genai
Google Gen AI SDK documentation
If your image is stored in your local file system, you can read it in as bytes data and use the from_bytes class method to create a Part object. from google.genai import types YOUR_IMAGE_PATH = 'your_image_path' YOUR_IMAGE_MIME_TYPE = 'your_image_mime_type' with open(YOUR_IMAGE_PATH, 'rb') as f: image_bytes = f.read() for chunk in client.models.generate_content_stream( model='gemini-2.5-flash', contents=[ 'What is this image about?', types.Part.from_bytes(data=image_bytes, mime_type=YOUR_IMAGE_MIME_TYPE), ], ): print(chunk.text, end='')
🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › google gen ai sdk
Google Gen AI SDK | Gemini Enterprise Agent Platform | Google Cloud Documentation
* * <p>mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.GenerateContent" * -Dexec.args="YOUR_MODEL_ID" */ package com.google.genai.examples; import com.google.genai.Client; import com.google.genai.types.GenerateContentResponse; /** An example of using the Unified Gen AI Java SDK to generate content.
🌐
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.
Starred by 377 users
Forked by 115 users
Languages   Java
🌐
PyPI
pypi.org › project › google-genai
google-genai · PyPI
2 weeks ago - If your image is stored in your local file system, you can read it in as bytes data and use the from_bytes class method to create a Part object. from google.genai import types YOUR_IMAGE_PATH = 'your_image_path' YOUR_IMAGE_MIME_TYPE = 'your_image_mime_type' with open(YOUR_IMAGE_PATH, 'rb') as f: image_bytes = f.read() for chunk in client.models.generate_content_stream( model='gemini-3.5-flash', contents=[ 'What is this image about?', types.Part.from_bytes(data=image_bytes, mime_type=YOUR_IMAGE_MIME_TYPE), ], ): print(chunk.text, end='')
      » pip install google-genai
    
Published   Jun 24, 2026
Version   2.10.0
🌐
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 - If your image is stored in your local file system, you can read it in as bytes data and use the from_bytes class method to create a Part object. from google.genai import types YOUR_IMAGE_PATH = 'your_image_path' YOUR_IMAGE_MIME_TYPE = 'your_image_mime_type' with open(YOUR_IMAGE_PATH, 'rb') as f: image_bytes = f.read() for chunk in client.models.generate_content_stream( model='gemini-3.5-flash', contents=[ 'What is this image about?', types.Part.from_bytes(data=image_bytes, mime_type=YOUR_IMAGE_MIME_TYPE), ], ): print(chunk.text, end='')
Starred by 3.8K users
Forked by 929 users
Languages   Python
🌐
GitHub
googleapis.github.io › python-genai › genai.html
Submodules - Google Gen AI SDK documentation
For tuned models, the model name starts with ‘tunedModels/’, for example: ‘tunedModels/1234567890123456789’ · Some models support multimodal input and output. Built-in MCP support is an experimental feature. ... from google.genai import types from google import genai client = genai.Client( vertexai=True, project='my-project-id', location='us-central1' ) async for chunk in await client.aio.models.generate_content_stream( model='gemini-2.0-flash', contents='''What is a good name for a flower shop that specializes in selling bouquets of dried flowers?''' ): print(chunk.text) # **Elegant
🌐
GitHub
github.com › googleapis › python-genai › blob › main › google › genai › types.py
python-genai/google/genai/types.py at main · googleapis/python-genai
Google Gen AI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications. - python-genai/google/genai/types.py at main · googleapis/python-genai
Author   googleapis
🌐
npm
npmjs.com › package › @google › genai
google/genai
1 week ago - NOTE: This doesn't apply to FunctionCall and FunctionResponse parts, if you are specifying those, you need to explicitly provide the full Content[] structure making it explicit which Parts are 'spoken' by the model, or the user. The SDK will throw an exception if you try this. To handle errors raised by the API, the SDK provides this ApiError class. 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() { await ai.models.generateContent({ model: 'non-existent-model', contents: 'Write a 100-word poem.', }).catch((e) => { console.error('error name: ', e.name); console.error('error message: ', e.message); console.error('error status: ', e.status); }); } main();
      » npm install @google/genai
    
Published   Jun 24, 2026
Version   2.10.0
🌐
Instructor
python.useinstructor.com › integrations › genai
Structured outputs with Google's genai SDK - Instructor
This is particularly useful for dynamic content or when testing different inputs: from google import genai import instructor from pydantic import BaseModel from google.genai import types # Define your Pydantic model class User(BaseModel): name: str age: int # Initialize and patch the client client = instructor.from_provider("google/gemini-2.5-flash") # Single string (converted to user message) response = client.create( messages=[{"role": "user", "content": "{{ name }} is {{ age }} years old"}], response_model=User, context={ "name": "Jason", "age": 25, }, ) print(response) # > name='Jason' age
Find elsewhere
🌐
Go Packages
pkg.go.dev › google.golang.org › genai
genai package - google.golang.org/genai - Go Packages
3 weeks ago - This SDK supports use cases like: ... For example, with just a few lines of code, you can access Gemini's multimodal capabilities to generate text from text-and-image input. parts := []*genai.Part{ {Text: "What's this image about?"}, {InlineData: &genai.Blob{Data: imageBytes, MIMEType: ...
🌐
Google
googleapis.dev › python › generativelanguage › latest › _modules › google › ai › generativelanguage_v1 › types › content.html
google.ai.generativelanguage_v1.types.content — google-ai-generativelanguage documentation
Attributes: mime_type (str): The IANA standard MIME type of the source data. Examples: - image/png - image/jpeg If an unsupported MIME type is provided, an error will be returned. For a complete list of supported types, see `Supported file formats <https://ai.google.dev/gemini-api/docs/prompting_with_media#supported_file_formats>`__.
🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › content
Content | Gemini Enterprise Agent Platform | Google Cloud Documentation
March 3, 2026 - A FunctionResponsePart must have a fixed IANA MIME type identifying the type and subtype of the media if the inlineData field is filled with raw bytes. ... The data of the function response part.
🌐
GitHub
googleapis.github.io › dotnet-genai
| Google GenAI .NET SDK
using System.Threading.Tasks; using Google.GenAI; using Google.GenAI.Types; public class CreateCache { public static async Task main() { // Example for Gemini Enterprise Agent Platform with GCS URIs: var enterpriseClient = new Client(project: project, location: location, enterprise: true); var agenterpriseConfig = new CreateCachedContentConfig { Contents = new List<Content> { new Content { Role = "user", Parts = new List<Part> { new Part { FileData = new FileData { FileUri = "gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf", MimeType = "application/pdf" } }, new Part { FileData = ne
🌐
Google AI
ai.google.dev › gemini api › generating content
Generating content | Gemini API | Google AI for Developers
May 20, 2026 - What would you like to know?", genai.RoleModel), } chat, err := client.Chats.Create(ctx, "gemini-3.5-flash", nil, history) if err != nil { log.Fatal(err) } firstResp, err := chat.SendMessage(ctx, genai.Part{Text: "I have 2 dogs in my house."}) if err != nil { log.Fatal(err) } fmt.Println(firstResp.Text()) secondResp, err := chat.SendMessage(ctx, genai.Part{Text: "How many paws are in my house?"}) if err != nil { log.Fatal(err) } fmt.Println(secondResp.Text()) chat.go · curl https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=$GEMINI_API_KEY \ -H 'Content-Type: application/json' \ -X POST \ -d '{ "contents": [ {"role":"user", "parts":[{ "text": "Hello"}]}, {"role": "model", "parts":[{ "text": "Great to meet you.
🌐
GitHub
github.com › googleapis › python-genai › blob › main › codegen_instructions.md
python-genai/codegen_instructions.md at main · googleapis/python-genai
While the simpler API call is often sufficient, you may run into scenarios where you need to work directly with the underlying Content and Part objects for more explicit control. These are the fundamental building blocks of the generate_content API. For instance, the following simple API call: from google import genai client = genai.Client() response = client.models.generate_content( model='gemini-3-flash-preview', contents='How does AI work?' ) print(response.text) is effectively a shorthand for this more explicit structure: from google import genai from google.genai import types client = genai.Client() response = client.models.generate_content( model='gemini-3-flash-preview', contents=[ types.Content(role='user', parts=[types.Part.from_text(text='How does AI work?')]), ] ) print(response.text) The list of APIs and capabilities above are not comprehensive.
Author   googleapis
🌐
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 - Args: location: required, The city and state, e.g. San Franciso, CA unit: celsius or fahrenheit """ print(f'Called with: {location=}') return "23C" model = genai.GenerativeModel( model_name="gemini-3.5-flash", tools=[get_current_weather] ) response = model.generate_content("What is the weather in San Francisco?") function_call = response.candidates[0].parts[0].function_call · After · In the new SDK, automatic function calling is the default. Here, you disable it. from google import genai from google.genai import types client = genai.Client() def get_current_weather(location: str) -> str: """Get the current whether in a given location.
🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › generate content with the gemini api
Generate content with the Gemini API | 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?", ) print(response.text) # Example response: # Okay, let's break down how AI works.
🌐
Google
docs.cloud.google.com › python › client libraries › vertex generative ai sdk for python
Vertex Generative AI SDK for Python | Python client libraries | Google Cloud Documentation
prompt = { "prompt_data": { "contents": [{"parts": [{"text": "Hello, {name}! How are you?"}]}], "system_instruction": {"parts": [{"text": "Please answer in a short sentence."}]}, "variables": [ {"name": {"text": "Alice"}}, ], "model": "gemini-2.5-flash", }, } prompt_resource = client.prompts.create( prompt=prompt, ) Note that you can also use the types.Prompt object to define your prompt. Some of the types used to do this are from the Gen AI SDK. import types from google.genai import types as genai_types prompt = types.Prompt( prompt_data=types.PromptData( contents=[genai_types.Content(parts=[genai_types.Part(text="Hello, {name}! How are you?")])], system_instruction=genai_types.Content(parts=[genai_types.Part(text="Please answer in a short sentence.")]), variables=[ {"name": genai_types.Part(text="Alice")}, ], model="gemini-2.5-flash", ), )
🌐
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 - FunctionCalls return all the FunctionCall parts in the candidate. type ChatSession struct { History []*Content // contains filtered or unexported fields } A ChatSession provides interactive chat. ... This example shows how to set the History field on ChatSession explicitly. 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() model := client.GenerativeModel("gemini-1.5-flash") cs := model.StartChat() cs.History = []*genai.Content{ { Parts: []genai.Part{ genai.Text("Hello, I have 2 dogs in my house."), }, Role: "user", }, { Parts: []genai.Part{ genai.Text("Great to meet you.