genkit library
The core Genkit framework library.
Use this library to define Flows, Models, and Tools.
This is the main entry point for creating Genkit applications.
Classes
- $BaseDataPoint
- $Candidate
- $CustomPart
- $DataPart
- $DocumentData
- $Embedding
- $EmbedRequest
- $EmbedResponse
- $EvalFnResponse
- $EvalRequest
- $GenerateActionOptions
- $GenerateActionOutputConfig
- $GenerateRequest
- $GenerateResponse
- $GenerateResumeOptions
- $GenerationUsage
- $Media
- $MediaPart
- $Message
- $MiddlewareRef
- $ModelInfo
- $ModelRequest
- $ModelResponse
- $ModelResponseChunk
- $Operation
- $OutputConfig
- $Part
- $ReasoningPart
- $ResourcePart
- $RuntimeError
- $Score
- $TextPart
- $ToolDefinition
- $ToolRequest
- $ToolRequestPart
- $ToolResponse
- $ToolResponsePart
-
Action<
Input, Output, Chunk, Init> -
ActionFnArg<
Chunk, Input, Init> - The per-invocation context handed to an action's implementation function.
-
ActionMetadata<
Input, Output, Chunk, Init> -
ActionStream<
Chunk, Response> - A stream of chunks emitted by an action, which also resolves to a final response.
- BaseDataPoint
- CancellationController
- The writable side of a cancellation.
- CancellationToken
- A read-only view of a cancellation request.
- Candidate
- CustomPart
- DataPart
- DocumentData
- DynamicActionProvider
- A provider that resolves actions (tools, prompts, resources) dynamically at runtime rather than registering them statically. Backs integrations such as the MCP host, where the available actions are discovered from a remote server and may change over time.
-
Embedder<
CustomOptions> -
EmbedderRef<
CustomOptions> - Embedding
- EmbedRequest
- EmbedResponse
- EvalFnResponse
- EvalFnResponseEvaluation
- EvalRequest
- Evaluator
-
Flow<
Input, Output, Chunk, Init> - GenerateActionOptions
- GenerateActionOutputConfig
- GenerateActionOutputConfigInstructions
- GenerateMiddleware
- Middleware for the processing of a Generation request.
- GenerateMiddlewareContext
- Ambient dependencies handed to a middleware factory at instantiation time.
-
GenerateMiddlewareDef<
CustomOptions> -
A named, configurable middleware, built with generateMiddleware or
ai.defineGenerateMiddleware. -
GenerateMiddlewareRef<
CustomOptions> - GenerateRequest
- GenerateResponse
-
GenerateResponseChunk<
Output> - A chunk of a response from a generate action: the model's chunk plus the partially parsed output and the chunks streamed before it.
-
GenerateResult<
Output> -
The result of
generate: the final model response plus the parsed output, the full conversation messages, and the originating request. - GenerateResumeOptions
- GenerateTurnState
- The state of one turn of the generate tool loop, as seen by GenerateMiddleware.generate.
- GenerationUsage
- Genkit
- The main entry point for creating Genkit applications.
- GenkitAI
- Encapsulates Genkit's AI APIs.
- GenkitPlugin
- A plugin for Genkit.
-
Interrupt<
Input, Output> - A special kind of Tool that always interrupts the generation loop.
- InterruptResponse
- A response to an interrupted tool request.
- Media
- MediaPart
- Message
- MiddlewareRef
-
Model<
CustomOptions> - ModelInfo
-
ModelRef<
CustomOptions> - ModelRequest
- ModelResponse
- ModelResponseChunk
- Operation
- OutputConfig
- Part
-
Prompt<
Input, Output> - A defined prompt that can render, generate, and stream.
-
PromptAction<
Input> - The registered action for a prompt.
- PromptRef
- Identifies a defined prompt: its registered name and metadata.
- ReasoningPart
- Registry
- Holds the actions, plugins, and named values of a Genkit instance.
- ResourceAction
- ResourceInput
- ResourceOutput
- ResourcePart
- RetryMiddleware
- A middleware that retries model and tool requests on failure.
- RetryOptions
-
RunResult<
Output> - RuntimeError
- Score
- ScoreScore
- SimulateConstrainedGenerationMiddleware
- Rewrites a constrained request into an unconstrained one that carries the schema as prompt instructions.
- TemplateHelperOptions
- Options passed to template helper functions during rendering.
- TextPart
-
Tool<
Input, Output> - ToolDefinition
-
ToolFnArg<
Input> - Arguments passed to a tool function execution.
-
ToolInterruptResult<
Output> - An interrupt result that bubbles the tool request back to the caller with an optional data payload.
- ToolRequest
- ToolRequestPart
- ToolResponse
- ToolResponsePart
-
ToolResponseResult<
Output> - A normal tool response carrying structured output and optional multipart parts and metadata.
-
ToolResult<
Output> - The result returned by a tool's implementation function.
Enums
- StatusCode
- Canonical status codes for Genkit operations.
Extension Types
- ActionType
-
Well-known action type identifiers used as the
actionTypeof an Action and as the first segment of its registry key (/$actionType/$name). - EvalStatus
- FinishReason
- Role
- ToolChoice
Extensions
- MessageExtension on Message
- ModelResponseChunkExtension on ModelResponseChunk
- ModelResponseExtension on ModelResponse
- PartExtension on Part
- Extension methods for Part.
- ToolRequestPartExtension on ToolRequestPart
- Extension methods for ToolRequestPart.
Functions
-
embedderMetadata(
String name, {SchemanticType? customOptions}) → ActionMetadata -
embedderRef<
CustomOptions> (String name, {SchemanticType< CustomOptions> ? customOptions}) → EmbedderRef<CustomOptions> -
generateMiddleware<
CustomOptions> ({required String name, required GenerateMiddleware create(CustomOptions? config, GenerateMiddlewareContext ctx), SchemanticType< CustomOptions> ? configSchema}) → GenerateMiddlewareDef<CustomOptions> -
Builds a middleware definition without registering it. For plugin authors:
return it from
GenkitPlugin.middleware. -
middlewareRef<
CustomOptions> ({required String name, CustomOptions? config}) → GenerateMiddlewareRef< CustomOptions> -
modelMetadata(
String name, {ModelInfo? info, SchemanticType? customOptions}) → ActionMetadata -
modelRef<
CustomOptions> (String name, {SchemanticType< CustomOptions> ? customOptions, CustomOptions? config}) → ModelRef<CustomOptions> -
retry(
{int? maxRetries, List< StatusCode> ? statuses, Duration? initialDelay, Duration? maxDelay, double? backoffFactor, bool? noJitter, bool? noRetryModel, bool? retryTools}) → GenerateMiddlewareRef<RetryOptions> - Retries failed model (and optionally tool) calls with exponential backoff.
-
simulateConstrainedGeneration(
) → GenerateMiddlewareRef< void> - Puts a requested output schema in the prompt instead of sending it to the model as a native constraint.
Typedefs
-
ActionFn<
Input, Output, Chunk, Init> = Future< Output> Function(Input input, ActionFnArg<Chunk, Input, Init> context) -
PromptFn<
Input> = Future< GenerateActionOptions> Function(Input input, ActionFnArg<void, Input, void> ctx) -
Builds the generate request for a custom prompt from its
input. -
RawActionFn<
Input, Output, Chunk, Init> = Future< Output> Function(Input? input, ActionFnArg<Chunk, Input, Init> context) - The low-level implementation function stored by Action.
-
ResourceFn
= Future<
ResourceOutput> Function(ResourceInput input, ActionFnArg<void, ResourceInput, void> ctx) -
StreamingCallback<
Chunk> = void Function(Chunk chunk) - TemplateHelperFn = dynamic Function(List args, TemplateHelperOptions options)
- Function signature for custom Handlebars helper functions.
-
ToolFn<
Input, Output> = FutureOr< ToolResult< Function(Input input, ToolFnArg<Output> >Input> context) - A function that implements a tool.
- TraceStartCallback = void Function({required String spanId, required String traceId})
Exceptions / Errors
- CancelledException
- Thrown when an operation is aborted via a CancellationToken.
- GenkitException
- Exception thrown for errors encountered during Genkit flow operations.