Skip to main content

Google GenAI Plugin

This Genkit plugin provides a unified interface for Google AI (Gemini) and Vertex AI models, embedding, and other services.

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

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


@ai.flow()
async def greet(name: str) -> str:
    res = await ai.generate(prompt=f'Say hello to {name}.')
    return res.text

Features

Dynamic Models

The plugin automatically discovers available models from the API upon initialization. You can use any model name supported by the API (e.g., GoogleAI.gemini_model('gemini-flash-latest'), VertexAI.gemini_model('gemini-2.5-pro')).

Dynamic Configuration

Unrecognized provider parameters on the family config are forwarded to the API:

from genkit_google_genai import GeminiConfigSchema

config = GeminiConfigSchema.model_validate({
    'temperature': 1.0,
    'response_modalities': ['TEXT', 'IMAGE'],
})

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

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

operation = await ai.generate_operation(
    model=GoogleAI.veo_model('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)
print(operation.output)

With VertexAI:

from genkit import Genkit
from genkit_google_genai import VertexAI

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

operation = await ai.generate_operation(
    model=VertexAI.veo_model('veo-3.1-generate-001'),
    prompt='A paper airplane gliding through a bright classroom',
)
while not operation.done:
    operation = await ai.check_operation(operation)
print(operation.output)

Runnable version: google-genai-media.

Vertex AI Evaluators

Built-in evaluators for assessing model output quality. Evaluators are automatically registered when using the VertexAI plugin and are accessed via ai.evaluate():

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.root:
    print(f'Score: {result.evaluation.score}')

Runnable snippets are in py/samples.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genkit_google_genai-0.11.0.tar.gz (94.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

genkit_google_genai-0.11.0-py3-none-any.whl (73.1 kB view details)

Uploaded Python 3

File details

Details for the file genkit_google_genai-0.11.0.tar.gz.

File metadata

  • Download URL: genkit_google_genai-0.11.0.tar.gz
  • Upload date:
  • Size: 94.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for genkit_google_genai-0.11.0.tar.gz
Algorithm Hash digest
SHA256 32a1a585e3f5e1fe9daa1ce63e3eb527333c0f5305797de85c6856ef9234845d
MD5 fd55af416785b313e90ebea506e64c68
BLAKE2b-256 419d250d2efabd584c0e5052f5d482caefb4ba0c71bfcf7b465111ba62364be7

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_google_genai-0.11.0.tar.gz:

Publisher: publish_python.yml on genkit-ai/genkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genkit_google_genai-0.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for genkit_google_genai-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a453bce937fbe0fb6aec5582c363c66bb86df468c8938d64b0251d86b662f1ec
MD5 9b5944c9635ec40a6e3931a7620c1b17
BLAKE2b-256 bd82cf422f779b6a41fa2b29988eb06025c3d10182c8d6b26e5b14ac05e44114

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_google_genai-0.11.0-py3-none-any.whl:

Publisher: publish_python.yml on genkit-ai/genkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 files

0.10.0

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

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