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:

Create a new Dart project:

Terminal window
dart create -t console-simple my_genkit_app
cd my_genkit_app

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 core Genkit package, the Google AI plugin, and the build_runner dev dependency (for schema generation):

Terminal window
dart pub add genkit genkit_google_genai schemantic dev:build_runner

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.

Replace bin/my_genkit_app.dart with the following code:

bin/my_genkit_app.dart
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 @Schema annotation
  • Configures the gemini-2.5-flash model
  • 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_runner to generate schema types. You’ll need to run it before your code will compile.

  • 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

First, generate the schema code:

Terminal window
dart run build_runner build

Then, run your application:

Terminal window
dart run

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 -- dart run

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:

    • 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.