Skip to content

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.

  1. Create a directory for the Genkit sample project:
Terminal window
mkdir -p ~/tmp/genkit-any-project
cd ~/tmp/genkit-any-project
  1. Initialize a Dart project:
Terminal window
dart create -t console-simple .
  1. Add Genkit dependencies:
Terminal window
dart pub add genkit genkit_shelf shelf shelf_router genkit_google_genai
  1. Create a sample app using Genkit and Shelf:
bin/server.dart
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}');
}
  1. 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.

Terminal window
dart compile exe bin/server.dart -o server

The resulting server file is a standalone executable (on the same architecture).

  1. Deploy:

    Upload the server executable 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.