client library

Client-side utilities for interacting with Genkit.

Use this library when building clients (e.g., web or mobile apps) that communicate with Genkit actions or flows, or when using Genkit in a purely client-side context (e.g. with Chrome AI).

Classes

$AgentAbortRequest
$AgentAbortResponse
$AgentErrorInfo
$AgentInit
$AgentInput
$AgentMetadata
$AgentOutput
$AgentResult
$AgentResume
$AgentStreamChunk
$Artifact
$BaseDataPoint
$Candidate
$CustomPart
$DataPart
$DocumentData
$Embedding
$EmbedRequest
$EmbedResponse
$EvalFnResponse
$EvalRequest
$GenerateActionOptions
$GenerateActionOutputConfig
$GenerateRequest
$GenerateResponse
$GenerateResumeOptions
$GenerationUsage
$GetSnapshotDataInput
$JsonPatchOperation
$Media
$MediaPart
$Message
$MiddlewareRef
$ModelInfo
$ModelRequest
$ModelResponse
$ModelResponseChunk
$Operation
$OutputConfig
$Part
$ReasoningPart
$ReflectionCancelActionParams
$ReflectionCancelActionResponse
$ReflectionConfigureParams
$ReflectionEndInputStreamParams
$ReflectionListActionsResponse
$ReflectionListValuesParams
$ReflectionListValuesResponse
$ReflectionRegisterParams
$ReflectionRunActionParams
$ReflectionRunActionStateParams
$ReflectionSendInputStreamChunkParams
$ReflectionStreamChunkParams
$ResourcePart
$Score
$SessionSnapshot
$SessionState
$TextPart
$ToolDefinition
$ToolRequest
$ToolRequestPart
$ToolResponse
$ToolResponsePart
$TurnEnd
ActionStream<Chunk, Response>
A stream of chunks emitted by an action, which also resolves to a final response.
AgentAbortRequest
AgentAbortResponse
AgentApi<State>
The transport-agnostic surface for talking to an agent. The same shape is returned by ai.defineAgent(...) on the server and by remoteAgent(...) on the client.
AgentChat<State>
A stateful conversation with an agent. Tracks state across turns so callers do not have to thread snapshotId/state by hand.
AgentChunk<State>
A streamed chunk. Mirrors GenerateResponseChunk and adds the agent fields (artifact, custom).
AgentErrorInfo
AgentInit
AgentInput
AgentInterrupt<Input, Output>
A single tool request a turn paused on. respond/restart are builders: they return the part to put into a resume payload; they do not send.
AgentMetadata
AgentOutput
AgentResponse<State>
The completed result of a turn. Mirrors GenerateResponse and adds the agent fields (snapshotId, state, artifacts).
AgentResult
AgentResume
AgentSnapshot<State>
A generate-style, typed veneer over a raw SessionSnapshot. Mirrors how AgentResponse wraps an AgentOutput: it delegates the snapshot's scalar fields and surfaces the aggregates (messages, artifacts) and the typed custom state (custom), while keeping the untyped wire objects reachable via sessionState / raw.
AgentStreamChunk
AgentTransport
The pluggable backend the agent-client core runs over. Implementations exist for the in-process server agent (driving the agent action directly) and for the HTTP remoteAgent (driving stream/run calls).
AgentTurn<State>
A single in-flight turn — the analog of generateStream's {stream, response}, plus abort.
Artifact
BaseDataPoint
CancellationToken
A minimal cooperative cancellation primitive, the Dart stand-in for the Web's AbortSignal/AbortController.
Candidate
CustomPart
DataPart
DetachedTask<State>
A handle to a background (detached) task.
DocumentData
Embedding
EmbedRequest
EmbedResponse
EvalFnResponse
EvalFnResponseEvaluation
EvalRequest
GenerateActionOptions
GenerateActionOutputConfig
GenerateActionOutputConfigInstructions
GenerateRequest
GenerateResponse
GenerateResumeOptions
GenerationUsage
GetSnapshotDataInput
JsonPatchOperation
Media
MediaPart
Message
MiddlewareRef
ModelInfo
ModelRequest
ModelResponse
ModelResponseChunk
Operation
OutputConfig
Part
ReasoningPart
ReflectionCancelActionParams
ReflectionCancelActionResponse
ReflectionConfigureParams
ReflectionEndInputStreamParams
ReflectionListActionsResponse
ReflectionListValuesParams
ReflectionListValuesResponse
ReflectionRegisterParams
ReflectionRunActionParams
ReflectionRunActionStateParams
ReflectionSendInputStreamChunkParams
ReflectionStreamChunkParams
RemoteAction<Input, Output, Chunk, Init>
Represents a remote Genkit action (flow) that can be invoked or streamed.
ResourcePart
Score
ScoreScore
SessionSnapshot
SessionState
TextPart
ToolDefinition
ToolRequest
ToolRequestPart
ToolResponse
ToolResponsePart
TurnEnd

Enums

StatusCodes
Exception thrown for errors encountered during Genkit flow operations. Common status codes for Genkit operations.

Functions

applyPatch(Object? document, JsonPatch patch) Object?
Applies an RFC 6902 JSON Patch to document, returning the new value.
defineRemoteAction<Input, Output, Chunk, Init>({required String url, Map<String, String>? defaultHeaders, Client? httpClient, Output fromResponse(dynamic jsonData)?, Chunk fromStreamChunk(dynamic jsonData)?, SchemanticType<Input>? inputSchema, SchemanticType<Output>? outputSchema, SchemanticType<Chunk>? streamSchema}) RemoteAction<Input, Output, Chunk, Init>
Defines a remote Genkit action (flow) client.
diff(Object? from, Object? to) JsonPatch
Computes an RFC 6902 JSON Patch that transforms from into to.
remoteAgent<State>({required String url, String? getSnapshotUrl, String? abortUrl, HeadersResolver? headers, AgentStateManagement? stateManagement, SchemanticType<State>? stateSchema, Client? httpClient}) AgentApi<State>
Creates a typed client for talking to a Genkit agent over HTTP.

Typedefs

HeadersResolver = FutureOr<Map<String, String>?> Function()
Resolves request headers, either statically or per request.
JsonPatch = List<JsonPatchOperationMap>
An RFC 6902 JSON Patch: an ordered list of operations.
JsonPatchOperationMap = Map<String, dynamic>
A single RFC 6902 (JSON Patch) operation, as a plain JSON map: {op, path, from?, value?}.
TurnStream = ({Future<AgentOutput> output, Stream<AgentStreamChunk> stream})
The streamed result of a single turn: incremental stream chunks plus an output future for the final, non-throwing AgentOutput (failures resolve with finishReason: 'failed').

Exceptions / Errors

AgentError<State>
Thrown when a turn fails. Carries the last-good state so the session is recoverable.
GenkitException
Exception thrown for errors encountered during Genkit flow operations.