Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

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-python

It 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 init my-genkit-app && cd my-genkit-app
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>'

GOOGLE_API_KEY and GOOGLE_GENAI_API_KEY are read next, in that order. For a per-tenant key, start GoogleAI() with no key and pass context={'secrets': {'api_key': tenant_key}} on each generate, generate_operation, check_operation, embed, or embed_many call. With no key from any of these, GoogleAI() logs one warning when it's constructed (to stderr unless your app configures logging), and a call with no plugin key and no secret fails with FAILED_PRECONDITION. A key the API rejects fails with UNAUTHENTICATED and reason=ErrorReason.INVALID_CREDENTIALS, carrying the API's message.

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. Call the flow from main and run it
async def main() -> None:
    print(await greet('Grace'))
    # => Hello Grace! How can I help you today?


if __name__ == '__main__':
    ai.run_main(main())

Features

Dynamic Models

The plugin registers a static catalog of known models at startup, with no network call, so a rate-limited or offline project still starts. Any other model id resolves by name on first use. The live model list is fetched only when the Dev UI lists actions, then cached for the process. 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 and safety settings, and let the model call the tool
async def main() -> None:
    res = await ai.generate(
        model=GoogleAI.gemini('gemini-flash-latest'),
        prompt='How many jars of pesto do we have, and how should opened jars be stored?',
        tools=[check_inventory],
        tool_choice='auto',
        config=GeminiConfig(
            thinking_level='HIGH',
            include_thoughts=True,
            safety_settings=[
                {'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold': 'BLOCK_ONLY_HIGH'},
            ],
        ),
    )
    print(res.text)
    # => We have 12 jars of pesto in stock. Refrigerate opened jars and use
    #    them within 7 to 10 days.


if __name__ == '__main__':
    ai.run_main(main())

Audio generation with GeminiTtsConfig

from genkit import Genkit
from genkit_google_genai import GeminiTtsConfig, GoogleAI

ai = Genkit(plugins=[GoogleAI()])


# Generate multi-speaker audio dialog
async def main() -> None:
    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 if res.media else '')
    # => data:audio/L16;codec=pcm;rate=24000;base64,AAAAAP7/AQD+/w...


if __name__ == '__main__':
    ai.run_main(main())

Gemini returns raw 16-bit PCM at 24 kHz. Wrap it in a WAV header (stdlib wave) before saving to .wav.

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
async def main() -> None:
    res = await ai.generate(
        model=GoogleAI.gemini_image('gemini-3.1-flash-image'),
        prompt='A modern minimalist espresso bar with warm cedar accents.',
        config=GeminiImageConfig(
            aspect_ratio='16:9',
            image_size='2K',
        ),
    )

    if res.media:
        print(res.media.url[:40])
        # => data:image/jpeg;base64,/9j/4AAQSkZJRgABA


if __name__ == '__main__':
    ai.run_main(main())

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 never reach Gemini:

  • thinking_level with thinking_budget, and voice with speakers, raise INVALID_ARGUMENT from generate (GeminiConfig(...) raises a Pydantic ValidationError on construction). When one comes from a model reference default, pass None for it on the call.

The model checks the rest when it builds the request. These don't raise: the call returns finish_reason='failed' with response.error.status == 'INVALID_ARGUMENT':

  • google_search_start_time without google_search_end_time, and file_search_top_k or file_search_metadata_filter without file_search_store_names.
  • Vertex AI only settings on the Gemini API: google_search_exclude_domains, google_search_blocking_confidence, safety method, 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.

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

from genkit import Genkit
from genkit_google_genai import GoogleAI

ai = Genkit(plugins=[GoogleAI()], model=GoogleAI.gemini('gemini-flash-latest'))


class Country(BaseModel):
    name: str
    capital: str
    population: int


async def main() -> None:
    response = await ai.generate(prompt='Give quick facts about Japan.', output_schema=Country)
    print(response.output)
    # => name='Japan' capital='Tokyo' population=123000000


if __name__ == '__main__':
    ai.run_main(main())

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:

import asyncio

from genkit import Genkit
from genkit_google_genai import GoogleAI

# 1. Initialize Genkit with GoogleAI
ai = Genkit(plugins=[GoogleAI()])

# 2. Launch background video generation and poll until it finishes
async def main() -> None:
    operation = await ai.generate_operation(
        model=GoogleAI.veo('veo-3.1-lite-generate-preview'),
        prompt='A paper airplane gliding through a bright classroom',
    )
    while not operation.done:
        await asyncio.sleep(5)
        operation = await ai.check_operation(operation)

    # 3. Read the finished video off the response
    if operation.output and operation.output.media:
        print(operation.output.media.url)
        # => https://generativelanguage.googleapis.com/v1beta/files/preview.mp4


if __name__ == '__main__':
    ai.run_main(main())

With VertexAI:

import asyncio

from genkit import Genkit
from genkit_google_genai import VertexAI

# 1. Initialize Genkit with VertexAI
ai = Genkit(plugins=[VertexAI()])

# 2. Launch background video generation and poll until it finishes
async def main() -> None:
    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:
        await asyncio.sleep(5)
        operation = await ai.check_operation(operation)

    # 3. Read the finished video off the response
    if operation.output and operation.output.media:
        print(operation.output.media.url)
        # => data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28y...


if __name__ == '__main__':
    ai.run_main(main())

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()])


async def main() -> None:
    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 media in response.media_parts:
        print(media.url)
        # => data:image/png;base64,iVBORw0KGgoAAAANSU...


if __name__ == '__main__':
    ai.run_main(main())

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')])


async def main() -> None:
    # 1. Prepare a test dataset
    dataset = [
        BaseDataPoint(
            input='Write about AI.',
            output='AI is transforming industries through intelligent automation.',
        ),
    ]

    # 2. Score fluency (1-5)
    results = await ai.evaluate(
        evaluator='vertexai/fluency',
        dataset=dataset,
    )

    for result in results:
        print(f'Score: {result.evaluation[0].score}')
        # => Score: 5


if __name__ == '__main__':
    ai.run_main(main())

Runnable snippets are in samples.

Metadata

Release files for genkit-google-genai 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

Source distribution for genkit-google-genai 0.14.0
File Size Uploaded Provenance Actions
genkit_google_genai-0.14.0.tar.gz 256.9 kB With provenance Details for genkit_google_genai-0.14.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for genkit-google-genai 0.14.0
File Interpreter ABI Platform Actions
genkit_google_genai-0.14.0-py3-none-any.whl Python 3 none any Details for genkit_google_genai-0.14.0-py3-none-any.whl

Total release size: 395.9 kB

Release files / genkit_google_genai-0.14.0.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL genkit_google_genai-0.14.0.tar.gz
Size 256.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a77e4c43e5ab221f2d9196373c2cf37b626338b91fb721127eebdd7de0bb3876
BLAKE2b-256 checksum
How to use checksums
56e8b06218c19ab4381103d5d08c418bc66e1b94a2e9172ac3498456c77c8383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 19, 2026.

Transparency log

Release files / genkit_google_genai-0.14.0-py3-none-any.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL genkit_google_genai-0.14.0-py3-none-any.whl
Size 139.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b996b21453c0c113c8bf98190c3edf2f3571765448e8a9411f5839c88e5d30f
BLAKE2b-256 checksum
How to use checksums
440687e9066a6b45436cc02236451c10cdd600b09c6204f05925d8213f1f65ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 19, 2026.

Transparency log

Security for genkit-google-genai 0.14.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.

Change of provenance

The repository and configuration that created this release differ from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 2 files

Attestation for genkit_google_genai-0.14.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 19, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page