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:

To install uv:

Terminal window
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Create a new project directory:

Terminal window
mkdir genkit-intro && cd genkit-intro

Initialize the project with uv:

Terminal window
uv init --no-readme --python 3.10

This creates a pyproject.toml file and sets up your project structure.

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 required Python packages:

Terminal window
uv add genkit genkit-plugin-google-genai

This installs:

  • genkit: Genkit core capabilities
  • genkit-plugin-google-genai: 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.py file:

main.py
from typing import Optional
from pydantic import BaseModel, Field
from genkit import Genkit
from genkit import Output
from genkit.plugins.google_genai import GoogleAI
# Initialize Genkit with the Google AI plugin
ai = Genkit(
plugins=[GoogleAI()],
model='googleai/gemini-2.5-flash',
)
# Define input schema
class RecipeInput(BaseModel):
ingredient: str = Field(description='Main ingredient or cuisine type')
dietary_restrictions: Optional[str] = Field(default=None, description='Any dietary restrictions')
# Define output schema
class Recipe(BaseModel):
title: str
description: str
prep_time: str
cook_time: str
servings: int
ingredients: list[str]
instructions: list[str]
# Define a recipe generator flow
@ai.flow()
async def recipe_generator_flow(input_data: RecipeInput) -> Recipe:
# Create a prompt based on the input
dietary_restrictions = input_data.dietary_restrictions or 'none'
prompt = f"""Create a recipe with the following requirements:
Main ingredient: {input_data.ingredient}
Dietary restrictions: {dietary_restrictions}"""
# Generate structured recipe data using the same schema
result = await ai.generate(
prompt=prompt,
output=Output(schema=Recipe),
)
if not result.output:
raise ValueError('Failed to generate recipe')
return result.output
async def main() -> None:
# Run the flow
recipe = await recipe_generator_flow(RecipeInput(
ingredient='avocado',
dietary_restrictions='vegetarian'
))
# Print the structured recipe
print(recipe.model_dump_json(indent=2))
ai.run_main(main())

This code sample:

  • Defines reusable input and output schemas with Pydantic
  • 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 app (Genkit apps are just regular Python applications):

Terminal window
uv run main.py

You should see a structured recipe output in JSON format.

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.

To inspect your app with Genkit Dev UI, run:

Terminal window
genkit start -- uv run main.py

The command will print the Dev UI URL:

Genkit Developer UI: http://localhost:4000

In the Developer UI:

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

    • recipe_generator_flow
  2. Enter sample input:

{
"ingredient": "avocado",
"dietary_restrictions": "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.