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_google_genai
  1. Create a sample app that serves a flow over HTTP with GenkitRouter from package:genkit/io.dart. It only needs dart:io, no web framework:
bin/server.dart
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.

  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 3400).
    • GOOGLE_API_KEY: Your Google GenAI API key.