{"id":10935,"library":"genkit","title":"Genkit AI Framework","description":"Genkit is an open-source AI framework developed by Google (initially from Firebase) designed to streamline the building, deployment, and monitoring of AI-powered applications. The JavaScript/TypeScript SDK is currently at a stable production-ready version, `1.32.0`, with frequent minor and patch releases, often introducing new model support and features (e.g., `1.33.0-rc.0` is a recent release candidate). Genkit offers a unified interface for integrating with a wide array of generative AI model providers, including Google AI (Gemini, Imagen), Vertex AI, Anthropic, OpenAI, and local models via Ollama. Its key differentiators include a code-centric approach to defining AI flows, built-in observability with automatic tracing and logging, structured output generation with Zod schema validation, tool calling, Retrieval-Augmented Generation (RAG) capabilities, and comprehensive local development tools like a CLI and a web-based Developer UI for interactive testing and debugging. It aims to simplify the development lifecycle of complex AI applications and supports flexible deployment to various environments.","status":"active","version":"1.32.0","language":"javascript","source_language":"en","source_url":"https://github.com/firebase/genkit","tags":["javascript","genkit","ai","genai","generative-ai","typescript"],"install":[{"cmd":"npm install genkit","lang":"bash","label":"npm"},{"cmd":"yarn add genkit","lang":"bash","label":"yarn"},{"cmd":"pnpm add genkit","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for integrating with Google's Gemini and Vertex AI models.","package":"@genkit-ai/google-genai","optional":false},{"reason":"Used extensively for defining and validating input and output schemas for flows and models.","package":"zod","optional":false},{"reason":"Provides new 'generate middleware' capabilities for advanced flow control and agentic behaviors, introduced in v1.33.0-rc.0.","package":"@genkit-ai/middleware","optional":true},{"reason":"Required for integrating with Anthropic's models.","package":"@genkit-ai/anthropic","optional":true},{"reason":"Required for integrating with OpenAI's models.","package":"@genkit-ai/compat-oai/openai","optional":true}],"imports":[{"note":"The core configuration function. Genkit primarily uses ESM imports in modern Node.js environments. For older CJS, dynamic import might be necessary or ensure build tooling transpiles correctly.","wrong":"const configureGenkit = require('genkit').configureGenkit","symbol":"configureGenkit","correct":"import { configureGenkit } from 'genkit'"},{"note":"Defines an observable AI workflow. It is imported directly from `genkit` since recent versions. Previous versions might have imported from `@genkit-ai/core` or `@genkit-ai/flow`.","wrong":"import { defineFlow } from '@genkit-ai/core'","symbol":"defineFlow","correct":"import { defineFlow } from 'genkit'"},{"note":"This is the primary plugin for Google's GenAI models (Gemini, Vertex AI). The older `@genkit-ai/googleai` and `@genkit-ai/vertexai` packages are deprecated.","wrong":"import { googleAI } from '@genkit-ai/googleai'","symbol":"googleGenai","correct":"import { googleGenai } from '@genkit-ai/google-genai'"}],"quickstart":{"code":"import { configureGenkit, defineFlow, generate } from 'genkit';\nimport { googleGenai } from '@genkit-ai/google-genai';\nimport * as z from 'zod';\n\n// Ensure you have `npm install genkit @genkit-ai/google-genai zod`\n// And set GOOGLE_API_KEY as an environment variable (e.g., in .env or your shell)\n// e.g., export GOOGLE_API_KEY='your-api-key'\n\n// Configure Genkit with a plugin for Google Generative AI\nconfigureGenkit({\n  plugins: [\n    googleGenai({\n      apiKey: process.env.GOOGLE_API_KEY ?? '',\n    }),\n  ],\n  logLevel: 'debug',\n  enableTracingAndMetrics: true,\n});\n\n// Define input and output schemas using Zod for type safety\nconst RecipeInputSchema = z.object({\n  mainIngredient: z.string().describe('The primary ingredient for the recipe.'),\n  dietaryRestrictions: z.string().optional().describe('Any dietary restrictions (e.g., vegetarian, gluten-free).'),\n});\n\nconst RecipeOutputSchema = z.object({\n  title: z.string().describe('The title of the recipe.'),\n  ingredients: z.array(z.string()).describe('List of ingredients.'),\n  instructions: z.array(z.string()).describe('Step-by-step cooking instructions.'),\n  prepTimeMinutes: z.number().int().positive().describe('Preparation time in minutes.'),\n});\n\n// Define a Genkit flow to generate a recipe\nexport const recipeGeneratorFlow = defineFlow(\n  {\n    name: 'recipeGenerator',\n    inputSchema: RecipeInputSchema,\n    outputSchema: RecipeOutputSchema,\n    description: 'Generates a recipe based on a main ingredient and dietary restrictions.',\n  },\n  async ({ mainIngredient, dietaryRestrictions }) => {\n    const prompt = `Create a detailed recipe with ${mainIngredient} as the main ingredient.`;\n    const restrictionsPrompt = dietaryRestrictions ? ` It must be ${dietaryRestrictions}.` : '';\n    const fullPrompt = prompt + restrictionsPrompt + ` Respond in JSON format strictly following the provided schema.`;\n\n    const response = await generate({\n      model: googleGenai.model('gemini-1.5-flash'), // Use a suitable Gemini model\n      prompt: fullPrompt,\n      output: { schema: RecipeOutputSchema },\n      config: { temperature: 0.7 },\n    });\n\n    if (!response.output) {\n      throw new Error('Failed to generate recipe output.');\n    }\n    return response.output;\n  }\n);\n\n// To run this flow in development, you would typically use 'genkit start'\n// and interact via the Developer UI at http://localhost:4000/ or make HTTP calls.\n// Example of direct execution (for testing or serverless functions):\nasync function runExample() {\n  console.log('Running recipeGeneratorFlow...');\n  try {\n    const recipe = await recipeGeneratorFlow({\n      mainIngredient: 'chicken',\n      dietaryRestrictions: 'low-carb'\n    });\n    console.log('Generated Recipe:', JSON.stringify(recipe, null, 2));\n  } catch (error) {\n    console.error('Flow failed:', error);\n  }\n}\n\nrunExample();","lang":"typescript","description":"This quickstart demonstrates how to set up Genkit with the Google GenAI plugin, define type-safe input/output schemas using Zod, and create a simple AI flow that generates a structured recipe based on user input, ready for local execution and deployment."},"warnings":[{"fix":"Replace imports from `@genkit-ai/googleai` and `@genkit-ai/vertexai` with `@genkit-ai/google-genai`. Update model string references accordingly (e.g., `googleAI.model('gemini-pro')` might become `googleGenai.model('gemini-1.5-flash')`).","message":"The `@genkit-ai/googleai` and `@genkit-ai/vertexai` packages for model plugins are deprecated. Users should migrate to `@genkit-ai/google-genai` for all Google Generative AI models (Gemini, Imagen, etc.).","severity":"deprecated","affected_versions":">=1.26.0"},{"fix":"Review the latest Genkit documentation for the `@genkit-ai/google-genai` plugin to identify supported and recommended models. Update your code to use current model identifiers.","message":"Some specific Imagen and Veo models within the Google GenAI plugin have been deprecated. Users relying on these models may experience errors or reduced functionality.","severity":"deprecated","affected_versions":">=1.32.0"},{"fix":"Upgrade your project's TypeScript version to `5.9.3` or higher to ensure compatibility. Review any custom type definitions that might conflict with new library types.","message":"Genkit JavaScript SDK updated its core TypeScript dependency to `5.9.3`. Projects using older TypeScript versions might encounter compilation issues or type mismatches.","severity":"breaking","affected_versions":">=1.31.0"},{"fix":"Consult the official Genkit documentation on 'middleware' to understand the new API surface and recommended patterns for implementing generation-time logic such as caching, retries, or input/output transformations. Install `@genkit-ai/middleware` if needed.","message":"The introduction of `generate middleware` and the new `@genkit-ai/middleware` package in v1.33.0-rc.0 signifies a new pattern for modifying `generate()` calls. Existing custom middleware or direct manipulation of generation context might need to be refactored.","severity":"gotcha","affected_versions":">=1.33.0-rc.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install the package using npm: `npm install @genkit-ai/google-genai`.","cause":"The `@genkit-ai/google-genai` package has not been installed in the project.","error":"Error: Cannot find module '@genkit-ai/google-genai' or its corresponding type declarations."},{"fix":"Set the `GOOGLE_API_KEY` environment variable in your shell (`export GOOGLE_API_KEY='your-key'`), in a `.env` file, or pass it directly in the `googleGenai` plugin configuration.","cause":"The `apiKey` for the `googleGenai` plugin (or other model plugins) is missing, often due to a forgotten environment variable.","error":"Error: Genkit configuration error: GOOGLE_API_KEY environment variable is not set."},{"fix":"Review the `inputSchema` definition for the flow or model. Ensure the data passed to the flow or model's `generate` call strictly matches the expected types and structure.","cause":"Input provided to a Genkit flow (or model with structured input) does not conform to its defined Zod schema.","error":"ZodError: [ { \"code\": \"invalid_type\", \"expected\": \"string\", \"received\": \"number\", \"path\": [ \"mainIngredient\" ], \"message\": \"Expected string, received number\" } ]"}],"ecosystem":"npm"}