Get started with Genkit using Go
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.
Make your first request
-
Install Go 1.24 or later. See Download and install in the official Go docs.
-
Initialize a new Go project directory with the Genkit package:
Terminal window mkdir genkit-intro && cd genkit-introgo mod init example/genkit-introgo get github.com/firebase/genkit/go -
Create a
main.go
file with the following sample code:package mainimport ("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 Genkit with the Google AI plugin and Gemini 2.0 Flash.g, err := genkit.Init(ctx,genkit.WithPlugins(&googlegenai.GoogleAI{}),genkit.WithDefaultModel("googleai/gemini-2.0-flash"),)if err != nil {log.Fatalf("could not initialize Genkit: %v", err)}resp, err := genkit.Generate(ctx, g, ai.WithPrompt("What is the meaning of life?"))if err != nil {log.Fatalf("could not generate model response: %v", err)}log.Println(resp.Text())} -
Configure your Gemini API key by setting the
GEMINI_API_KEY
environment variable:Terminal window export GEMINI_API_KEY=<your API key>If you don’t already have one, create a key in Google AI Studio. Google AI provides a generous free-of-charge tier and does not require a credit card to get started.
-
Run the app to see the model response:
Terminal window go run .# Example output (may vary):# There is no single universally agreed-upon meaning of life; it's a deeply# personal question. Many find meaning through connection, growth,# contribution, happiness, or discovering their own purpose.
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.