This guide shows you how to get started with Genkit in a Go app.
If you discover issues with the libraries or this documentation please report them in our GitHub repository.
Requirements
Go 1.24 or later. See Download and install in the official Go docs.
Node.js 20 or later (for the Genkit CLI and UI). See the next section for a brief guide on installing Node.
Install Genkit
If you don't already have Node 20 or newer on your system, install it now.
Recommendation: The
nvm
andnvm-windows
tools are a convenient way to install specific versions of Node if it's not already installed on your system. These tools install Node on a per-user basis, so you don't need to make system-wide changes.To install
nvm
:Run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Download and run the installer as described in the nvm-windows docs.
Then, to install Node and
npm
, open a new shell and run the following command:nvm install 20
Install the Genkit CLI by running the following command:
npm i -g genkit-cli
This command installs the Genkit CLI into your Node installation directory so that it can be used outside of a Node project.
Create and explore a sample project
Create a new project directory:
mkdir genkit-intro && cd genkit-intro
Initialize the Go module and get the Genkit package:
go mod init example/genkit-intro
go get github.com/firebase/genkit/go
Configure your model API key
For this guide, we'll show you how to use the Gemini API which provides a generous free-of-charge tier and does not require a credit card to get started. To use the Gemini API, you'll need an API key. If you don't already have one, create a key in Google AI Studio.
After you've created an API key, set the GEMINI_API_KEY
environment
variable to your key with the following command:
export GEMINI_API_KEY=<your API key>
Make your first request
Get started with Genkit in just a few lines of code.
package main
import (
"context"
"log"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
)
func main() {
ctx := context.Background()
// Initialize a Genkit instance.
g, err := genkit.Init(ctx,
// Install the Google AI plugin which provides Gemini models.
genkit.WithPlugins(&googlegenai.GoogleAI{}),
// Set the default model to use for generate calls.
genkit.WithDefaultModel("googleai/gemini-2.0-flash"),
)
if err != nil {
log.Fatal(err)
}
// Generate a model response.
resp, err := genkit.Generate(ctx, g, ai.WithPrompt("Hello, Gemini!"))
if err != nil {
log.Fatal(err)
}
log.Println(resp.Text())
}
Next steps
Now that you're set up to make model requests with Genkit, learn how to use more Genkit capabilities to build your AI-powered apps and workflows. To get started with additional Genkit capabilities, see the following guides:
- Developer tools: Learn how to set up and use Genkit's CLI and developer UI to help you locally test and debug your app.
- Generating content: Learn how to use Genkit's unified generation API to generate text and structured data from any supported model.
- Creating flows: Learn how to use special Genkit functions, called flows, that provide end-to-end observability for workflows and rich debugging from Genkit tooling.
- Managing prompts: Learn how Genkit helps you manage your prompts and configuration together as code.