Skip to main content
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

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.

generate() options

The full set of options available on ai.generate():

Working with the response

ai.generate() returns a GenerateResponse with several useful accessors:

System prompts

Use the system field to set persistent instructions that shape how the model responds:

Multi-turn conversations

Pass previous messages via messages to give the model conversation history:
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:

Structured output

Request a structured JSON response by providing an output.schema. Genkit validates the model’s response against the schema.
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: 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.