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.

Genkit provides a single generate() API that works with any supported model provider. Swap models by changing a single string; the rest of your code stays the same.

Basic generation

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

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

const response = await ai.generate({
  model: 'googleai/gemini-2.5-flash',
  prompt: 'Why is the sky blue?',
});

console.log(response.text);

Specifying a model

Models are identified by a namespaced string: "<plugin>/<model-name>". You can also set a default model on the genkit instance so you don’t have to repeat it on every call.
// As a string reference
await ai.generate({ model: 'googleai/gemini-2.5-flash', prompt: 'Hello' });

// As a modelRef (enables TypeScript-typed config)
import { googleAI } from '@genkit-ai/google-genai';
await ai.generate({
  model: googleAI.model('gemini-2.5-flash'),
  prompt: 'Hello',
});

// Using the default model (set at initialization)
const ai = genkit({
  plugins: [googleAI()],
  model: 'googleai/gemini-2.5-flash', // default
});
await ai.generate('Hello'); // uses the default

generate() options

The full set of options available on ai.generate():
OptionTypeDescription
modelstring | ModelRefModel to use. Overrides the default.
promptstring | Part | Part[]The user prompt.
systemstring | Part | Part[]System instructions (persona, constraints, etc.).
messagesMessageData[]Conversation history for multi-turn prompting.
toolsToolArgument[]Tools/functions the model may call.
toolChoice'auto' | 'required' | 'none'How the model should use tools.
configobjectModel-specific configuration (temperature, topP, etc.).
outputOutputOptionsDesired output format (JSON schema, structured output).
docsDocumentData[]Retrieved documents to inject as context (RAG).

Working with the response

ai.generate() returns a GenerateResponse with several useful accessors:
const response = await ai.generate({
  model: 'googleai/gemini-2.5-flash',
  prompt: 'List the planets in order from the sun.',
  output: {
    schema: z.object({
      planets: z.array(z.string()),
    }),
  },
});

// Plain text of the first candidate
console.log(response.text);

// Parsed structured output (typed against the output schema)
console.log(response.output); // { planets: ['Mercury', 'Venus', ...] }

// All candidate messages
console.log(response.candidates);

// Token usage
console.log(response.usage);
// { inputTokens: 12, outputTokens: 28, totalTokens: 40 }

System prompts

Use the system field to set persistent instructions that shape how the model responds:
const response = await ai.generate({
  model: 'googleai/gemini-2.5-flash',
  system: 'You are a terse technical writer. Respond in plain text only.',
  prompt: 'Explain what a webhook is.',
});

Multi-turn conversations

Pass previous messages via messages to give the model conversation history:
const history = [
  { role: 'user', content: [{ text: 'My name is Alex.' }] },
  { role: 'model', content: [{ text: 'Nice to meet you, Alex!' }] },
];

const response = await ai.generate({
  model: 'googleai/gemini-2.5-flash',
  messages: history,
  prompt: 'What is my name?',
});
// → "Your name is Alex."
For stateful multi-turn conversations you don’t need to manage history manually. See Sessions.

Model configuration

Pass model-specific parameters through config. These vary by model but typically include:
const response = await ai.generate({
  model: 'googleai/gemini-2.5-flash',
  prompt: 'Write a haiku about autumn.',
  config: {
    temperature: 1.2,   // higher = more creative
    topP: 0.95,
    maxOutputTokens: 200,
    stopSequences: ['\n\n'],
  },
});

Structured output

Request a structured JSON response by providing an output.schema. Genkit validates the model’s response against the schema.
const response = await ai.generate({
  model: 'googleai/gemini-2.5-flash',
  prompt: 'Extract the product name, price, and category from this text: ...',
  output: {
    schema: z.object({
      name: z.string(),
      price: z.number(),
      category: z.string(),
    }),
  },
});

const product = response.output; // { name: '...', price: 9.99, category: '...' }
See Structured Output for more detail.

Model plugins

Models are provided by plugins. Install and configure the plugin for the provider you want to use:
ProviderPluginExample model string
Google AI (Gemini)@genkit-ai/google-genaigoogleai/gemini-2.5-flash
Vertex AI@genkit-ai/google-genaivertexai/gemini-2.5-pro
Ollama (local)genkitx-ollamaollama/llama3.2
Anthropiccommunityanthropic/claude-3-5-sonnet
See Plugins for the full list.

Next steps

Structured Output

Force models to return typed JSON matching your schema.

Streaming

Stream tokens as they are generated.

Multimodal

Send images, audio, and video to models.

Tools

Let models call your functions.

Build docs developers (and LLMs) love