Get a Google AI API key
Genkit’s Google AI plugin uses the Gemini API. Get a free API key from Google AI Studio.
Set the key as an environment variable before running any Genkit code:The plugin also accepts
GEMINI_API_KEY and GOOGLE_API_KEY. You can alternatively pass the key directly as googleAI({ apiKey: '...' }), but using an environment variable is recommended so credentials are never committed to source control.Install dependencies
Create a new Node.js project (or open an existing one), then install Genkit and the Google AI plugin:Install the Genkit CLI globally so you can use the Developer UI:
Write your first Genkit app
Create Run it with
src/index.ts with the following content:tsx (or compile with tsc first):Explore with the Developer UI
The Genkit CLI wraps your app with tracing and launches a local Developer UI where you can run flows, inspect execution traces, and compare model outputs interactively.The CLI starts your app, then opens the Developer UI at
http://localhost:4000. In the UI you can:- Run the
tellJokeflow against any input without touching your code. - Inspect traces to see exactly what was sent to and received from the model.
- Tweak prompts and compare outputs across different Gemini model variants.
Next steps
Concepts: Flows
Learn how flows add observability, retries, and HTTP exposure to any AI function.
Concepts: Models
Understand model references, config options, multimodal inputs, and streaming.
Guides: Structured output
Return validated, type-safe JSON from any model call using Zod schemas.
Guides: Streaming
Stream tokens to the client as they are generated for a faster perceived response.
Guides: Agents
Build multi-step agentic workflows with tool calling and looping.
Plugins: Google AI
Full reference for the
@genkit-ai/google-genai plugin including Vertex AI, Imagen, and embeddings.Plugins overview
Browse all available plugins: Vertex AI, Ollama, Firebase, and community providers.
Developer tools
Deep dive into the Genkit CLI and Developer UI.
