io library

Serve Genkit flows, models and other actions over HTTP (dart:io).

import 'package:genkit/io.dart';

final genkit = GenkitRouter()
  ..addAction(helloFlow)
  ..addAction(secureFlow, contextProvider: bearerAuth);

await genkit.serve();

Or plug it into your own dart:io server with GenkitRouter.handleHttpRequest, or serve a single action with ioHandler. Other HTTP frameworks integrate through the framework-neutral GenkitRouter.handle, actionHandler and withCors (package:genkit_shelf is the shelf adapter).

Agents are served with addAgent from the experimental package:genkit/experimental_io.dart.

Depends on dart:io, so it does not work on the web.

Classes

CorsOptions
CORS settings for GenkitRouter.serve and GenkitRouter.handleHttpRequest.
GenkitHttpRequest
A framework-neutral HTTP request, the input of a GenkitHttpHandler.
GenkitHttpResponse
A framework-neutral HTTP response, the output of a GenkitHttpHandler.
GenkitRouter
Serves a set of Genkit actions over HTTP.
RequestData
What a ContextProvider sees of the incoming request.

Functions

actionHandler(Action action, {ContextProvider? contextProvider, bool sendLegacyErrorFrame = false}) → GenkitHttpHandler
Serves a single action (flow, model, tool, ...) as a framework-neutral GenkitHttpHandler.
ioHandler(Action action, {ContextProvider? contextProvider, bool sendLegacyErrorFrame = false}) → Future<void> Function(HttpRequest request)
Serves a single action as a dart:io request handler, the dart:io counterpart of Go's genkit.Handler.
withCors(CorsOptions options, GenkitHttpRequest request, GenkitHttpHandler inner) → Future<GenkitHttpResponse>
Applies options around inner; answers preflight OPTIONS itself.

Typedefs

ContextProvider = FutureOr<Map<String, dynamic>> Function(RequestData request)
Builds the action context for a request, typically from auth headers.
GenkitHttpHandler = Future<GenkitHttpResponse> Function(GenkitHttpRequest request)
Handles one GenkitHttpRequest. See actionHandler.