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_shelf shelf shelf_router genkit_google_genai- Create a sample app using Genkit and Shelf:
import 'dart:io';import 'package:genkit/genkit.dart';import 'package:genkit_shelf/genkit_shelf.dart';import 'package:genkit_google_genai/genkit_google_genai.dart';import 'package:shelf/shelf.dart';import 'package:shelf/shelf_io.dart' as io;import 'package:shelf_router/shelf_router.dart';import 'package:schemantic/schemantic.dart';
void main() async { final ai = Genkit( plugins: [googleAI(apiKey: Platform.environment['GOOGLE_API_KEY'])], model: googleAI.gemini('gemini-2.5-flash'), );
final flow = ai.defineFlow( name: 'flow', fn: (String input, _) async => 'Processed $input', inputSchema: .string(), outputSchema: .string(), );
final router = Router(); // Mount the flow handler router.post('/flow', shelfHandler(flow));
// Create a handler pipeline (e.g., adding logging) final handler = const Pipeline() .addMiddleware(logRequests()) .addHandler(router.call);
// Start the server final port = int.parse(Platform.environment['PORT'] ?? '8080'); final server = await io.serve(handler, InternetAddress.anyIPv4, port); print('Server running on port ${server.port}');}-
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 8080 in the code above).GOOGLE_API_KEY: Your Google GenAI API key.