Class References
Function References
- text
- textOptions
- combineStrategies
- convertMessagesToModelMessages
- convertZodToJsonSchema
- createReplayStream
- embedding
- generateMessageId
- maxIterations
- messages
- modelMessageToUIMessage
- modelMessagesToUIMessages
- normalizeToUIMessage
- parsePartialJSON
- summarize
- toServerSentEventsStream
- toServerSentEventsResponse
- toolDefinition
- uiMessageToModelMessages
- realtimeToken
- untilFinishReason
Interface References
- AIAdapter
- AIAdapterConfig
- AgentLoopState
- AudioPart
- AudioVisualization
- BaseStreamChunk
- TextCompletionChunk
- TextOptions
- ChunkRecording
- ChunkStrategy
- ClientTool
- ContentPartSource
- ContentStreamChunk
- DefaultMessageMetadataByModality
- DocumentPart
- DoneStreamChunk
- EmbeddingOptions
- EmbeddingResult
- ErrorStreamChunk
- ImagePart
- InternalToolCallState
- JSONParser
- ModelMessage
- ProcessorResult
- ProcessorState
- RealtimeAdapter
- RealtimeClientOptions
- RealtimeConnection
- RealtimeMessage
- RealtimeSessionConfig
- RealtimeToken
- RealtimeTokenAdapter
- RealtimeTokenOptions
- ResponseFormat
- ServerTool
- StreamProcessorEvents
- StreamProcessorHandlers
- StreamProcessorOptions
- SummarizationOptions
- SummarizationResult
- TextPart
- ThinkingPart
- ThinkingStreamChunk
- Tool
- ToolCall
- ToolCallPart
- ToolCallStreamChunk
- ToolConfig
- ToolDefinition
- ToolDefinitionConfig
- ToolDefinitionInstance
- ToolInputAvailableStreamChunk
- ToolResultPart
- ToolResultStreamChunk
- UIMessage
- VideoPart
Type Alias References
- AgentLoopStrategy
- AnyClientTool
- TextStreamOptionsForModel
- TextStreamOptionsUnion
- ConstrainedContent
- ConstrainedModelMessage
- ContentPart
- ContentPartForModalities
- ExtractModalitiesForModel
- ExtractModelsFromAdapter
- InferToolInput
- InferToolName
- InferToolOutput
- MessagePart
- RealtimeEvent
- RealtimeMessagePart
- RealtimeMode
- RealtimeStatus
- ModalitiesArrayToUnion
- Modality
- StreamChunk
- ToolCallState
- ToolResultState
Variable References
TextOptions
Defined in: packages/ai/src/types.ts:1306
Options passed into the SDK and further piped to the AI provider.
Type Parameters#
TProviderOptionsSuperset#
TProviderOptionsSuperset extends Record<string, any> = Record<string, any>
TProviderOptionsForModel#
TProviderOptionsForModel = TProviderOptionsSuperset
TContext#
TContext = unknown
Properties#
abortController?#
optional abortController?: AbortController;Defined in: packages/ai/src/types.ts:1434
AbortController for request cancellation.
Allows you to cancel an in-progress request using an AbortController. Useful for implementing timeouts or user-initiated cancellations.
Example#
const abortController = new AbortController();
setTimeout(() => abortController.abort(), 5000); // Cancel after 5 seconds
await chat({ ..., abortController });See#
https://developer.mozilla.org/en-US/docs/Web/API/AbortController
agentLoopStrategy?#
optional agentLoopStrategy?: AgentLoopStrategy;Defined in: packages/ai/src/types.ts:1334
approvals?#
optional approvals?: ReadonlyMap<string, boolean>;Defined in: packages/ai/src/types.ts:1526
Client approval decisions for this run, keyed by approval id. The engine populates this from approvals carried on the incoming messages. Harness adapters consult it to resolve ask-policy permission requests (the agent pauses on a risky action; the client re-runs with a decision recorded here). Undefined for direct adapter usage outside the chat engine.
capabilities?#
optional capabilities?: CapabilityContext;Defined in: packages/ai/src/types.ts:1517
Middleware capability context for this run. The engine populates it with the live middleware context so harness adapters that declare requires: [SomeCapability] can read provided capabilities from inside chatStream — e.g. getSandbox(options.capabilities). Capabilities are provisioned by middleware setup before the adapter runs. Undefined for direct adapter usage outside the chat engine.
context?#
optional context?: TContext;Defined in: packages/ai/src/types.ts:1318
Runtime context provided by the caller and passed to middleware and server-side tool implementations.
lazyToolsConfig?#
optional lazyToolsConfig?: LazyToolsConfig;Defined in: packages/ai/src/types.ts:1372
Optional configuration for lazy-tool discovery (tools marked lazy: true). Tunes how much of each lazy tool's description appears in the discovery catalog. Optional — defaults to { includeDescription: 'none' }.
logger#
logger: InternalLogger;Defined in: packages/ai/src/types.ts:1441
Internal logger threaded from the chat entry point. Adapter implementations must call logger.request() before SDK calls, logger.provider() for each chunk received, and logger.errors() in catch blocks.
messages#
messages: ModelMessage<
| string
| ContentPart<unknown, unknown, unknown, unknown, unknown>[]
| null>[];Defined in: packages/ai/src/types.ts:1312
metadata?#
optional metadata?: Record<string, any>;Defined in: packages/ai/src/types.ts:1383
Observability metadata attached to this call. Surfaced to middleware, devtools, and the event client; values may be arbitrarily structured (objects, arrays). Adapters never forward this field onto the provider wire request.
To send provider-side request metadata, use the provider's modelOptions field instead, where the provider supports one (e.g. OpenAI's and OpenRouter's metadata are both Record<string, string>).
midConversationChanges?#
optional midConversationChanges?: MidConversationChanges;Defined in: packages/ai/src/types.ts:1482
The tools and system prompts that changed between model calls. The engine sets it only when adapter.midConversationChannels has a channel that is on. tools and systemPrompts stay the full current lists, so an adapter that ignores this field sends the same request as before. Adapters resolve it with splitMidConversationChanges.
model#
model: string;Defined in: packages/ai/src/types.ts:1311
modelOptions?#
optional modelOptions?: TProviderOptionsForModel;Defined in: packages/ai/src/types.ts:1384
outputSchema?#
optional outputSchema?: SchemaInput;Defined in: packages/ai/src/types.ts:1420
Schema for structured output.
Two distinct use sites:
User-facing (activity layer): accepts any SchemaInput — Zod, ArkType, Valibot, or a raw JSON Schema. The activity layer converts to JSON Schema before handing off.
Adapter-facing (chatStream call): the engine populates this with a pre-converted JSON Schema only when the adapter declared supportsCombinedToolsAndSchema(modelOptions) === true. The adapter should then wire the schema into the upstream request (e.g. response_format: { type: 'json_schema', ... }, text.format, output_format, --json-schema) alongside any tools.
How the engine then takes the object depends on combinedStructuredOutputSource():
- 'text' (default): the final-turn assistant text is the JSON.
- 'event': the adapter emits structured-output.complete during chatStream. Accumulated prose is not parsed.
Adapters that did NOT declare the capability never see this field populated — the engine instead invokes structuredOutput / structuredOutputStream after the agent loop.
parentRunId?#
optional parentRunId?: string;Defined in: packages/ai/src/types.ts:1463
Parent run ID for AG-UI protocol nested run correlation. Surfaced for observability/middleware; not consumed by the LLM call.
parentSubagentRunId?#
optional parentSubagentRunId?: string;Defined in: packages/ai/src/types.ts:1498
The subagentRunId of the child that started this one, for a nested child. Middleware reads it as ctx.parentSubagentRunId.
promptCache?#
optional promptCache?: ResolvedPromptCache;Defined in: packages/ai/src/types.ts:1452
Automatic prompt caching for this request. chat() sets it. When it is absent, the adapter adds no automatic cache fields.
reasoning?#
optional reasoning?: ReasoningRequest;Defined in: packages/ai/src/types.ts:1391
How hard the model thinks, normalized by chat(). undefined: the user did not ask, so the adapter sends nothing and the provider default applies. The adapter clamps the level to the model's levels and writes its own wire field.
repairToolInput?#
optional repairToolInput?: false | ((context) => unknown);Defined in: packages/ai/src/types.ts:1347
How a tool input that fails the final check is repaired. By default, common model mistakes such as "5" for a number are repaired against the schema. false turns the repair off. A function replaces the built-in repair: it returns the input to check again, or undefined to send the validation error to the model.
request?#
optional request?: Request | RequestInit;Defined in: packages/ai/src/types.ts:1392
resume?#
optional resume?: RunAgentResumeItem[];Defined in: packages/ai/src/types.ts:1507
AG-UI interrupt resume responses supplied by the client on a follow-up run. A first-party generic item carries the original request in metadata.
retry?#
optional retry?: object;Defined in: packages/ai/src/types.ts:1357
Retry a model call when the provider error has a wait time (usually a 429). chat() waits for the retryAfterMs time of the RUN_ERROR, then calls the model again. It retries only when the wait time is at most maxWaitMs and the call has streamed no output yet. The structured-output call is not retried. Off by default.
maxRetries#
maxRetries: number;Extra model calls after the first, for each model call of the run. 0 means no retry. The provider SDK does its own retries first, from the maxRetries of the adapter config.
maxWaitMs?#
optional maxWaitMs?: number;Longest wait time to accept, in milliseconds. Default 60 000.
runId?#
optional runId?: string;Defined in: packages/ai/src/types.ts:1458
Run ID for AG-UI protocol run correlation. When provided, this will be used in RunStartedEvent and RunFinishedEvent. If not provided, a unique ID will be generated.
state?#
optional state?: unknown;Defined in: packages/ai/src/types.ts:1501
Application state mirrored in a STATE_SNAPSHOT before an interrupt terminal.
subagentName?#
optional subagentName?: string;Defined in: packages/ai/src/types.ts:1493
The agent name when this chat runs as a subagent. Middleware reads it as ctx.subagentName.
subagentRunId?#
optional subagentRunId?: string;Defined in: packages/ai/src/types.ts:1488
AG-UI subagent run id when this chat runs as a child of another run. A child chat() passes ctx.subagentRunId. Middleware reads it as ctx.subagentRunId. Absent on a top-level run.
systemPrompts?#
optional systemPrompts?: SystemPrompt[];Defined in: packages/ai/src/types.ts:1333
System prompts to include with the request.
Accepts plain strings (the common case) or { content, metadata } objects that let providers attach typed metadata (e.g. Anthropic cache_control for prompt caching) per prompt. At the chat call site the adapter narrows metadata's type via ~types['systemPromptMetadata'] — providers that don't declare one default to never, which makes the field carry no meaningful value (TypeScript will only accept undefined there). Provider-foreign metadata that reaches an adapter via JS / as any is silently dropped, never written to the wire.
See#
SystemPrompt
threadId#
threadId: string;Defined in: packages/ai/src/types.ts:1447
Thread ID for AG-UI protocol run correlation. Required. It is used in RunStartedEvent and RunFinishedEvent.
toolChoice?#
optional toolChoice?: ToolChoice<string>;Defined in: packages/ai/src/types.ts:1468
How the model uses the tools of this request. chat() sets it only when the request has tools. A provider value in modelOptions wins over it.
toolExecution?#
optional toolExecution?: "parallel" | "sequential";Defined in: packages/ai/src/types.ts:1339
How the server tools of one model turn run. 'parallel' (the default) starts them together, and 'sequential' runs them one at a time.
tools?#
optional tools?: AnyTool[];Defined in: packages/ai/src/types.ts:1313
wrapFetch?#
optional wrapFetch?: FetchWrapper;Defined in: packages/ai/src/types.ts:1474
Wraps the fetch of this request. The engine composes the chat() option and the middleware wrappers into one function. An adapter that supports it calls wrapFetch(baseFetch) and sends the request with the result.