Open History to see the last commit
1---
2id: TextOptions
3title: TextOptions
4---
5
6Defined in: [packages/ai/src/types.ts:1305](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1305)
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:1444](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1444)
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:1333](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1333)
60
61***
62
63### approvals?
64
65```ts
66optional approvals?: ReadonlyMap<string, boolean>;
67```
68
69Defined in: [packages/ai/src/types.ts:1536](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1536)
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:1527](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1527)
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:1317](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1317)
103
104Runtime context provided by the caller and passed to middleware and
105server-side tool implementations.
106
107***
108
109### ~~conversationId?~~
110
111```ts
112optional conversationId?: string;
113```
114
115Defined in: [packages/ai/src/types.ts:1430](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1430)
116
117#### Deprecated
118
119Use `threadId` instead. `conversationId` is the legacy
120pre-AG-UI name for the same concept (a stable per-conversation
121identifier used to correlate client/server devtools events). When
122`conversationId` is omitted, the runtime falls back to `threadId`
123automatically, so most callers can simply pass `threadId` (or rely
124on `chatParamsFromRequest`, which surfaces it on `params`).
125
126Will be removed in a future major release.
127
128***
129
130### lazyToolsConfig?
131
132```ts
133optional lazyToolsConfig?: LazyToolsConfig;
134```
135
136Defined in: [packages/ai/src/types.ts:1371](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1371)
137
138Optional configuration for lazy-tool discovery (tools marked `lazy: true`).
139Tunes how much of each lazy tool's description appears in the discovery
140catalog. Optional — defaults to `{ includeDescription: 'none' }`.
141
142***
143
144### logger
145
146```ts
147logger: InternalLogger;
148```
149
150Defined in: [packages/ai/src/types.ts:1451](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1451)
151
152Internal logger threaded from the chat entry point. Adapter implementations
153must call `logger.request()` before SDK calls, `logger.provider()` for each
154chunk received, and `logger.errors()` in catch blocks.
155
156***
157
158### messages
159
160```ts
161messages: ModelMessage<
162 | string
163 | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
164 | null>[];
165```
166
167Defined in: [packages/ai/src/types.ts:1311](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1311)
168
169***
170
171### metadata?
172
173```ts
174optional metadata?: Record<string, any>;
175```
176
177Defined in: [packages/ai/src/types.ts:1382](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1382)
178
179Observability metadata attached to this call. Surfaced to middleware,
180devtools, and the event client; values may be arbitrarily structured
181(objects, arrays). Adapters never forward this field onto the provider
182wire request.
183
184To send provider-side request metadata, use the provider's
185`modelOptions` field instead, where the provider supports one (e.g.
186OpenAI's and OpenRouter's `metadata` are both Record<string, string>).
187
188***
189
190### midConversationChanges?
191
192```ts
193optional midConversationChanges?: MidConversationChanges;
194```
195
196Defined in: [packages/ai/src/types.ts:1492](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1492)
197
198The tools and system prompts that changed between model calls. The
199engine sets it only when `adapter.midConversationChannels` has a channel
200that is on. `tools` and `systemPrompts` stay the full current lists, so
201an adapter that ignores this field sends the same request as before.
202Adapters resolve it with `splitMidConversationChanges`.
203
204***
205
206### model
207
208```ts
209model: string;
210```
211
212Defined in: [packages/ai/src/types.ts:1310](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1310)
213
214***
215
216### modelOptions?
217
218```ts
219optional modelOptions?: TProviderOptionsForModel;
220```
221
222Defined in: [packages/ai/src/types.ts:1383](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1383)
223
224***
225
226### outputSchema?
227
228```ts
229optional outputSchema?: SchemaInput;
230```
231
232Defined in: [packages/ai/src/types.ts:1419](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1419)
233
234Schema for structured output.
235
236**Two distinct use sites:**
237
2381. **User-facing (activity layer):** accepts any
239 [SchemaInput](../type-aliases/SchemaInput.md) — Zod, ArkType, Valibot, or a raw JSON Schema.
240 The activity layer converts to JSON Schema before handing off.
241
2422. **Adapter-facing (`chatStream` call):** the engine populates this with
243 a pre-converted JSON Schema **only** when the adapter declared
244 `supportsCombinedToolsAndSchema(modelOptions) === true`. The adapter
245 should then wire the schema into the upstream request (e.g.
246 `response_format: { type: 'json_schema', ... }`, `text.format`,
247 `output_format`, `--json-schema`) alongside any `tools`.
248
249 How the engine then takes the object depends on
250 `combinedStructuredOutputSource()`:
251 - `'text'` (default): the final-turn assistant text is the JSON.
252 - `'event'`: the adapter emits `structured-output.complete` during
253 `chatStream`. Accumulated prose is not parsed.
254
255 Adapters that did NOT declare the capability never see this field
256 populated — the engine instead invokes `structuredOutput` /
257 `structuredOutputStream` after the agent loop.
258
259***
260
261### parentRunId?
262
263```ts
264optional parentRunId?: string;
265```
266
267Defined in: [packages/ai/src/types.ts:1473](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1473)
268
269Parent run ID for AG-UI protocol nested run correlation.
270Surfaced for observability/middleware; not consumed by the LLM call.
271
272***
273
274### parentSubagentRunId?
275
276```ts
277optional parentSubagentRunId?: string;
278```
279
280Defined in: [packages/ai/src/types.ts:1508](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1508)
281
282The subagentRunId of the child that started this one, for a nested child.
283Middleware reads it as `ctx.parentSubagentRunId`.
284
285***
286
287### promptCache?
288
289```ts
290optional promptCache?: ResolvedPromptCache;
291```
292
293Defined in: [packages/ai/src/types.ts:1462](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1462)
294
295Automatic prompt caching for this request. `chat()` sets it. When it is
296absent, the adapter adds no automatic cache fields.
297
298***
299
300### reasoning?
301
302```ts
303optional reasoning?: ReasoningRequest;
304```
305
306Defined in: [packages/ai/src/types.ts:1390](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1390)
307
308How hard the model thinks, normalized by `chat()`. `undefined`: the user
309did not ask, so the adapter sends nothing and the provider default applies.
310The adapter clamps the level to the model's levels and writes its own
311wire field.
312
313***
314
315### repairToolInput?
316
317```ts
318optional repairToolInput?: false | ((context) => unknown);
319```
320
321Defined in: [packages/ai/src/types.ts:1346](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1346)
322
323How a tool input that fails the final check is repaired. By default,
324common model mistakes such as `"5"` for a number are repaired against the
325schema. `false` turns the repair off. A function replaces the built-in
326repair: it returns the input to check again, or `undefined` to send the
327validation error to the model.
328
329***
330
331### request?
332
333```ts
334optional request?: Request | RequestInit;
335```
336
337Defined in: [packages/ai/src/types.ts:1391](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1391)
338
339***
340
341### resume?
342
343```ts
344optional resume?: RunAgentResumeItem[];
345```
346
347Defined in: [packages/ai/src/types.ts:1517](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1517)
348
349AG-UI interrupt resume responses supplied by the client on a follow-up run.
350A first-party generic item carries the original request in `metadata`.
351
352***
353
354### retry?
355
356```ts
357optional retry?: object;
358```
359
360Defined in: [packages/ai/src/types.ts:1356](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1356)
361
362Retry a model call when the provider error has a wait time (usually a
363429). `chat()` waits for the `retryAfterMs` time of the `RUN_ERROR`, then
364calls the model again. It retries only when the wait time is at most
365`maxWaitMs` and the call has streamed no output yet. The structured-output
366call is not retried. Off by default.
367
368#### maxRetries
369
370```ts
371maxRetries: number;
372```
373
374Extra model calls after the first, for each model call of the run. `0`
375means no retry. The provider SDK does its own retries first, from the
376`maxRetries` of the adapter config.
377
378#### maxWaitMs?
379
380```ts
381optional maxWaitMs?: number;
382```
383
384Longest wait time to accept, in milliseconds. Default 60 000.
385
386***
387
388### runId?
389
390```ts
391optional runId?: string;
392```
393
394Defined in: [packages/ai/src/types.ts:1468](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1468)
395
396Run ID for AG-UI protocol run correlation.
397When provided, this will be used in RunStartedEvent and RunFinishedEvent.
398If not provided, a unique ID will be generated.
399
400***
401
402### state?
403
404```ts
405optional state?: unknown;
406```
407
408Defined in: [packages/ai/src/types.ts:1511](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1511)
409
410Application state mirrored in a STATE_SNAPSHOT before an interrupt terminal.
411
412***
413
414### subagentName?
415
416```ts
417optional subagentName?: string;
418```
419
420Defined in: [packages/ai/src/types.ts:1503](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1503)
421
422The agent name when this chat runs as a subagent. Middleware reads it as
423`ctx.subagentName`.
424
425***
426
427### subagentRunId?
428
429```ts
430optional subagentRunId?: string;
431```
432
433Defined in: [packages/ai/src/types.ts:1498](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1498)
434
435AG-UI subagent run id when this chat runs as a child of another run.
436A child `chat()` passes `ctx.subagentRunId`. Middleware reads it as
437`ctx.subagentRunId`. Absent on a top-level run.
438
439***
440
441### systemPrompts?
442
443```ts
444optional systemPrompts?: SystemPrompt[];
445```
446
447Defined in: [packages/ai/src/types.ts:1332](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1332)
448
449System prompts to include with the request.
450
451Accepts plain strings (the common case) or `{ content, metadata }`
452objects that let providers attach typed metadata (e.g. Anthropic
453`cache_control` for prompt caching) per prompt. At the chat call site
454the adapter narrows `metadata`'s type via `~types['systemPromptMetadata']`
455— providers that don't declare one default to `never`, which makes the
456field carry no meaningful value (TypeScript will only accept
457`undefined` there). Provider-foreign metadata that reaches an adapter
458via JS / `as any` is silently dropped, never written to the wire.
459
460#### See
461
462SystemPrompt
463
464***
465
466### threadId?
467
468```ts
469optional threadId?: string;
470```
471
472Defined in: [packages/ai/src/types.ts:1457](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1457)
473
474Thread ID for AG-UI protocol run correlation.
475When provided, this will be used in RunStartedEvent and RunFinishedEvent.
476
477***
478
479### toolChoice?
480
481```ts
482optional toolChoice?: ToolChoice<string>;
483```
484
485Defined in: [packages/ai/src/types.ts:1478](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1478)
486
487How the model uses the tools of this request. `chat()` sets it only when
488the request has tools. A provider value in `modelOptions` wins over it.
489
490***
491
492### toolExecution?
493
494```ts
495optional toolExecution?: "parallel" | "sequential";
496```
497
498Defined in: [packages/ai/src/types.ts:1338](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1338)
499
500How the server tools of one model turn run. `'parallel'` (the default)
501starts them together, and `'sequential'` runs them one at a time.
502
503***
504
505### tools?
506
507```ts
508optional tools?: AnyTool[];
509```
510
511Defined in: [packages/ai/src/types.ts:1312](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1312)
512
513***
514
515### wrapFetch?
516
517```ts
518optional wrapFetch?: FetchWrapper;
519```
520
521Defined in: [packages/ai/src/types.ts:1484](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1484)
522
523Wraps the fetch of this request. The engine composes the `chat()` option
524and the middleware wrappers into one function. An adapter that supports
525it calls `wrapFetch(baseFetch)` and sends the request with the result.