1
Get a Google AI API key
Genkit’s Google AI plugin uses the Gemini API. Get a free API key from Google AI Studio.
Set the key as an environment variable before running your app:The
googlegenai.GoogleAI plugin also accepts GOOGLE_API_KEY. You can pass the key directly in the plugin struct (&googlegenai.GoogleAI{APIKey: "..."}) but using an environment variable keeps credentials out of source control.2
Add Genkit to your Go module
Initialize a new module (or open an existing one), then fetch the Genkit packages:Install the Genkit CLI to get the Developer UI:
3
Write your first Genkit app
Create Run it directly:
main.go:4
Explore with the Developer UI
The Genkit CLI wraps your app with tracing and launches a local Developer UI where you can run flows interactively and inspect execution traces.This starts your app, then opens the Developer UI at
http://localhost:4000. From there you can:- Run the
tellJokeflow with any input without restarting your app. - Inspect traces to see the full request and response sent to Gemini.
- Compare models by switching between
gemini-2.5-flashandgemini-2.5-proin real time.
5
Add structured output (optional)
genkit.GenerateData uses Go generics to return type-safe, unmarshaled structs:6
Expose flows as HTTP endpoints (optional)
To serve your flows over HTTP, register them with the standard Then call the flow:
net/http mux:genkit.Handler returns a standard http.HandlerFunc, so it works with any Go HTTP framework (Gin, Echo, Chi, and others).Next steps
Concepts: Flows
Learn how flows add observability, retries, and HTTP exposure to any AI function.
Concepts: Models
Understand model references, config options, multimodal inputs, and streaming.
Guides: Structured output
Return validated, type-safe structs from any model call using Go generics.
Guides: Streaming
Stream tokens to the client as they arrive using
genkit.GenerateStream.Guides: Agents
Build multi-step agentic workflows with
genkit.DefineTool and looping.Plugins: Google AI
Full reference for the
googlegenai plugin including Vertex AI, Imagen, and embeddings.Plugins overview
Browse all available plugins: Vertex AI, Ollama, Anthropic, and more.
Developer tools
Deep dive into the Genkit CLI and Developer UI.
