Open History to see the last commit
1---
2id: TextOptions
3title: TextOptions
4---
5
6Defined in: packages/ai/src/types.ts:1306
7
8Options passed into the SDK and further piped to the AI provider.
9
10## Type Parameters
11
12### TProviderOptionsSuperset
13
14`TProviderOptionsSuperset` *extends* `Record`\<`string`, `any`\> = `Record`\<`string`, `any`\>
15
16### TProviderOptionsForModel
17
18`TProviderOptionsForModel` = `TProviderOptionsSuperset`
19
20### TContext
21
22`TContext` = `unknown`
23
24## Properties
25
26### abortController?
27
28```ts
29optional abortController?: AbortController;
30```
31
32Defined in: packages/ai/src/types.ts:1434
33
34AbortController for request cancellation.
35
36Allows you to cancel an in-progress request using an AbortController.
37Useful for implementing timeouts or user-initiated cancellations.
38
39#### Example
40
41```ts
42const abortController = new AbortController();
43setTimeout(() => abortController.abort(), 5000); // Cancel after 5 seconds
44await chat({ ..., abortController });
45```
46
47#### See
48
49https://developer.mozilla.org/en-US/docs/Web/API/AbortController
50
51***
52
53### agentLoopStrategy?
54
55```ts
56optional agentLoopStrategy?: AgentLoopStrategy;
57```
58
59Defined in: packages/ai/src/types.ts:1334
60
61***
62
63### approvals?
64
65```ts
66optional approvals?: ReadonlyMap<string, boolean>;
67```
68
69Defined in: packages/ai/src/types.ts:1526
70
71Client approval decisions for this run, keyed by approval id. The engine
72populates this from approvals carried on the incoming messages. Harness
73adapters consult it to resolve `ask`-policy permission requests (the agent
74pauses on a risky action; the client re-runs with a decision recorded
75here). Undefined for direct adapter usage outside the chat engine.
76
77***
78
79### capabilities?
80
81```ts
82optional capabilities?: CapabilityContext;
83```
84
85Defined in: packages/ai/src/types.ts:1517
86
87Middleware capability context for this run. The engine populates it with
88the live middleware context so harness adapters that declare
89`requires: [SomeCapability]` can read provided capabilities from inside
90`chatStream` — e.g. `getSandbox(options.capabilities)`. Capabilities are
91provisioned by middleware `setup` before the adapter runs. Undefined for
92direct adapter usage outside the chat engine.
93
94***
95
96### context?
97
98```ts
99optional context?: TContext;
100```
101
102Defined in: packages/ai/src/types.ts:1318
103
104Runtime context provided by the caller and passed to middleware and
105server-side tool implementations.
106
107***
108
109### lazyToolsConfig?
110
111```ts
112optional lazyToolsConfig?: LazyToolsConfig;
113```
114
115Defined in: packages/ai/src/types.ts:1372
116
117Optional configuration for lazy-tool discovery (tools marked `lazy: true`).
118Tunes how much of each lazy tool's description appears in the discovery
119catalog. Optional — defaults to `{ includeDescription: 'none' }`.
120
121***
122
123### logger
124
125```ts
126logger: InternalLogger;
127```
128
129Defined in: packages/ai/src/types.ts:1441
130
131Internal logger threaded from the chat entry point. Adapter implementations
132must call `logger.request()` before SDK calls, `logger.provider()` for each
133chunk received, and `logger.errors()` in catch blocks.
134
135***
136
137### messages
138
139```ts
140messages: ModelMessage<
141 | string
142 | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
143 | null>[];
144```
145
146Defined in: packages/ai/src/types.ts:1312
147
148***
149
150### metadata?
151
152```ts
153optional metadata?: Record<string, any>;
154```
155
156Defined in: packages/ai/src/types.ts:1383
157
158Observability metadata attached to this call. Surfaced to middleware,
159devtools, and the event client; values may be arbitrarily structured
160(objects, arrays). Adapters never forward this field onto the provider
161wire request.
162
163To send provider-side request metadata, use the provider's
164`modelOptions` field instead, where the provider supports one (e.g.
165OpenAI's and OpenRouter's `metadata` are both Record<string, string>).
166
167***
168
169### midConversationChanges?
170
171```ts
172optional midConversationChanges?: MidConversationChanges;
173```
174
175Defined in: packages/ai/src/types.ts:1482
176
177The tools and system prompts that changed between model calls. The
178engine sets it only when `adapter.midConversationChannels` has a channel
179that is on. `tools` and `systemPrompts` stay the full current lists, so
180an adapter that ignores this field sends the same request as before.
181Adapters resolve it with `splitMidConversationChanges`.
182
183***
184
185### model
186
187```ts
188model: string;
189```
190
191Defined in: packages/ai/src/types.ts:1311
192
193***
194
195### modelOptions?
196
197```ts
198optional modelOptions?: TProviderOptionsForModel;
199```
200
201Defined in: packages/ai/src/types.ts:1384
202
203***
204
205### outputSchema?
206
207```ts
208optional outputSchema?: SchemaInput;
209```
210
211Defined in: packages/ai/src/types.ts:1420
212
213Schema for structured output.
214
215**Two distinct use sites:**
216
2171. **User-facing (activity layer):** accepts any
218 [SchemaInput](../type-aliases/SchemaInput.md) — Zod, ArkType, Valibot, or a raw JSON Schema.
219 The activity layer converts to JSON Schema before handing off.
220
2212. **Adapter-facing (`chatStream` call):** the engine populates this with
222 a pre-converted JSON Schema **only** when the adapter declared
223 `supportsCombinedToolsAndSchema(modelOptions) === true`. The adapter
224 should then wire the schema into the upstream request (e.g.
225 `response_format: { type: 'json_schema', ... }`, `text.format`,
226 `output_format`, `--json-schema`) alongside any `tools`.
227
228 How the engine then takes the object depends on
229 `combinedStructuredOutputSource()`:
230 - `'text'` (default): the final-turn assistant text is the JSON.
231 - `'event'`: the adapter emits `structured-output.complete` during
232 `chatStream`. Accumulated prose is not parsed.
233
234 Adapters that did NOT declare the capability never see this field
235 populated — the engine instead invokes `structuredOutput` /
236 `structuredOutputStream` after the agent loop.
237
238***
239
240### parentRunId?
241
242```ts
243optional parentRunId?: string;
244```
245
246Defined in: packages/ai/src/types.ts:1463
247
248Parent run ID for AG-UI protocol nested run correlation.
249Surfaced for observability/middleware; not consumed by the LLM call.
250
251***
252
253### parentSubagentRunId?
254
255```ts
256optional parentSubagentRunId?: string;
257```
258
259Defined in: packages/ai/src/types.ts:1498
260
261The subagentRunId of the child that started this one, for a nested child.
262Middleware reads it as `ctx.parentSubagentRunId`.
263
264***
265
266### promptCache?
267
268```ts
269optional promptCache?: ResolvedPromptCache;
270```
271
272Defined in: packages/ai/src/types.ts:1452
273
274Automatic prompt caching for this request. `chat()` sets it. When it is
275absent, the adapter adds no automatic cache fields.
276
277***
278
279### reasoning?
280
281```ts
282optional reasoning?: ReasoningRequest;
283```
284
285Defined in: packages/ai/src/types.ts:1391
286
287How hard the model thinks, normalized by `chat()`. `undefined`: the user
288did not ask, so the adapter sends nothing and the provider default applies.
289The adapter clamps the level to the model's levels and writes its own
290wire field.
291
292***
293
294### repairToolInput?
295
296```ts
297optional repairToolInput?: false | ((context) => unknown);
298```
299
300Defined in: packages/ai/src/types.ts:1347
301
302How a tool input that fails the final check is repaired. By default,
303common model mistakes such as `"5"` for a number are repaired against the
304schema. `false` turns the repair off. A function replaces the built-in
305repair: it returns the input to check again, or `undefined` to send the
306validation error to the model.
307
308***
309
310### request?
311
312```ts
313optional request?: Request | RequestInit;
314```
315
316Defined in: packages/ai/src/types.ts:1392
317
318***
319
320### resume?
321
322```ts
323optional resume?: RunAgentResumeItem[];
324```
325
326Defined in: packages/ai/src/types.ts:1507
327
328AG-UI interrupt resume responses supplied by the client on a follow-up run.
329A first-party generic item carries the original request in `metadata`.
330
331***
332
333### retry?
334
335```ts
336optional retry?: object;
337```
338
339Defined in: packages/ai/src/types.ts:1357
340
341Retry a model call when the provider error has a wait time (usually a
342429). `chat()` waits for the `retryAfterMs` time of the `RUN_ERROR`, then
343calls the model again. It retries only when the wait time is at most
344`maxWaitMs` and the call has streamed no output yet. The structured-output
345call is not retried. Off by default.
346
347#### maxRetries
348
349```ts
350maxRetries: number;
351```
352
353Extra model calls after the first, for each model call of the run. `0`
354means no retry. The provider SDK does its own retries first, from the
355`maxRetries` of the adapter config.
356
357#### maxWaitMs?
358
359```ts
360optional maxWaitMs?: number;
361```
362
363Longest wait time to accept, in milliseconds. Default 60 000.
364
365***
366
367### runId?
368
369```ts
370optional runId?: string;
371```
372
373Defined in: packages/ai/src/types.ts:1458
374
375Run ID for AG-UI protocol run correlation.
376When provided, this will be used in RunStartedEvent and RunFinishedEvent.
377If not provided, a unique ID will be generated.
378
379***
380
381### state?
382
383```ts
384optional state?: unknown;
385```
386
387Defined in: packages/ai/src/types.ts:1501
388
389Application state mirrored in a STATE_SNAPSHOT before an interrupt terminal.
390
391***
392
393### subagentName?
394
395```ts
396optional subagentName?: string;
397```
398
399Defined in: packages/ai/src/types.ts:1493
400
401The agent name when this chat runs as a subagent. Middleware reads it as
402`ctx.subagentName`.
403
404***
405
406### subagentRunId?
407
408```ts
409optional subagentRunId?: string;
410```
411
412Defined in: packages/ai/src/types.ts:1488
413
414AG-UI subagent run id when this chat runs as a child of another run.
415A child `chat()` passes `ctx.subagentRunId`. Middleware reads it as
416`ctx.subagentRunId`. Absent on a top-level run.
417
418***
419
420### systemPrompts?
421
422```ts
423optional systemPrompts?: SystemPrompt[];
424```
425
426Defined in: packages/ai/src/types.ts:1333
427
428System prompts to include with the request.
429
430Accepts plain strings (the common case) or `{ content, metadata }`
431objects that let providers attach typed metadata (e.g. Anthropic
432`cache_control` for prompt caching) per prompt. At the chat call site
433the adapter narrows `metadata`'s type via `~types['systemPromptMetadata']`
434— providers that don't declare one default to `never`, which makes the
435field carry no meaningful value (TypeScript will only accept
436`undefined` there). Provider-foreign metadata that reaches an adapter
437via JS / `as any` is silently dropped, never written to the wire.
438
439#### See
440
441SystemPrompt
442
443***
444
445### threadId
446
447```ts
448threadId: string;
449```
450
451Defined in: packages/ai/src/types.ts:1447
452
453Thread ID for AG-UI protocol run correlation. Required. It is used in
454RunStartedEvent and RunFinishedEvent.
455
456***
457
458### toolChoice?
459
460```ts
461optional toolChoice?: ToolChoice<string>;
462```
463
464Defined in: packages/ai/src/types.ts:1468
465
466How the model uses the tools of this request. `chat()` sets it only when
467the request has tools. A provider value in `modelOptions` wins over it.
468
469***
470
471### toolExecution?
472
473```ts
474optional toolExecution?: "parallel" | "sequential";
475```
476
477Defined in: packages/ai/src/types.ts:1339
478
479How the server tools of one model turn run. `'parallel'` (the default)
480starts them together, and `'sequential'` runs them one at a time.
481
482***
483
484### tools?
485
486```ts
487optional tools?: AnyTool[];
488```
489
490Defined in: packages/ai/src/types.ts:1313
491
492***
493
494### wrapFetch?
495
496```ts
497optional wrapFetch?: FetchWrapper;
498```
499
500Defined in: packages/ai/src/types.ts:1474
501
502Wraps the fetch of this request. The engine composes the `chat()` option
503and the middleware wrappers into one function. An adapter that supports
504it calls `wrapFetch(baseFetch)` and sends the request with the result.