Getting Started
- Project Setup: Lines 10-27
- Initialization: Lines 29-95
- Genkit CLI: Lines 97-144
- Import Paths: Lines 146-155
Project Setup
mkdir my-genkit-app && cd my-genkit-app
go mod init my-genkit-app
go get github.com/firebase/genkit/go@latestProvider plugins ship in the same module under plugins/, so they don't need to
be fetched separately. Just import the ones you want and run go mod tidy
afterwards. The available plugins include:
plugins/googlegenaifor Google AI and Vertex AIplugins/anthropicfor Anthropic Claudeplugins/compat_oaifor OpenAI-compatible APIs (OpenAI, Groq, xAI, etc.)plugins/ollamafor local Ollama modelsplugins/middlewarefor the built-in middleware bundle (Retry,Fallback,ToolApproval,Filesystem,Skills)
Initialization
Every Genkit app starts with genkit.Init, which returns a *Genkit instance:
import (
"context"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
)
ctx := context.Background()
g := genkit.Init(ctx,
genkit.WithPlugins(&googlegenai.GoogleAI{}),
)The *Genkit Instance
The *Genkit value g is the central registry. Pass it to every Genkit
function:
// Defining resources
genkit.DefineFlow(g, "myFlow", ...)
genkit.DefineTool(g, "myTool", ...)
genkit.DefinePrompt(g, "myPrompt", ...)
// Generating content
genkit.GenerateText(ctx, g, ...)
genkit.Generate(ctx, g, ...)Do not store g in a global variable. Pass it explicitly through your call
chain.
Init Options
g := genkit.Init(ctx,
// Register one or more plugins
genkit.WithPlugins(&googlegenai.GoogleAI{}, &anthropic.Anthropic{}),
// Set a default model (used when no model is specified)
genkit.WithDefaultModel("googleai/gemini-flash-latest"),
// Set directory for .prompt files (default: "prompts")
genkit.WithPromptDir("my-prompts"),
// Or embed prompts using Go's embed package
// genkit.WithPromptFS(promptsFS),
)Embedding Prompts
Use go:embed to bundle .prompt files into the binary:
//go:embed prompts
var promptsFS embed.FS
g := genkit.Init(ctx,
genkit.WithPlugins(&googlegenai.GoogleAI{}),
genkit.WithPromptFS(promptsFS),
)Genkit CLI
The Genkit CLI provides a local Developer UI for running flows, tracing executions, and inspecting model interactions.
Install:
curl -sL cli.genkit.dev | bashVerify:
genkit --versionDeveloper UI
Start your app with the Developer UI attached:
genkit start -- go run .This launches:
- Your app (with tracing enabled)
- The Developer UI at
http://localhost:4000 - A telemetry API at
http://localhost:4033
Add -o to auto-open the UI in your browser:
genkit start -o -- go run .The Developer UI lets you:
- Run and test flows interactively
- View traces for each generation call (inputs, outputs, latency, token usage)
- Inspect prompt rendering and tool calls
- Debug multi-step flows with per-step trace data
Without the CLI
Set GENKIT_ENV=dev to enable the reflection API without the CLI:
GENKIT_ENV=dev go run .Import Paths
import (
"github.com/firebase/genkit/go/genkit" // Core: Init, Generate*, DefineFlow, etc.
"github.com/firebase/genkit/go/ai" // Types: WithModel, WithPrompt, Message, Part, etc.
"github.com/firebase/genkit/go/core" // Low-level: Run (sub-steps), Flow types
"github.com/firebase/genkit/go/plugins/server" // server.Start for HTTP
)