Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/genkit-ai/genkit/llms.txt

Use this file to discover all available pages before exploring further.

The @genkit-ai/google-genai package is the unified Google plugin for Genkit. It exports two initializers:
  • googleAI — connects to the Gemini Developer API (Google AI Studio). Best for prototyping, quick experiments, and apps that don’t need a Google Cloud project.
  • vertexAI — connects to Google Cloud Vertex AI. Best for production workloads, enterprise compliance, and access to Vertex-only features. See the Vertex AI plugin page for the full Vertex story.
This page covers googleAI.
The older @genkit-ai/googleai package is superseded by @genkit-ai/google-genai. Migrate by changing your import and plugin initializer — the model reference syntax is identical.

Installation

npm install @genkit-ai/google-genai

Configuration

API key

Obtain a free API key from Google AI Studio and set it as an environment variable:
export GEMINI_API_KEY=your_api_key
# GOOGLE_API_KEY is also accepted as a fallback
Or pass it directly at plugin init time (useful for testing, not recommended for production):
import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';

const ai = genkit({
  plugins: [
    googleAI(),
    // Or with an explicit key:
    // googleAI({ apiKey: process.env.MY_KEY }),
  ],
});

Plugin options (TypeScript)

The GoogleAIPluginOptions interface exposes these fields:
interface GoogleAIPluginOptions {
  /**
   * API key to authenticate with the Gemini API.
   * Defaults to GEMINI_API_KEY or GOOGLE_API_KEY env vars.
   * Set to `false` to require a per-request apiKey in model config.
   */
  apiKey?: string | false;

  /** Override the default API version (e.g. 'v1'). */
  apiVersion?: string;

  /** Override the default base URL. */
  baseUrl?: string;

  /** Additional headers sent with every request. */
  customHeaders?: Record<string, string>;

  /** Use legacy responseSchema field instead of responseJsonSchema. */
  legacyResponseSchema?: boolean;
}

Available models

The plugin dynamically discovers available models from the API. Pre-registered known models include:
Model nameBest for
gemini-2.5-proComplex reasoning, long context
gemini-2.5-flashFast, cost-effective general tasks
gemini-2.5-flash-liteLowest latency, simple tasks
gemini-2.5-flash-imageNative image output alongside text
gemini-2.5-flash-preview-ttsText-to-speech
gemini-2.5-pro-preview-ttsHigh-quality TTS
gemma-3-27b-itOpen-weight text generation
gemma-3-12b-itSmaller open-weight model
imagen-4.0-generate-001Photorealistic image generation
imagen-4.0-fast-generate-001Faster image generation
imagen-4.0-ultra-generate-001Highest quality image generation
gemini-embedding-001Text embeddings (768 dims)
gemini-embedding-2-previewMultimodal embeddings (3072 dims)
You can use any model ID supported by the underlying SDK — new models appear automatically without a plugin update.

Basic text generation

import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';

const ai = genkit({ plugins: [googleAI()] });

const response = await ai.generate({
  model: googleAI.model('gemini-2.5-flash'),
  prompt: 'Explain how neural networks learn.',
});

console.log(response.text);

Model configuration

Pass a GeminiConfig object alongside the model reference to tune generation:
const response = await ai.generate({
  model: googleAI.model('gemini-2.5-flash', {
    temperature: 0.7,
    maxOutputTokens: 1024,
    safetySettings: [
      {
        category: 'HARM_CATEGORY_HATE_SPEECH',
        threshold: 'BLOCK_ONLY_HIGH',
      },
    ],
    // Enable thinking for complex reasoning tasks
    thinkingConfig: {
      thinkingBudget: 2048,
      includeThoughts: false,
    },
  }),
  prompt: 'Walk me through this algorithm step by step.',
});
Available GeminiConfig fields include:
FieldTypeDescription
temperaturenumber (0–2)Sampling randomness. Default 1.0.
topPnumber (0–1)Nucleus sampling probability. Default 0.95.
maxOutputTokensnumberToken cap on the response.
stopSequencesstring[]Stop generation at these strings.
safetySettingsarrayPer-category content filtering thresholds.
thinkingConfigobjectControl the thinking budget for Gemini 2.5+.
codeExecutionbooleanAllow the model to write and run Python code.
googleSearchboolean | objectGround responses with live Google Search.
functionCallingConfigobjectControl when tools are invoked (AUTO / ANY / NONE).
responseModalities('TEXT'|'IMAGE'|'AUDIO')[]Request specific output types.
contextCachebooleanReuse cached input tokens.

Structured output

import { z } from 'genkit';

const RecipeSchema = z.object({
  name: z.string(),
  ingredients: z.array(z.string()),
  steps: z.array(z.string()),
});

const { output } = await ai.generate({
  model: googleAI.model('gemini-2.5-flash'),
  prompt: 'Give me a recipe for banana bread.',
  output: { schema: RecipeSchema },
});

console.log(output.name);

Multimodal input

Gemini 2.5 models accept text, images, audio, video, and PDFs in the same request:
const response = await ai.generate({
  model: googleAI.model('gemini-2.5-flash'),
  messages: [
    {
      role: 'user',
      content: [
        { text: 'What is in this image?' },
        { media: { url: 'https://example.com/photo.jpg', contentType: 'image/jpeg' } },
      ],
    },
  ],
});
For Gemini 2.5+ models, external HTTPS URLs are passed directly to the API. For Gemini 2.0 models, Genkit automatically downloads external media and inlines it (up to 100 MB).

Function calling (tools)

const weatherTool = ai.defineTool(
  {
    name: 'getWeather',
    description: 'Returns the current weather for a city.',
    inputSchema: z.object({ city: z.string() }),
    outputSchema: z.object({ temperature: z.number(), condition: z.string() }),
  },
  async ({ city }) => fetchWeather(city)
);

const response = await ai.generate({
  model: googleAI.model('gemini-2.5-flash'),
  prompt: 'What is the weather like in London?',
  tools: [weatherTool],
});

Embeddings

const embeddings = await ai.embed({
  embedder: googleAI.embedder('gemini-embedding-001'),
  content: 'Machine learning optimises model parameters.',
});
// embeddings[0].embedding → number[]

Embedder config

OptionDescription
taskTypeHint about downstream use (RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, SEMANTIC_SIMILARITY, etc.)
outputDimensionalityTruncate to a smaller dimension (1–768, model-dependent).
titleDocument title, used with RETRIEVAL_DOCUMENT task type.

Image generation (Imagen)

const response = await ai.generate({
  model: googleAI.model('imagen-4.0-generate-001', {
    numberOfImages: 2,
    aspectRatio: '16:9',
  }),
  prompt: 'A serene Japanese garden at sunrise, watercolour style.',
});

const image = response.media();
// image.url contains a base64 data URI

Google Search grounding

Ground responses with real-time web data:
const response = await ai.generate({
  model: googleAI.model('gemini-2.5-flash', {
    googleSearch: true,
  }),
  prompt: 'What are the top AI announcements this week?',
});

Vertex AI plugin

Enterprise Gemini access with GCP credentials.

Structured output

Type-safe JSON generation with Zod schemas.

Multimodal

Working with images, audio, and video.

Tools

Give models access to functions and external data.

Build docs developers (and LLMs) love