Google GenAI Plugin
This Genkit plugin provides a unified interface for Google AI (Gemini) and Vertex AI models, embedding, and other services.
Building with a coding agent? Install the Genkit Python skill first.
npx skills add genkit-ai/skills --skill developing-genkit-pythonIt teaches your agent the current Genkit Python APIs and common gotchas. Source, manual install and skills for other languages: genkit-ai/skills.
Setup environment
uv add genkit genkit-google-genai
Configuration
Google AI (AI Studio)
To use Google AI models, obtain an API key from Google AI Studio and set it in your environment:
export GEMINI_API_KEY='<your-api-key>'
Vertex AI (Google Cloud)
To use Vertex AI models, ensure you have a Google Cloud project and Application Default Credentials (ADC) set up:
gcloud auth application-default login
Quickstart
from genkit import Genkit
from genkit_google_genai import GoogleAI
# 1. Initialize Genkit with plugin and default model reference
ai = Genkit(plugins=[GoogleAI()], model=GoogleAI.gemini('gemini-flash-latest'))
# 2. Define a typed flow
@ai.flow()
async def greet(name: str) -> str:
res = await ai.generate(prompt=f'Say hello to {name}.')
return res.text
# 3. Execute and inspect output
print(await greet('Grace'))
# => Hello Grace! How can I help you today?
Features
Dynamic Models
The plugin automatically discovers available models from the API upon initialization. You can use any model name supported by the API via model reference constructors (e.g., GoogleAI.gemini('gemini-flash-latest'), VertexAI.gemini('gemini-3.1-pro-preview')).
Typed config
Config classes take flat snake_case keyword arguments, so pyright, pyrefly
and ty check every key. The plugin builds Gemini's nested request objects
(thinkingConfig, speechConfig, tools) when it sends the request. The Dev
UI and .prompt files use the same flat fields in camelCase
(thinkingLevel); both spellings validate at runtime.
Text generation with GeminiConfig and tool_choice
from genkit import Genkit
from genkit_google_genai import GeminiConfig, GoogleAI
# 1. Initialize plugin and client
ai = Genkit(plugins=[GoogleAI()])
# 2. Define a function tool
@ai.tool()
async def check_inventory(ingredient: str) -> dict[str, int]:
return {'pesto': 12, 'pine_nuts': 4}
# 3. Generate with flat thinking, safety, search grounding, and a tool
res = await ai.generate(
model=GoogleAI.gemini('gemini-flash-latest'),
prompt='Check pesto inventory and cite current safety storage guidelines.',
tools=[check_inventory],
config=GeminiConfig(
thinking_level='HIGH',
include_thoughts=True,
safety_settings=[
{'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold': 'BLOCK_ONLY_HIGH'},
],
google_search=True,
),
)
print(res.text)
# => Inventory verified: 12 jars of pesto in stock. Storage guidelines require refrigeration at 40°F (4°C) or below after opening.
Audio generation with GeminiTtsConfig
from genkit import Genkit
from genkit_google_genai import GeminiTtsConfig, GoogleAI
ai = Genkit(plugins=[GoogleAI()])
# Generate multi-speaker audio dialog
res = await ai.generate(
model=GoogleAI.gemini_tts('gemini-2.5-flash-preview-tts'),
prompt='Host: Welcome to Morning Roaster. Chef: Today we review Ethiopian beans.',
config=GeminiTtsConfig(
speakers={'Host': 'Kore', 'Chef': 'Puck'},
language_code='en-US',
),
)
print(res.media.url)
# => data:audio/wav;base64,UklGRiQAAABXQVZFZ...
Image generation with GeminiImageConfig
from genkit import Genkit
from genkit_google_genai import GeminiImageConfig, GoogleAI
ai = Genkit(plugins=[GoogleAI()])
# Generate high-resolution image with specified aspect ratio and size
res = await ai.generate(
model=GoogleAI.gemini_image('gemini-2.5-flash-preview-image-generation'),
prompt='A modern minimalist espresso bar with warm cedar accents.',
config=GeminiImageConfig(
aspect_ratio='16:9',
image_size='2K',
),
)
print(res.media.url)
# => data:image/png;base64,iVBORw0KGgoAAAANSU...
Default config on model references
Pass a config instance directly to GoogleAI.gemini(...) or VertexAI.gemini(...) to configure defaults that every call inherits:
model = GoogleAI.gemini(
'gemini-flash-latest',
config=GeminiConfig(temperature=0.7, thinking_level='MEDIUM'),
)
Config rules and validation
Choice fields take plain strings. The Literal aliases (ThinkingLevel,
HarmCategory, ImageAspectRatio, ...) export from the package root for
annotating your own code. safety_settings entries are SafetySetting
TypedDicts: pass a dict literal or SafetySetting(category=..., threshold=...).
Setting any google_search_* option turns Google Search on;
google_search=False next to an option raises. A nested key such as
thinkingConfig raises and names the flat fields that replace it.
timeout sets the HTTP timeout for one request, in seconds:
GeminiConfig(timeout=30). 0, negative, inf, NaN and bool raise. On GoogleAI,
the Gemini API rejects server deadlines under 10 seconds with HTTP 400
(VertexAI accepts shorter values).
Function calling mode is controlled by ai.generate(tool_choice=...), not config:
'auto', 'required', or 'none'. In 'required' mode, Gemini binds the request's
function tools as allowedFunctionNames.
Settings that can't be combined raise before anything is sent:
thinking_levelwiththinking_budget, andvoicewithspeakers. When one comes from a model reference default, passNonefor it on the call.google_search_start_timewithoutgoogle_search_end_time, andfile_search_top_korfile_search_metadata_filterwithoutfile_search_store_names.- Vertex AI only settings on the Gemini API:
google_search_exclude_domains,google_search_blocking_confidence, safetymethod,output_mime_type,output_compression_quality,person_generation,prominent_people.
A cloned (replicated) voice has no flat field; send it through extra:
config = GeminiTtsConfig(
extra={'generationConfig': {'speechConfig': {'voiceConfig': {'replicatedVoiceConfig': {
'mimeType': 'audio/wav',
'voiceSampleAudio': sample_b64,
'consentAudio': consent_b64,
}}}}},
)
Provider fields the plugin doesn't declare
Gemini, Gemini image, and Veo configs reject keys they don't declare, so a
typo like temprature fails before the request is sent. A request field the
schema doesn't declare yet goes in extra under its REST wire name. It's
merged over the top of the request body, recursing into nested objects:
from genkit_google_genai import GeminiConfig
config = GeminiConfig.model_validate({
'temperature': 1.0,
'extra': {
'generationConfig': {'newKnob': 1}, # adds one key to generationConfig
'labels': {'team': 'search'}, # Vertex AI request labels
},
})
extra can't set the fields Genkit builds from the request (contents,
systemInstruction, tools, toolConfig, the structured-output fields of
generationConfig, cachedContent); those raise INVALID_ARGUMENT.
Antigravity, Interactions Lyria, and Deep Research also reject unknown keys
and take undeclared fields in extra, which is merged into the Interactions
create body (snake_case names). A nested object merges key by key. Keys match
ignoring case and underscores, the same way the Gemini merge aligns them. A
None value means unset and is skipped. Like Gemini, fields Genkit builds from
the request raise in extra: the model id (agent, or model on Lyria),
input, tools (on Deep Research and Lyria), and Lyria's system_instruction.
Deep Research declares its tools as flat config fields (google_search,
url_context, code_execution, file_search_store_names, mcp_servers).
Antigravity enables google_search, url_context, and code_execution by
default when tools is omitted; extra={'tools': [...]} overrides that with an
explicit allowlist of Interactions tool dicts ({'type': 'google_search'},
{'type': 'mcp_server', ...}, etc.), generate(tools=...) appends client
function tools after extra['tools'] and continues stored interactions across
turns via previous_interaction_id and environment_id, and
extra={'tools': []} raises because the API reads an empty tools list as
unset. Lyria takes no tools, and neither Deep Research nor Lyria supports
function tools (generate(tools=...) raises). Blocks with defaults, such as
agent_config and environment, merge key by key.
timeout on these three configs (and in Deep Research's check_operation /
cancel_operation config) is the HTTP timeout in seconds. It used to be
milliseconds: config={'timeout': 30000} becomes config={'timeout': 30}.
op = await ai.generate_operation(
model='googleai/deep-research-preview-04-2026',
prompt='Summarize recent advances in quantum error correction.',
config={'thinking_summaries': 'auto', 'extra': {'agent_config': {'visualization': 'auto'}}},
)
# create body: {..., "agent_config": {"type": "deep-research",
# "thinking_summaries": "auto", "visualization": "auto"}}
Structured output
Set the output schema on the request; the plugin sends it to Gemini as
responseJsonSchema, so anyOf, $ref, additionalProperties and numeric
bounds reach the model as written.
from pydantic import BaseModel
class Country(BaseModel):
name: str
capital: str
population: int
response = await ai.generate(prompt='Give quick facts about Japan.', output_schema=Country)
print(response.output)
To send the schema as the older OpenAPI-style responseSchema field instead,
construct the plugin with GoogleAI(legacy_response_schema=True) or
VertexAI(legacy_response_schema=True). The schema is converted to that shape.
Keywords the conversion does not map, such as pattern, minLength,
additionalProperties and an anyOf or oneOf next to a type, are left
out, as are a $ref back to a model that contains it, an array with no
convertible items and a map (an object with additionalProperties and no
properties, such as dict[str, int]). It raises INVALID_ARGUMENT for a constraint with no
type (an enum of strings counts as a string), for a type list, anyOf
or oneOf that would lose some but not all of its non-null branches, for a
required property or whole schema that cannot be converted, and for an
unresolvable $ref, an unsupported type or a keyword value it cannot read.
Constrained enum output always goes out this way, as text/x.enum with a
converted responseSchema.
Video generation (Veo)
Video is a job, not a round-trip. generate_operation hands back a ticket;
check_operation is how you find out when the video is ready. When the job
finishes, operation.output has a playable media.url — Studio sends a
download URL, Vertex often sends the mp4 inline.
With GoogleAI:
from genkit import Genkit
from genkit_google_genai import GoogleAI
# 1. Initialize Genkit with GoogleAI
ai = Genkit(plugins=[GoogleAI()])
# 2. Launch background video generation
operation = await ai.generate_operation(
model=GoogleAI.veo('veo-3.1-fast-generate-preview'),
prompt='A paper airplane gliding through a bright classroom',
)
while not operation.done:
operation = await ai.check_operation(operation)
# 3. Access output media artifact
print(operation.output.message.content[0].media.url)
# => https://generativelanguage.googleapis.com/v1beta/files/preview.mp4
With VertexAI:
from genkit import Genkit
from genkit_google_genai import VertexAI
# 1. Initialize Genkit with VertexAI
ai = Genkit(plugins=[VertexAI()])
# 2. Launch background video generation
operation = await ai.generate_operation(
model=VertexAI.veo('veo-3.1-generate-001'),
prompt='A paper airplane gliding through a bright classroom',
)
while not operation.done:
operation = await ai.check_operation(operation)
# 3. Access output media artifact
print(operation.output.message.content[0].media.url)
# => gs://my-bucket/videos/output.mp4
Runnable version: google-genai-media.
Virtual Try-On (Vertex AI)
virtual-try-on-001 dresses a person in a product and returns the composited
images. The inputs are media parts on the last message, tagged so the model
knows which is which: metadata={'type': 'personImage'} for the person and
metadata={'type': 'productImage'} for the product. Each url is a data:
url, bare base64 image data, or a gs:// path; http(s) urls are not fetched.
from genkit import Genkit, Message, Part, Role
from genkit_google_genai import VertexAI
ai = Genkit(plugins=[VertexAI()])
response = await ai.generate(
model=VertexAI.virtual_try_on('virtual-try-on-001'),
messages=[
Message(
role=Role.USER,
content=[
Part.from_media(
'gs://my-bucket/person.png', content_type='image/png', metadata={'type': 'personImage'}
),
Part.from_media(
'gs://my-bucket/shirt.png', content_type='image/png', metadata={'type': 'productImage'}
),
],
)
],
)
for part in response.message.content:
print(part.media.url)
Vertex AI Evaluators
Built-in evaluators for assessing model output quality, accessed via ai.evaluate(). The VertexAI plugin registers them only when a project resolves (VertexAI(project=...) or GOOGLE_CLOUD_PROJECT); VertexAI(api_key=...) without a project lists none. They authenticate with Application Default Credentials, not api_key or credentials:
from genkit import Genkit
from genkit.evaluator import BaseDataPoint
from genkit_google_genai import VertexAI
ai = Genkit(plugins=[VertexAI(project='my-project')])
# Prepare test dataset
dataset = [
BaseDataPoint(
input='Write about AI.',
output='AI is transforming industries through intelligent automation.',
),
]
# Evaluate fluency (scores 1-5)
results = await ai.evaluate(
evaluator='vertexai/fluency',
dataset=dataset,
)
for result in results:
print(f'Score: {result.evaluation[0].score}')
Runnable snippets are in py/samples.
Metadata
Release files for genkit-google-genai 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| genkit_google_genai-0.13.0.tar.gz | 239.5 kB | With provenance | Details for genkit_google_genai-0.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| genkit_google_genai-0.13.0-py3-none-any.whl | Python 3 | none | any | Details for genkit_google_genai-0.13.0-py3-none-any.whl |
Total release size: 373.6 kB
Release files / genkit_google_genai-0.13.0.tar.gz
| Download URL | genkit_google_genai-0.13.0.tar.gz |
|---|---|
| Size | 239.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
422546f61ea7b3df08fcb916ed5d3b205259c0daa4598fff688c9f9b4a9a9f6b
|
|
BLAKE2b-256 checksum How to use checksums |
299fdd8980f6033c86ddccc9b83e0b717c7e19177a49590fa183ca5dd4e5ae2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / genkit_google_genai-0.13.0-py3-none-any.whl
| Download URL | genkit_google_genai-0.13.0-py3-none-any.whl |
|---|---|
| Size | 134.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
90c1408d07619585341b676faffe286de296cffba1012efc75c835f2280b549b
|
|
BLAKE2b-256 checksum How to use checksums |
f00f89897c11abacafa2ba5ba1d9cb712bbe43557b5693be54e884bc20391b15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for genkit-google-genai 0.13.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for genkit_google_genai-0.13.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.