Response
Defines a shared data model for AI model output.
Responses are represented as typed parts so different providers can expose text, reasoning, tool calls, files, sources, metadata, finish information, and errors through one shape. The same model is used for complete responses and streaming responses, where start, delta, and end parts describe content as it arrives. This module also carries provider metadata and schemas used by tools that need to validate response parts.
Configuration
DocumentSourcePartMetadata interface
Signature
interface DocumentSourcePartMetadata extends ProviderMetadata {
[key: string]: Json;
}ErrorPartMetadata interface
Represents provider-specific metadata that can be associated with a ErrorPart through module augmentation.
Signature
interface ErrorPartMetadata extends ProviderMetadata {
[key: string]: Json;
}FilePartMetadata interface
Represents provider-specific metadata that can be associated with a FilePart through module augmentation.
Signature
interface FilePartMetadata extends ProviderMetadata {
[key: string]: Json;
}FinishPartMetadata interface
Represents provider-specific metadata that can be associated with a FinishPart through module augmentation.
Signature
interface FinishPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ReasoningDeltaPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningDeltaPart through module augmentation.
Signature
interface ReasoningDeltaPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ReasoningEndPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningEndPart through module augmentation.
Signature
interface ReasoningEndPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ReasoningPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningPart through module augmentation.
Signature
interface ReasoningPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ReasoningStartPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningStartPart through module augmentation.
Signature
interface ReasoningStartPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ResponseMetadataPartMetadata interface
Represents provider-specific metadata that can be associated with a ResponseMetadataPart through module augmentation.
Signature
interface ResponseMetadataPartMetadata extends ProviderMetadata {
[key: string]: Json;
}TextDeltaPartMetadata interface
Represents provider-specific metadata that can be associated with a TextDeltaPart through module augmentation.
Signature
interface TextDeltaPartMetadata extends ProviderMetadata {
[key: string]: Json;
}TextEndPartMetadata interface
Represents provider-specific metadata that can be associated with a TextEndPart through module augmentation.
Signature
interface TextEndPartMetadata extends ProviderMetadata {
[key: string]: Json;
}TextPartMetadata interface
Represents provider-specific metadata that can be associated with a TextPart through module augmentation.
Signature
interface TextPartMetadata extends ProviderMetadata {
[key: string]: Json;
}TextStartPartMetadata interface
Represents provider-specific metadata that can be associated with a TextStartPart through module augmentation.
Signature
interface TextStartPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ToolApprovalRequestPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolApprovalRequestPart through module augmentation.
Signature
interface ToolApprovalRequestPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ToolCallPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolCallPart through module augmentation.
Signature
interface ToolCallPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ToolParamsDeltaPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolParamsDeltaPart through module augmentation.
Signature
interface ToolParamsDeltaPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ToolParamsEndPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolParamsEndPart through module augmentation.
Signature
interface ToolParamsEndPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ToolParamsStartPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolParamsStartPart through module augmentation.
Signature
interface ToolParamsStartPartMetadata extends ProviderMetadata {
[key: string]: Json;
}ToolResultPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolResultPart through module augmentation.
Signature
interface ToolResultPartMetadata extends ProviderMetadata {
[key: string]: Json;
}UrlSourcePartMetadata interface
Represents provider-specific metadata that can be associated with a UrlSourcePart through module augmentation.
Signature
interface UrlSourcePartMetadata extends ProviderMetadata {
[key: string]: Json;
}Constructors
Creates a new response content part of the specified type.
Signature
declare function makePart<
Type extends
| "error"
| "source"
| "tool-approval-request"
| "file"
| "response-metadata"
| "finish"
| "text"
| "reasoning"
| "tool-call"
| "text-start"
| "text-delta"
| "text-end"
| "reasoning-start"
| "reasoning-delta"
| "reasoning-end"
| "tool-params-start"
| "tool-params-delta"
| "tool-params-end"
| "tool-result",
>(
type: Type,
params: Omit<
| Extract<
TextStartPart,
{
type: Type;
}
>
| Extract<
TextDeltaPart,
{
type: Type;
}
>
| Extract<
TextEndPart,
{
type: Type;
}
>
| Extract<
ReasoningStartPart,
{
type: Type;
}
>
| Extract<
ReasoningDeltaPart,
{
type: Type;
}
>
| Extract<
ReasoningEndPart,
{
type: Type;
}
>
| Extract<
ToolParamsStartPart,
{
type: Type;
}
>
| Extract<
ToolParamsDeltaPart,
{
type: Type;
}
>
| Extract<
ToolParamsEndPart,
{
type: Type;
}
>
| Extract<
ToolApprovalRequestPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
DocumentSourcePart,
{
type: Type;
}
>
| Extract<
UrlSourcePart,
{
type: Type;
}
>
| Extract<
ResponseMetadataPart,
{
type: Type;
}
>
| Extract<
FinishPart,
{
type: Type;
}
>
| Extract<
ErrorPart,
{
type: Type;
}
>
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
ToolCallPart<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultSuccess<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultFailure<any, any>,
{
type: Type;
}
>,
"type" | "metadata" | "~effect/ai/Content/Part"
> & {
readonly metadata?:
| Extract<
TextStartPart,
{
type: Type;
}
>
| Extract<
TextDeltaPart,
{
type: Type;
}
>
| Extract<
TextEndPart,
{
type: Type;
}
>
| Extract<
ReasoningStartPart,
{
type: Type;
}
>
| Extract<
ReasoningDeltaPart,
{
type: Type;
}
>
| Extract<
ReasoningEndPart,
{
type: Type;
}
>
| Extract<
ToolParamsStartPart,
{
type: Type;
}
>
| Extract<
ToolParamsDeltaPart,
{
type: Type;
}
>
| Extract<
ToolParamsEndPart,
{
type: Type;
}
>
| Extract<
ToolApprovalRequestPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
DocumentSourcePart,
{
type: Type;
}
>
| Extract<
UrlSourcePart,
{
type: Type;
}
>
| Extract<
ResponseMetadataPart,
{
type: Type;
}
>
| Extract<
FinishPart,
{
type: Type;
}
>
| Extract<
ErrorPart,
{
type: Type;
}
>
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
ToolCallPart<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultSuccess<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultFailure<any, any>,
{
type: Type;
}
>["metadata"];
},
):
| Extract<
TextStartPart,
{
type: Type;
}
>
| Extract<
TextDeltaPart,
{
type: Type;
}
>
| Extract<
TextEndPart,
{
type: Type;
}
>
| Extract<
ReasoningStartPart,
{
type: Type;
}
>
| Extract<
ReasoningDeltaPart,
{
type: Type;
}
>
| Extract<
ReasoningEndPart,
{
type: Type;
}
>
| Extract<
ToolParamsStartPart,
{
type: Type;
}
>
| Extract<
ToolParamsDeltaPart,
{
type: Type;
}
>
| Extract<
ToolParamsEndPart,
{
type: Type;
}
>
| Extract<
ToolApprovalRequestPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
DocumentSourcePart,
{
type: Type;
}
>
| Extract<
UrlSourcePart,
{
type: Type;
}
>
| Extract<
ResponseMetadataPart,
{
type: Type;
}
>
| Extract<
FinishPart,
{
type: Type;
}
>
| Extract<
ErrorPart,
{
type: Type;
}
>
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
ToolCallPart<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultSuccess<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultFailure<any, any>,
{
type: Type;
}
>;toolApprovalRequestPart
Constructs a new tool approval request part.
Signature
declare function toolApprovalRequestPart(
params: ConstructorParams<ToolApprovalRequestPart>,
): ToolApprovalRequestPart;toolCallPart
Constructs a new tool call part.
Signature
declare function toolCallPart<Name extends string, Params>(
params: ConstructorParams<ToolCallPart<Name, Params>>,
): ToolCallPart<Name, Params>;toolResultPart
Constructs a new tool result part.
Signature
declare function toolResultPart<
Params extends ConstructorParams<ToolResultPart<string, unknown, unknown>>,
>(
params: Params,
): Params extends {
readonly isFailure: false;
readonly name: Name;
readonly result: Success;
}
? ToolResultPart<Name, Success, never>
: Params extends {
readonly isFailure: true;
readonly name: Name;
readonly result: Failure;
}
? ToolResultPart<Name, never, Failure>
: never;Guards
Models
Union type for all response parts with tool-specific typing.
Signature
type AllParts<Tools extends Record<string, Tool.Any>> =
| TextPart
| TextStartPart
| TextDeltaPart
| TextEndPart
| ReasoningPart
| ReasoningStartPart
| ReasoningDeltaPart
| ReasoningEndPart
| ToolParamsStartPart
| ToolParamsDeltaPart
| ToolParamsEndPart
| ToolCallParts<Tools>
| ToolResultParts<Tools>
| ToolApprovalRequestPart
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart
| ErrorPart;AllPartsEncoded type
Encoded representation of all response parts for serialization.
Signature
type AllPartsEncoded =
| TextPartEncoded
| TextStartPartEncoded
| TextDeltaPartEncoded
| TextEndPartEncoded
| ReasoningPartEncoded
| ReasoningStartPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolParamsStartPartEncoded
| ToolParamsDeltaPartEncoded
| ToolParamsEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| ToolApprovalRequestPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded
| ErrorPartEncoded;Union type representing all possible response content parts.
Signature
type AnyPart =
| TextPart
| TextStartPart
| TextDeltaPart
| TextEndPart
| ReasoningPart
| ReasoningStartPart
| ReasoningDeltaPart
| ReasoningEndPart
| ToolParamsStartPart
| ToolParamsDeltaPart
| ToolParamsEndPart
| ToolCallPart<any, any>
| ToolResultPart<any, any, any>
| ToolApprovalRequestPart
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart
| ErrorPart;AnyPartEncoded type
Encoded representation of all possible response content parts for serialization.
Signature
type AnyPartEncoded =
| TextPartEncoded
| TextStartPartEncoded
| TextDeltaPartEncoded
| TextEndPartEncoded
| ReasoningPartEncoded
| ReasoningStartPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolParamsStartPartEncoded
| ToolParamsDeltaPartEncoded
| ToolParamsEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| ToolApprovalRequestPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded
| ErrorPartEncoded;Base interface for all response content parts, including the type identifier and optional metadata.
Signature
interface BasePart<Type extends string, Metadata extends ProviderMetadata> {
readonly "~effect/ai/Content/Part": "~effect/ai/Content/Part";
readonly metadata: Metadata;
readonly type: Type;
}BasePartEncoded interface
Base interface for encoded response content parts.
Signature
interface BasePartEncoded<Type extends string, Metadata extends ProviderMetadata> {
readonly metadata?: Metadata;
readonly type: Type;
}BaseToolResult interface
The base fields of a tool result part.
Signature
interface BaseToolResult<Name extends string> extends BasePart<
"tool-result",
ToolResultPartMetadata
> {
readonly encodedResult: unknown;
readonly id: string;
readonly name: Name;
readonly preliminary: boolean;
readonly providerExecuted: boolean;
}DocumentSourcePart interface
Response part representing a document source reference used in generating the response.
Signature
interface DocumentSourcePart extends BasePart<"source", DocumentSourcePartMetadata> {
readonly fileName?: string;
readonly id: string;
readonly mediaType: string;
readonly sourceType: "document";
readonly title: string;
}DocumentSourcePartEncoded interface
Encoded representation of document source parts for serialization.
Signature
interface DocumentSourcePartEncoded extends BasePartEncoded<"source", DocumentSourcePartMetadata> {
readonly fileName?: string;
readonly id: string;
readonly mediaType: string;
readonly sourceType: "document";
readonly title: string;
}Response part indicating that an error occurred generating the response.
Signature
interface ErrorPart extends BasePart<"error", ErrorPartMetadata> {
readonly error: unknown;
}ErrorPartEncoded interface
Encoded representation of error parts for serialization.
Signature
interface ErrorPartEncoded extends BasePartEncoded<"error", ErrorPartMetadata> {
readonly error: unknown;
}Response part representing a file attachment.
Details
Supports various file types including images, documents, and binary data.
Signature
interface FilePart extends BasePart<"file", FilePartMetadata> {
readonly data: Uint8Array;
readonly mediaType: string;
}FilePartEncoded interface
Encoded representation of file parts for serialization.
Signature
interface FilePartEncoded extends BasePartEncoded<"file", FilePartMetadata> {
readonly data: string;
readonly mediaType: string;
}FinishPart interface
Response part indicating the completion of a response generation.
Signature
interface FinishPart extends BasePart<"finish", FinishPartMetadata> {
readonly reason:
| "length"
| "error"
| "stop"
| "content-filter"
| "tool-calls"
| "pause"
| "other"
| "unknown";
readonly response?: {
readonly headers: {
[key: string]: string | Redacted<string>;
};
readonly status: number;
};
readonly usage: Usage;
}FinishPartEncoded interface
Encoded representation of finish parts for serialization.
Signature
interface FinishPartEncoded extends BasePartEncoded<"finish", FinishPartMetadata> {
readonly reason:
| "length"
| "error"
| "stop"
| "content-filter"
| "tool-calls"
| "pause"
| "other"
| "unknown";
readonly response?: {
readonly headers: {
[key: string]: string | Redacted<string>;
};
readonly status: number;
};
readonly usage: {
readonly inputTokens: {
readonly cacheRead?: number;
readonly cacheWrite?: number;
readonly total?: number;
readonly uncached?: number;
};
readonly outputTokens: {
readonly reasoning?: number;
readonly text?: number;
readonly total?: number;
};
};
}FinishReason
Represents the reason why a model finished generation of a response.
Details
Possible finish reasons: - "stop": The model generated a stop sequence. - "length": The model exceeded its token budget. - "content-filter": The model generated content which violated a content filter. - "tool-calls": The model triggered a tool call. - "error": The model encountered an error. - "pause": The model requested to pause execution. - "other": The model stopped for a reason not supported by this protocol. - "unknown": The model did not specify a finish reason.
Signature
declare const FinishReason: Schema.Literals<
["stop", "length", "content-filter", "tool-calls", "error", "pause", "other", "unknown"]
>;FinishReason type
Type of the reason why a model stopped generating a response.
Details
Values include normal stops, token-limit stops, content filtering, tool-call pauses, provider errors, and unknown provider-specific finish reasons.
Signature
type FinishReason = typeof FinishReason.Type;A type for representing non-streaming response parts with tool-specific typing.
Signature
type Part<Tools extends Record<string, Tool.Any>> =
| TextPart
| ReasoningPart
| ToolCallParts<Tools>
| ToolResultParts<Tools>
| ToolApprovalRequestPart
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart;PartEncoded type
Encoded representation of non-streaming response parts for serialization.
Signature
type PartEncoded =
| TextPartEncoded
| ReasoningPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| ToolApprovalRequestPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded;ProviderMetadata type
Type of provider-specific metadata attached to response parts, keyed by provider-specific names with JSON or null values.
Signature
type ProviderMetadata = typeof ProviderMetadata.Type;ReasoningDeltaPart interface
Response part containing incremental reasoning content to be added to the existing chunk of reasoning text with the same unique identifier.
Signature
interface ReasoningDeltaPart extends BasePart<"reasoning-delta", ReasoningDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}ReasoningDeltaPartEncoded interface
Encoded representation of reasoning delta parts for serialization.
Signature
interface ReasoningDeltaPartEncoded extends BasePartEncoded<
"reasoning-delta",
ReasoningDeltaPartMetadata
> {
readonly delta: string;
readonly id: string;
}ReasoningEndPart interface
Response part indicating the completion of a streaming reasoning chunk.
Signature
interface ReasoningEndPart extends BasePart<"reasoning-end", ReasoningEndPartMetadata> {
readonly id: string;
}ReasoningEndPartEncoded interface
Encoded representation of reasoning end parts for serialization.
Signature
interface ReasoningEndPartEncoded extends BasePartEncoded<
"reasoning-end",
ReasoningEndPartMetadata
> {
readonly id: string;
}ReasoningPart interface
Response part carrying provider-supplied reasoning text, such as an exposed reasoning summary or explanation. Do not assume it contains hidden chain-of-thought.
Signature
interface ReasoningPart extends BasePart<"reasoning", ReasoningPartMetadata> {
readonly text: string;
}ReasoningPartEncoded interface
Encoded representation of reasoning parts for serialization.
Signature
interface ReasoningPartEncoded extends BasePartEncoded<"reasoning", ReasoningPartMetadata> {
readonly text: string;
}ReasoningStartPart interface
Response part indicating the start of streaming reasoning content with a unique reasoning chunk identifier.
Signature
interface ReasoningStartPart extends BasePart<"reasoning-start", ReasoningStartPartMetadata> {
readonly id: string;
}ReasoningStartPartEncoded interface
Encoded representation of reasoning start parts for serialization.
Signature
interface ReasoningStartPartEncoded extends BasePartEncoded<
"reasoning-start",
ReasoningStartPartMetadata
> {
readonly id: string;
}ResponseMetadataPart interface
Response part containing metadata about the large language model response.
Signature
interface ResponseMetadataPart extends BasePart<"response-metadata", ResponseMetadataPartMetadata> {
readonly id?: string;
readonly modelId?: string;
readonly request?: {
readonly hash?: string;
readonly headers: {
[key: string]: string | Redacted<string>;
};
readonly method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "TRACE";
readonly url: string;
readonly urlParams: readonly Array<readonly [string, string]>;
};
readonly timestamp?: Utc;
}ResponseMetadataPartEncoded interface
Encoded representation of response metadata parts for serialization.
Signature
interface ResponseMetadataPartEncoded extends BasePartEncoded<"response-metadata", ResponseMetadataPartMetadata> {
readonly id?: string;
readonly modelId?: string;
readonly request?: {
readonly hash?: string;
readonly headers: {
[key: string]: string | Redacted<string>;
};
readonly method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "TRACE";
readonly url: string;
readonly urlParams: readonly Array<readonly [string, string]>;
};
readonly timestamp?: string;
}StreamPart type
A type for representing streaming response parts with tool-specific typing.
Signature
type StreamPart<Tools extends Record<string, Tool.Any>> =
| TextStartPart
| TextDeltaPart
| TextEndPart
| ReasoningStartPart
| ReasoningDeltaPart
| ReasoningEndPart
| ToolParamsStartPart
| ToolParamsDeltaPart
| ToolParamsEndPart
| ToolCallParts<Tools>
| ToolResultParts<Tools>
| ToolApprovalRequestPart
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart
| ErrorPart;StreamPartEncoded type
Encoded representation of streaming response parts for serialization.
Signature
type StreamPartEncoded =
| TextStartPartEncoded
| TextDeltaPartEncoded
| TextEndPartEncoded
| ReasoningStartPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolParamsStartPartEncoded
| ToolParamsDeltaPartEncoded
| ToolParamsEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| ToolApprovalRequestPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded
| ErrorPartEncoded;TextDeltaPart interface
Response part containing incremental text content to be added to the existing text chunk with the same unique identifier.
Signature
interface TextDeltaPart extends BasePart<"text-delta", TextDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}TextDeltaPartEncoded interface
Encoded representation of text delta parts for serialization.
Signature
interface TextDeltaPartEncoded extends BasePartEncoded<"text-delta", TextDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}TextEndPart interface
Response part indicating the completion of a streaming text chunk.
Signature
interface TextEndPart extends BasePart<"text-end", TextEndPartMetadata> {
readonly id: string;
}TextEndPartEncoded interface
Encoded representation of text end parts for serialization.
Signature
interface TextEndPartEncoded extends BasePartEncoded<"text-end", TextEndPartMetadata> {
readonly id: string;
}Response part representing plain text content.
Signature
interface TextPart extends BasePart<"text", TextPartMetadata> {
readonly text: string;
}TextPartEncoded interface
Encoded representation of text parts for serialization.
Signature
interface TextPartEncoded extends BasePartEncoded<"text", TextPartMetadata> {
readonly text: string;
}TextStartPart interface
Response part indicating the start of streaming text content with a unique text chunk identifier.
Signature
interface TextStartPart extends BasePart<"text-start", TextStartPartMetadata> {
readonly id: string;
}TextStartPartEncoded interface
Encoded representation of text start parts for serialization.
Signature
interface TextStartPartEncoded extends BasePartEncoded<"text-start", TextStartPartMetadata> {
readonly id: string;
}ToolApprovalRequestPart interface
Response part representing a tool approval request.
Details
Emitted when a tool requires user approval before execution. The framework checks the tool's needsApproval property and emits this part instead of executing the tool when approval is required.
Signature
interface ToolApprovalRequestPart extends BasePart<
"tool-approval-request",
ToolApprovalRequestPartMetadata
> {
readonly approvalId: string;
readonly toolCallId: string;
}ToolApprovalRequestPartEncoded interface
Encoded representation of tool approval request parts for serialization.
Signature
interface ToolApprovalRequestPartEncoded extends BasePartEncoded<
"tool-approval-request",
ToolApprovalRequestPartMetadata
> {
readonly approvalId: string;
readonly toolCallId: string;
}ToolCallPart interface
Response part representing a tool call request.
Signature
interface ToolCallPart<Name extends string, Params> extends BasePart<
"tool-call",
ToolCallPartMetadata
> {
readonly id: string;
readonly name: Name;
readonly params: Params;
readonly providerExecuted: boolean;
}ToolCallPartEncoded interface
Encoded representation of tool call parts for serialization.
Signature
interface ToolCallPartEncoded extends BasePartEncoded<"tool-call", ToolCallPartMetadata> {
readonly id: string;
readonly name: string;
readonly params: unknown;
readonly providerExecuted?: boolean;
}ToolParamsDeltaPart interface
Response part containing incremental tool parameter content.
Details
Represents a chunk of tool parameters being streamed, containing the incremental JSON content that forms the tool parameters.
Signature
interface ToolParamsDeltaPart extends BasePart<"tool-params-delta", ToolParamsDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}ToolParamsDeltaPartEncoded interface
Encoded representation of tool params delta parts for serialization.
Signature
interface ToolParamsDeltaPartEncoded extends BasePartEncoded<
"tool-params-delta",
ToolParamsDeltaPartMetadata
> {
readonly delta: string;
readonly id: string;
}ToolParamsEndPart interface
Response part indicating the end of streaming tool parameters.
Details
Marks the completion of a tool parameter stream, indicating that all parameter data has been sent and the tool call is ready to be executed.
Signature
interface ToolParamsEndPart extends BasePart<"tool-params-end", ToolParamsEndPartMetadata> {
readonly id: string;
}ToolParamsEndPartEncoded interface
Encoded representation of tool params end parts for serialization.
Signature
interface ToolParamsEndPartEncoded extends BasePartEncoded<
"tool-params-end",
ToolParamsEndPartMetadata
> {
readonly id: string;
}ToolParamsStartPart interface
Response part indicating the start of streaming tool parameters.
Details
Marks the beginning of tool parameter streaming with metadata about the tool call.
Signature
interface ToolParamsStartPart extends BasePart<"tool-params-start", ToolParamsStartPartMetadata> {
readonly id: string;
readonly name: string;
readonly providerExecuted: boolean;
}ToolParamsStartPartEncoded interface
Encoded representation of tool params start parts for serialization.
Signature
interface ToolParamsStartPartEncoded extends BasePartEncoded<
"tool-params-start",
ToolParamsStartPartMetadata
> {
readonly id: string;
readonly name: string;
readonly providerExecuted?: boolean;
}ToolResultFailure interface
Represents a failed tool call result.
Signature
interface ToolResultFailure<Name extends string, Failure> extends BaseToolResult<Name> {
readonly isFailure: true;
readonly result: Failure;
}ToolResultPart type
Response part representing the result of a tool call.
Signature
type ToolResultPart<Name extends string, Success, Failure> =
| ToolResultSuccess<Name, Success>
| ToolResultFailure<Name, Failure>;ToolResultPartEncoded interface
Encoded representation of tool result parts for serialization.
Signature
interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", ToolResultPartMetadata> {
readonly id: string;
readonly isFailure: boolean;
readonly name: string;
readonly preliminary?: boolean;
readonly providerExecuted?: boolean;
readonly result: unknown;
}ToolResultSuccess interface
Represents a successful tool call result.
Signature
interface ToolResultSuccess<Name extends string, Success> extends BaseToolResult<Name> {
readonly isFailure: false;
readonly result: Success;
}UrlSourcePart interface
Response part representing a URL source reference used in generating the response.
Signature
interface UrlSourcePart extends BasePart<"source", UrlSourcePartMetadata> {
readonly id: string;
readonly sourceType: "url";
readonly title: string;
readonly url: URL;
}UrlSourcePartEncoded interface
Encoded representation of URL source parts for serialization.
Signature
interface UrlSourcePartEncoded extends BasePartEncoded<"source", UrlSourcePartMetadata> {
readonly id: string;
readonly sourceType: "url";
readonly title: string;
readonly url: string;
}Represents usage information for a request to a large language model provider.
Details
If the model provider returns additional usage information than what is specified here, you can generally find that information under the provider metadata of the finish part of the response.
Signature
declare class Usage extends {
readonly inputTokens: {
readonly cacheRead?: number;
readonly cacheWrite?: number;
readonly total?: number;
readonly uncached?: number;
};
readonly outputTokens: {
readonly reasoning?: number;
readonly text?: number;
readonly total?: number;
};
} {
constructor(...args: [props: {
readonly inputTokens: {
readonly cacheRead?: number;
readonly cacheWrite?: number;
readonly total?: number;
readonly uncached?: number;
};
readonly outputTokens: {
readonly reasoning?: number;
readonly text?: number;
readonly total?: number;
};
}, options?: MakeOptions]);
}Schemas
Creates a Schema for all response parts based on a toolkit.
Details
Generates a schema that includes all possible response parts, with tool call and tool result parts dynamically created based on the provided toolkit.
Signature
declare const AllParts: <T extends WithHandler<any> | Any>(
toolkit: T,
) => Codec<
AllParts<T extends Any ? Tools<T> : WithHandlerTools<T>>,
AllPartsEncoded,
ResultDecodingServices<Tools<T>[keyof Tools<T>]>,
ResultEncodingServices<Tools<T>[keyof Tools<T>]>
>;DocumentSourcePart
Schema for validation and encoding of document source parts.
When to use
Use to validate or encode document source references returned as response content parts.
Details
Validates type: "source", sourceType: "document", required id, mediaType, and title, optional fileName, and the metadata fields inherited from response parts.
See
UrlSourcePartfor URL source referencesDocumentSourcePartEncodedfor the encoded document source representation
Signature
declare const DocumentSourcePart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly fileName: optionalKey<String>;
readonly id: String;
readonly mediaType: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly sourceType: tag<"document">;
readonly title: String;
readonly type: tag<"source">;
}>;Schema for validation and encoding of error parts.
Details
Validates and encodes error parts with type: "error" and an error payload kept as unknown.
Gotchas
The decoded error value is not guaranteed to be an Error; narrow it before reading Error-specific fields.
Signature
declare const ErrorPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly error: Unknown;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"error">;
}>;Schema for validation and encoding of file parts.
Details
Decoded data is a Uint8Array; encoded data is a base64 string through Schema.Uint8ArrayFromBase64.
Signature
declare const FilePart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly data: Uint8ArrayFromBase64;
readonly mediaType: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"file">;
}>;FinishPart
Schema for finish response parts.
Details
Validates type: "finish", reason through FinishReason, usage through Usage, and optional provider HTTP response details.
Signature
declare const FinishPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly reason: Literals<
["stop", "length", "content-filter", "tool-calls", "error", "pause", "other", "unknown"]
>;
readonly response: optional<
Struct<{
readonly headers: $Record<String, Union<readonly [String, Redacted<String>]>>;
readonly status: Int;
}>
>;
readonly type: tag<"finish">;
readonly usage: typeof Usage;
}>;HttpRequestDetails
Schema for HTTP request details associated with an AI response.
Details
Captures comprehensive information about the HTTP request made to the AI provider, enabling inspection of request metadata for debugging and observability purposes.
Signature
declare const HttpRequestDetails: Struct<{
readonly hash: optional<String>;
readonly headers: $Record<String, Union<readonly [String, Redacted<String>]>>;
readonly method: Literals<
readonly ["GET", "POST", "PATCH", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE"]
>;
readonly url: String;
readonly urlParams: $Array<Tuple<readonly [String, String]>>;
}>;HttpResponseDetails
Schema for HTTP response details associated with an AI response.
Details
Captures essential information about the HTTP response received from the AI provider, including status codes and headers for debugging and observability purposes.
Signature
declare const HttpResponseDetails: Struct<{
readonly headers: $Record<String, Union<readonly [String, Redacted<String>]>>;
readonly status: Int;
}>;Creates a Schema for non-streaming response parts based on a toolkit.
Signature
declare const Part: <T extends WithHandler<any> | Any>(
toolkit: T,
) => Codec<
Part<T extends Any ? Tools<T> : WithHandlerTools<T>>,
PartEncoded,
ResultDecodingServices<Tools<T>[keyof Tools<T>]>,
ResultEncodingServices<Tools<T>[keyof Tools<T>]>
>;ProviderMetadata
Schema for provider-specific metadata attached to response parts, represented as a record from provider-specific keys to JSON values or null.
Signature
declare const ProviderMetadata: Schema.$Record<
Schema.String,
Schema.NullOr<Schema.Codec<Schema.Json>>
>;ReasoningDeltaPart
Schema for validation and encoding of reasoning delta parts.
Signature
declare const ReasoningDeltaPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly delta: String;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"reasoning-delta">;
}>;ReasoningEndPart
Schema for validation and encoding of reasoning end parts.
Signature
declare const ReasoningEndPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"reasoning-end">;
}>;ReasoningPart
Schema for validation and encoding of reasoning parts.
Signature
declare const ReasoningPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly text: String;
readonly type: tag<"reasoning">;
}>;ReasoningStartPart
Schema for validation and encoding of reasoning start parts.
Signature
declare const ReasoningStartPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"reasoning-start">;
}>;ResponseMetadataPart
Schema for validation and encoding of response metadata parts.
Signature
declare const ResponseMetadataPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: optional<String>;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly modelId: optional<String>;
readonly request: optional<
Struct<{
readonly hash: optional<String>;
readonly headers: $Record<String, Union<readonly [String, Redacted<String>]>>;
readonly method: Literals<
readonly ["GET", "POST", "PATCH", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE"]
>;
readonly url: String;
readonly urlParams: $Array<Tuple<readonly [String, String]>>;
}>
>;
readonly timestamp: optional<DateTimeUtcFromString>;
readonly type: tag<"response-metadata">;
}>;StreamPart
Creates a Schema for streaming response parts based on a toolkit.
Signature
declare const StreamPart: <T extends WithHandler<any> | Any>(
toolkit: T,
) => Codec<
StreamPart<T extends Any ? Tools<T> : WithHandlerTools<T>>,
StreamPartEncoded,
ResultDecodingServices<Tools<T>[keyof Tools<T>]>,
ResultEncodingServices<Tools<T>[keyof Tools<T>]>
>;TextDeltaPart
Schema for validation and encoding of text delta parts.
Signature
declare const TextDeltaPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly delta: String;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"text-delta">;
}>;TextEndPart
Schema for validation and encoding of text end parts.
Signature
declare const TextEndPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"text-end">;
}>;Schema for validation and encoding of text parts.
Signature
declare const TextPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly text: String;
readonly type: tag<"text">;
}>;TextStartPart
Schema for validation and encoding of text start parts.
Signature
declare const TextStartPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"text-start">;
}>;ToolApprovalRequestPart
Schema for validation and encoding of tool approval request parts.
Signature
declare const ToolApprovalRequestPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly approvalId: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly toolCallId: String;
readonly type: tag<"tool-approval-request">;
}>;ToolCallPart
Creates a Schema for tool call parts with specific tool name and parameters.
Signature
declare const ToolCallPart: <Name extends string, Params extends Constraint>(
name: Name,
params: Params,
) => Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly name: Literal<Name>;
readonly params: Params;
readonly providerExecuted: withDecodingDefaultKey<Boolean>;
readonly type: Literal<"tool-call">;
}>;ToolParamsDeltaPart
Schema for validation and encoding of tool params delta parts.
Signature
declare const ToolParamsDeltaPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly delta: String;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"tool-params-delta">;
}>;ToolParamsEndPart
Schema for validation and encoding of tool params end parts.
Signature
declare const ToolParamsEndPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly type: tag<"tool-params-end">;
}>;ToolParamsStartPart
Schema for validation and encoding of tool params start parts.
Signature
declare const ToolParamsStartPart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly name: String;
readonly providerExecuted: withDecodingDefaultKey<Boolean>;
readonly type: tag<"tool-params-start">;
}>;ToolResultPart
Creates a Schema for tool result parts with specific tool name and result type.
Signature
declare const ToolResultPart: <
Name extends string,
Success extends Constraint,
Failure extends Constraint,
>(
name: Name,
success: Success,
failure: Failure,
) => decodeTo<
Struct<{
readonly "~effect/ai/Content/Part": Literal<"~effect/ai/Content/Part">;
readonly encodedResult: toEncoded<Union<readonly [Success, Failure]>>;
readonly id: String;
readonly isFailure: Boolean;
readonly metadata: $Record<String, NullOr<Codec<Json, Json, never, never>>>;
readonly name: Literal<Name>;
readonly preliminary: Boolean;
readonly providerExecuted: Boolean;
readonly result: Union<readonly [Success, Failure]>;
readonly type: Literal<"tool-result">;
}>,
Struct<{
readonly id: String;
readonly isFailure: Boolean;
readonly metadata: optional<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly name: Literal<Name>;
readonly preliminary: optional<Boolean>;
readonly providerExecuted: optional<Boolean>;
readonly result: toEncoded<Union<readonly [Success, Failure]>>;
readonly type: Literal<"tool-result">;
}>
>;UrlSourcePart
Schema for validation and encoding of url source parts.
Signature
declare const UrlSourcePart: Struct<{
readonly "~effect/ai/Content/Part": withDecodingDefaultKey<tag<"~effect/ai/Content/Part">>;
readonly id: String;
readonly metadata: withDecodingDefault<$Record<String, Codec<Json, Json, never, never>>>;
readonly sourceType: tag<"url">;
readonly title: String;
readonly type: tag<"source">;
readonly url: URLFromString;
}>;Utility Types
ConstructorParams type
A utility type for specifying the parameters required to construct a specific response part.
Signature
type ConstructorParams<Part extends AnyPart> = Omit<
Part,
typeof PartTypeId | "type" | "sourceType" | "metadata"
> & {
readonly metadata?: Part["metadata"];
};ToolCallParts type
Utility type that extracts tool call parts from a set of tools.
Signature
type ToolCallParts<Tools extends Record<string, Tool.Any>> = {
[Name in keyof Tools]: Name extends string
? ToolCallPart<Name, Tool.Parameters<Tools[Name]>>
: never;
}[keyof Tools];ToolResultParts type
Utility type that extracts tool result parts from a set of tools.
Signature
type ToolResultParts<Tools extends Record<string, Tool.Any>> = {
[Name in keyof Tools]: Name extends string
? ToolResultPart<Name, Tool.Success<Tools[Name]>, Tool.FailureResult<Tools[Name]>>
: never;
}[keyof Tools];
Represents provider-specific metadata that can be associated with a
DocumentSourcePartthrough module augmentation.