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
provides Genkit core capabilities.@genkit-ai/googleai
provides access to the Google AI Gemini models.
npminstallgenkit@genkit-ai/googleai
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 GEMINI_API_KEY
environment variable to your key with the following command:
exportGEMINI_API_KEY=<yourAPIkey>
Make your first request
Get started with Genkit in just a few lines of simple code.
// import the Genkit and Google AI plugin librariesimport{gemini20Flash,googleAI}from'@genkit-ai/googleai';import{genkit}from'genkit';// configure a Genkit instanceconstai=genkit({plugins:[googleAI()],model:gemini20Flash,// set default model});asyncfunctionmain(){// make a generation requestconst{text}=awaitai.generate('Hello, Gemini!');console.log(text);}main();
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.
- Managing prompts: Learn how Genkit helps you manage your prompts and configuration together as code.
- Integrating in an app: Walk through a deployed example of multiple Genkit flows powering a web app.