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
- TypeScript
- Go
- Python
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.
- TypeScript
- Go
- Python
generate() options
The full set of options available on ai.generate():
| Option | Type | Description |
|---|---|---|
model | string | ModelRef | Model to use. Overrides the default. |
prompt | string | Part | Part[] | The user prompt. |
system | string | Part | Part[] | System instructions (persona, constraints, etc.). |
messages | MessageData[] | Conversation history for multi-turn prompting. |
tools | ToolArgument[] | Tools/functions the model may call. |
toolChoice | 'auto' | 'required' | 'none' | How the model should use tools. |
config | object | Model-specific configuration (temperature, topP, etc.). |
output | OutputOptions | Desired output format (JSON schema, structured output). |
docs | DocumentData[] | Retrieved documents to inject as context (RAG). |
Working with the response
ai.generate() returns a GenerateResponse with several useful accessors:
- TypeScript
- Go
- Python
System prompts
Use thesystem field to set persistent instructions that shape how the model responds:
Multi-turn conversations
Pass previous messages viamessages 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 throughconfig. These vary by model but typically include:
Structured output
Request a structured JSON response by providing anoutput.schema. Genkit validates the model’s response against the schema.
Model plugins
Models are provided by plugins. Install and configure the plugin for the provider you want to use:| Provider | Plugin | Example model string |
|---|---|---|
| Google AI (Gemini) | @genkit-ai/google-genai | googleai/gemini-2.5-flash |
| Vertex AI | @genkit-ai/google-genai | vertexai/gemini-2.5-pro |
| Ollama (local) | genkitx-ollama | ollama/llama3.2 |
| Anthropic | community | anthropic/claude-3-5-sonnet |
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.
