This guide shows you how to get started with Genkit in a Node.js app.
Prerequisites
This guide assumes that you're familiar with building applications with Node.js.
To complete this quickstart, make sure that your development environment meets the following requirements:
- Node.js v20+
- npm
Install Genkit dependencies
Install the following Genkit dependencies to use Genkit in your project:
@genkit-ai/ai
and@genkit-ai/core
provide Genkit core capabilities.@genkit-ai/googleai
provide access to the Google AI Gemini models.genkit
provides the Genkit CLI and tooling to help you test and debug your solution later.
npm install @genkit-ai/ai @genkit-ai/core @genkit-ai/googleai
npm install -g genkit
Configure your model API key
For this guide, we’ll show you how to use the Gemini API which provides a generous free tier and does not require a credit card to get started. To use the Gemini API, you'll need an API key. If you don't already have one, create a key in Google AI Studio.
Get an API key from Google AI Studio
After you’ve created an API key, set the GOOGLE_GENAI_API_KEY
environment variable to your key with the following command:
export GOOGLE_GENAI_API_KEY=<your API key>
Import the library
Import the Genkit core libraries and the plugin for the Google AI Gemini APIs.
import { generate } from '@genkit-ai/ai';
import { configureGenkit } from '@genkit-ai/core';
import { googleAI, gemini15Flash } from '@genkit-ai/googleai';
Make your first request
Use the generate
method to generate a text response.
configureGenkit({ plugins: [googleAI()] });
const result = await generate({
model: gemini15Flash,
prompt: 'Tell me a heroic story about a software developer.',
});
console.log(result.text())
Next steps
Now that you’re set up to make model requests with Genkit, learn how to use more Genkit capabilities to build your AI-powered apps and workflows. To get started with additional Genkit capabilities, see the following guides:
- Developer tools: Learn how to set up and use Genkit’s CLI and developer UI to help you locally test and debug your app.
- Generating content: Learn how to use Genkit’s unified generation API to generate text and structured data from any supported model.
- Creating flows: Learn how to use special Genkit functions, called flows, that provide end-to-end observability for workflows and rich debugging from Genkit tooling.
- Prompting models: Learn how Genkit lets you treat prompt templates as functions, encapsulating model configurations and input/output schema.