Deploy to any platform
You can deploy Genkit flows as web services using any platform that can host a Dart executable. This page walks you through the general process of deploying the default sample flow.
- Create a directory for the Genkit sample project:
mkdir -p ~/tmp/genkit-any-projectcd ~/tmp/genkit-any-project- Initialize a Dart project:
dart create -t console-simple .- Add Genkit dependencies:
dart pub add genkit genkit_google_genai- Create a sample app that serves a flow over HTTP with
GenkitRouterfrompackage:genkit/io.dart. It only needsdart:io, no web framework:
import 'dart:io';
import 'package:genkit/genkit.dart';import 'package:genkit/io.dart';import 'package:genkit_google_genai/genkit_google_genai.dart';
void main() async { final ai = Genkit( plugins: [googleAI(apiKey: Platform.environment['GOOGLE_API_KEY'])], model: googleAI.gemini('gemini-flash-latest'), );
final flow = ai.defineFlow( name: 'flow', fn: (String input, _) async => 'Processed $input', inputSchema: .string(), outputSchema: .string(), );
// Each action becomes a POST route named after it: POST /flow final genkit = GenkitRouter()..addAction(flow);
// Listens on all interfaces, on $PORT if set, otherwise 3400. final server = await genkit.serve(); print('Server running on port ${server.port}');}If you already run a Shelf app, mount the same router into it with genkit_shelf instead. See the Shelf tutorial.
-
Compile for Deployment:
Dart applications can be compiled into self-contained executables (AOT compilation), which makes them easy to deploy without needing the full Dart SDK on the target server.
dart compile exe bin/server.dart -o serverThe resulting server file is a standalone executable (on the same architecture).
-
Deploy:
Upload the
serverexecutable to your hosting provider and configure it to run. Ensure you set the necessary environment variables:PORT: The port your server should listen on (defaults to 3400).GOOGLE_API_KEY: Your Google GenAI API key.