Skip to main content
The Genkit Python SDK is in alpha. Core functionality — text generation, flows, tools, and structured output — is available and works, but APIs are subject to change before the stable release. Production use is not yet recommended.
This guide walks you through installing Genkit for Python, writing your first AI-powered async function, and exploring it with the local Developer UI.
1

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 GoogleAI plugin also accepts GEMINI_API_KEY. You can pass the key explicitly as GoogleAI(api_key='...'), but using an environment variable keeps credentials out of source control.
2

Install dependencies

Install the Genkit core package and the Google AI plugin:
Install the Genkit CLI to use the Developer UI:
The Genkit CLI is distributed via npm regardless of the language you use for your app. Node.js 18+ is required only for the CLI and Developer UI — your Python application does not depend on Node.
3

Write your first Genkit app

Create main.py:
Run the app:
4

Explore with the Developer UI

The Genkit CLI wraps your app with tracing and launches a local Developer UI where you can run flows interactively and inspect execution traces.
This starts your app, then opens the Developer UI at http://localhost:4000. From there you can:
  • Run the tell_joke flow against any input without restarting your app.
  • Inspect traces to see the full prompt and response exchanged with Gemini.
  • Compare models by switching between available Gemini variants in real time.
Set GENKIT_ENV=dev in your environment to keep the reflection server running even when started outside the genkit start command.
5

Add structured output (optional)

Pass a Pydantic BaseModel as the output schema and Genkit will validate the model’s response for you:
6

Define tools (optional)

Tools let the model call Python functions to access real-time data or take actions:

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.

Concepts: Tools

Let models call Python functions to fetch data, take actions, and more.

Guides: Structured output

Return validated Pydantic models from any generation call.

Guides: Streaming

Stream tokens as they arrive with ai.generate_stream().

Plugins: Google AI

Full reference for the genkit-google-genai plugin including Vertex AI and embeddings.

Plugins overview

Browse available plugins: Vertex AI, Ollama, Anthropic, Firebase, and more.

Developer tools

Deep dive into the Genkit CLI and Developer UI.