Genkit CLI

1.32.0 · active · verified Sun Apr 19

Genkit is an open-source framework by Google for building and deploying AI-powered applications, available with JavaScript/TypeScript, Go, and Python SDKs. The `genkit-cli` package provides the command-line interface for interacting with the Genkit framework, facilitating development tasks such as project initialization, running local development servers, deploying flows, and inspecting traces. The current stable version of the JavaScript/TypeScript CLI is 1.32.0, with minor updates and release candidates released frequently, indicating active development. Key differentiators include its multi-language SDK support, integration with Google's AI services (like Vertex AI and Google GenAI), and a local development UI for visualizing AI application flows and traces.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to install the Genkit CLI, initialize a new Genkit project, configure it with the Google AI plugin, define a simple AI flow, and then run it using the local development UI. It includes setting up environment variables for API keys and assumes a basic TypeScript project setup.

# 1. Install the Genkit CLI globally
npm install -g genkit-cli

# 2. Initialize a new Genkit project (select 'TypeScript' and a plugin like 'Google AI')
# This creates a genkit.ts config file and boilerplate.
genkit init

# 3. Configure your Genkit project and define a simple flow (e.g., in src/index.ts)
# Make sure to set environment variables like GOOGLE_API_KEY or GEMINI_API_KEY.
# For example, in a .env file or by exporting:
# export GOOGLE_API_KEY="YOUR_API_KEY"

// src/index.ts (example configuration and flow)
import { configureGenkit, defineFlow, generate, z } from '@genkit-ai/core';
import { googleGenai } from '@genkit-ai/google-genai';

export default configureGenkit({
  plugins: [
    googleGenai({ apiKey: process.env.GOOGLE_API_KEY ?? '' }),
  ],
  flowRegistry: [
    defineFlow(
      {
        name: 'helloWorldFlow',
        inputSchema: z.string().describe('Name to greet'),
        outputSchema: z.string().describe('Greeting message'),
      },
      async (name) => {
        const response = await generate({ 
          model: 'gemini-pro', 
          prompt: `Hello, ${name}! Generate a short, friendly greeting.`, 
          config: { temperature: 0.7 }
        });
        return response.text();
      }
    ),
  ],
  logLevel: 'debug',
  enableTracing: true,
});

// 4. Start the local Genkit development UI
# This command starts your app in dev mode and launches a local web UI (typically http://localhost:3400 or 4000).
# You can then interact with 'helloWorldFlow' via the UI.
genkit start -- npx tsx --watch src/index.ts

# 5. Run a flow directly from the CLI (optional)
# genkit flow:run helloWorldFlow '{"name": "Genkit User"}'

view raw JSON →