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.
Prerequisites
Section titled “Prerequisites”Before you begin, make sure your environment meets these requirements:
- Dart SDK 3.10.0 or later (Download and install)
Set up your project
Section titled “Set up your project”Create a new Dart project:
dart create -t console-simple my_genkit_appcd my_genkit_appInstall Genkit packages
Section titled “Install Genkit packages”First, install the Genkit CLI. This gives you access to local developer tools, including the Developer UI:
curl -sL cli.genkit.dev | bashThen, install the core Genkit package, the Google AI plugin, and the build_runner dev dependency (for schema generation):
dart pub add genkit genkit_google_genai schemantic dev:build_runnerConfigure your model API key
Section titled “Configure your model API key”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:
export GEMINI_API_KEY=<your API key>Create your first application
Section titled “Create your first application”A flow is a special Genkit function with built-in observability, type safety, and tooling integration.
Replace bin/my_genkit_app.dart with the following code:
import 'dart:convert';
import 'package:genkit/genkit.dart';import 'package:genkit_google_genai/genkit_google_genai.dart';import 'package:schemantic/schemantic.dart';
part 'my_genkit_app.g.dart';
// Define input schema@Schema()abstract class $RecipeInput { @Field(description: 'Main ingredient or cuisine type') String get ingredient;
@Field(description: 'Any dietary restrictions') String? get dietaryRestrictions;}
// Define output schema@Schema()abstract class $Recipe { String get title; String get description; String get prepTime; String get cookTime; int get servings; List<String> get ingredients; List<String> get instructions; List<String>? get tips;}
void main() async { final ai = Genkit(plugins: [googleAI()]);
// Define a recipe generator flow final recipeGeneratorFlow = ai.defineFlow( name: 'recipeGeneratorFlow', inputSchema: RecipeInput.$schema, outputSchema: Recipe.$schema, fn: (input, _) async { // Create a prompt based on the input final dietaryRestrictions = input.dietaryRestrictions ?? 'none'; final prompt = 'Create a recipe with the following requirements:\n' 'Main ingredient: ${input.ingredient}\n' 'Dietary restrictions: $dietaryRestrictions';
// Generate structured recipe data using the same schema final response = await ai.generate( model: googleAI.gemini('gemini-2.5-flash'), config: GeminiOptions(temperature: 0.8), prompt: prompt, outputSchema: Recipe.$schema, );
if (response.output == null) { throw Exception('Failed to generate recipe'); } return response.output!; }, );
// Run the flow final recipe = await recipeGeneratorFlow(RecipeInput( ingredient: 'avocado', dietaryRestrictions: 'vegetarian', ));
print(JsonEncoder.withIndent(' ').convert(recipe));}This code sample:
- Defines reusable input and output schemas using
@Schemaannotation - Configures the
gemini-2.5-flashmodel - Defines a Genkit flow to generate a structured recipe based on your input
- Runs the flow with a sample input and prints the result
Note: Genkit Dart uses
build_runnerto generate schema types. You’ll need to run it before your code will compile.
Why use flows?
Section titled “Why use flows?”- 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
Section titled “Run your application”First, generate the schema code:
dart run build_runner buildThen, run your application:
dart runYou should see a structured recipe output in JSON format.
Test in the Developer UI
Section titled “Test in the Developer UI”The Developer UI is a local tool for testing and inspecting Genkit components, like flows, with a visual interface.
Start the Developer UI
Section titled “Start the Developer UI”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:
genkit start -- dart runThe command will print the Dev UI URL:
Genkit Developer UI: http://localhost:4000Run and inspect flows
Section titled “Run and inspect flows”In the Developer UI:
-
Select your recipe generator flow from the list of flows:
recipeGeneratorFlow
-
Enter sample input:
{ "ingredient": "avocado", "dietaryRestrictions": "vegetarian" }- 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.
Next steps
Section titled “Next steps”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
.promptfiles or code.