Skip to content

Get started with Genkit

This guide shows you how to get started with Genkit in your preferred language and test it in the Developer UI.

Before you begin, make sure your environment meets these requirements:

This guide assumes you’re already familiar with building Go applications.

Initialize a new Go project directory:

Terminal window
mkdir genkit-intro && cd genkit-intro
go mod init example/genkit-intro

Create a main.go file for your application entry point.

First, install the Genkit CLI. This gives you access to local developer tools, including the Developer UI:

Terminal window
curl -sL cli.genkit.dev | bash

Then, install the Genkit package for Go:

Terminal window
go get github.com/firebase/genkit/go

This provides Genkit core capabilities and access to Google AI Gemini models.

Genkit can work with multiple model providers. This guide uses the Gemini API, which offers a generous free tier and doesn’t require a credit card to get started.

To use it, you’ll need an API key from Google AI Studio:

Get a Gemini API Key

Once you have a key, set the GEMINI_API_KEY environment variable:

Terminal window
export GEMINI_API_KEY=<your API key>

A flow is a special Genkit function with built-in observability, type safety, and tooling integration.

Create a main.go file with the following sample code:

package main
import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
"github.com/firebase/genkit/go/plugins/server"
)
// Define input schema
type RecipeInput struct {
Ingredient string `json:"ingredient" jsonschema:"description=Main ingredient or cuisine type"`
DietaryRestrictions string `json:"dietaryRestrictions,omitempty" jsonschema:"description=Any dietary restrictions"`
}
// Define output schema
type Recipe struct {
Title string `json:"title"`
Description string `json:"description"`
PrepTime string `json:"prepTime"`
CookTime string `json:"cookTime"`
Servings int `json:"servings"`
Ingredients []string `json:"ingredients"`
Instructions []string `json:"instructions"`
Tips []string `json:"tips,omitempty"`
}
func main() {
ctx := context.Background()
// Initialize Genkit with the Google AI plugin
g := genkit.Init(ctx,
genkit.WithPlugins(&googlegenai.GoogleAI{}),
genkit.WithDefaultModel("googleai/gemini-2.5-flash"),
)
// Define a recipe generator flow
recipeGeneratorFlow := genkit.DefineFlow(g, "recipeGeneratorFlow", func(ctx context.Context, input *RecipeInput) (*Recipe, error) {
// Create a prompt based on the input
dietaryRestrictions := input.DietaryRestrictions
if dietaryRestrictions == "" {
dietaryRestrictions = "none"
}
prompt := fmt.Sprintf(`Create a recipe with the following requirements:
Main ingredient: %s
Dietary restrictions: %s`, input.Ingredient, dietaryRestrictions)
// Generate structured recipe data using the same schema
recipe, _, err := genkit.GenerateData[Recipe](ctx, g,
ai.WithPrompt(prompt),
)
if err != nil {
return nil, fmt.Errorf("failed to generate recipe: %w", err)
}
return recipe, nil
})
// Run the flow once to test it
recipe, err := recipeGeneratorFlow.Run(ctx, &RecipeInput{
Ingredient: "avocado",
DietaryRestrictions: "vegetarian",
})
if err != nil {
log.Fatalf("could not generate recipe: %v", err)
}
// Print the structured recipe
recipeJSON, _ := json.MarshalIndent(recipe, "", " ")
fmt.Println("Sample recipe generated:")
fmt.Println(string(recipeJSON))
// Start a server to serve the flow and keep the app running for the Developer UI
mux := http.NewServeMux()
mux.HandleFunc("POST /recipeGeneratorFlow", genkit.Handler(recipeGeneratorFlow))
log.Println("Starting server on http://localhost:3400")
log.Println("Flow available at: POST http://localhost:3400/recipeGeneratorFlow")
log.Fatal(server.Start(ctx, "127.0.0.1:3400", mux))
}

This code sample:

  • Defines reusable input and output schemas using Go structs with JSON schema tags
  • Configures the gemini-2.5-flash model as the default
  • Defines a Genkit flow to generate a structured recipe based on your input
  • Runs the flow with a sample input and prints the structured result
  • Type-safe inputs and outputs: Define clear schemas for your data
  • Integrates with the Developer UI: Test and debug flows visually
  • Easy deployment as APIs: Deploy flows as HTTP endpoints
  • Built-in tracing and observability: Monitor performance and debug issues

Run your application to see it in action:

Terminal window
go run .

You should see a structured recipe output in JSON format, followed by the server starting on http://localhost:3400. The server will continue running to serve your flow as an HTTP endpoint and enable the Developer UI.

With the server running, you can test your flow by making HTTP requests to it. This demonstrates how your flow works as a web API.

In a new terminal window (while keeping your Go application running), try this curl command:

Terminal window
curl -X POST "http://localhost:3400/recipeGeneratorFlow" \
-H "Content-Type: application/json" \
-d '{"data": {"ingredient": "tomato", "dietaryRestrictions": "vegan"}}'

You should receive a JSON response with a generated recipe. This shows how your Genkit flow can be called from any HTTP client, making it easy to integrate into web applications, mobile apps, or other services.

The Developer UI is a local tool for testing and inspecting Genkit components, like flows, with a visual interface.

The Genkit CLI is required to run the Developer UI. If you followed the installation steps above, you already have it installed.

Run the following command from your project root:

Terminal window
genkit start -- go run .

This starts your app and launches the Developer UI at http://localhost:4000 by default. The server will continue running on http://localhost:3400 to serve your flows and enable the Developer UI to inspect them.

In the Developer UI:

  1. Select your recipe generator flow from the list of flows:

    • recipeGeneratorFlow
  2. Enter sample input:

{
"ingredient": "avocado",
"dietaryRestrictions": "vegetarian"
}
  1. Click Run

You’ll see the generated recipe as structured output, along with a visual trace of the AI generation process for debugging and optimization.

Now that you’ve created and tested your first Genkit application, explore more features to build powerful AI-driven applications:

  • Developer tools: Set up your local workflow with the Genkit CLI and Dev UI.
  • Generating content: Use Genkit’s unified generation API to work with multimodal and structured output across supported models.
  • Creating flows: Learn about streaming flows, schema customization, deployment options, and more.
  • Tool calling: Enable your AI models to interact with external systems and APIs.
  • Managing prompts with Dotprompt: Define flexible prompt templates using .prompt files or code.