Skip to main content
This guide will help you create your first AI-powered application using Genkit for Go. You’ll learn how to initialize Genkit, make your first generation request, and work with structured data.

Prerequisites

Step 1: Initialize Your Project

Create a new Go module:

Step 2: Install Genkit

Add Genkit and the Google AI plugin to your project:

Step 3: Set Your API Key

Set your Google AI API key as an environment variable:

Step 4: Create Your First Application

Create a file named main.go:
main.go

Step 5: Run Your Application

Run your application with the Genkit CLI for automatic tracing:
Or run it directly:
You should see a response explaining why Go is great for AI applications.

Access the Developer UI

When running with genkit start, open http://localhost:4000 to access the Developer UI where you can:
  • View execution traces
  • Test flows interactively
  • Debug multi-step operations

Generate Structured Data

Genkit for Go provides type-safe JSON output with GenerateData:

Stream Responses

Stream text as it’s generated for responsive user experiences:

Define Tools

Give models the ability to take actions and access external data:

Create a Flow

Flows wrap your AI logic for better observability and deployment:

Define Prompts

Create reusable prompts with Handlebars templating:

Expose Flows as HTTP Endpoints

Serve your flows over HTTP with automatic JSON serialization:
Test your endpoint:

Try Other Model Providers

Genkit supports multiple AI providers:

Learn More

Go API Reference

Explore the complete Go API

Structured Output

Generate type-safe JSON responses

Tool Calling

Give AI models access to functions

Deployment

Deploy your Go applications