Open History to see the last commit
1---
2id: TextAdapter
3title: TextAdapter
4---
5
6# Interface: TextAdapter\<TModel, TProviderOptions, TInputModalities, TMessageMetadataByModality, TToolCapabilities, TToolCallMetadata, TSystemPromptMetadata\>
7
8Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:63](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L63)
9
10Text adapter interface with pre-resolved generics.
11
12An adapter is created by a provider function: `provider('model')` → `adapter`
13All type resolution happens at the provider call site, not in this interface.
14
15Generic parameters:
16- TModel: The specific model name (e.g., 'gpt-4o')
17- TProviderOptions: Provider-specific options for this model (already resolved)
18- TInputModalities: Supported input modalities for this model (already resolved)
19- TMessageMetadata: Metadata types for content parts (already resolved)
20- TToolCapabilities: Tuple of tool-kind strings supported by this model, resolved from `supports.tools`
21- TToolCallMetadata: Metadata type that round-trips with tool calls (e.g. Gemini's `thoughtSignature`)
22- TSystemPromptMetadata: Provider-typed metadata accepted on each
23 `systemPrompts[i]` entry (e.g. Anthropic `cache_control`). Defaults to
24 `never` — adapters without per-prompt metadata reject the `metadata`
25 field at the call site.
26
27## Type Parameters
28
29### TModel
30
31`TModel` *extends* `string`
32
33### TProviderOptions
34
35`TProviderOptions` *extends* `Record`\<`string`, `any`\>
36
37### TInputModalities
38
39`TInputModalities` *extends* `ReadonlyArray`\<[`Modality`](../type-aliases/Modality.md)\>
40
41### TMessageMetadataByModality
42
43`TMessageMetadataByModality` *extends* [`DefaultMessageMetadataByModality`](DefaultMessageMetadataByModality.md)
44
45### TToolCapabilities
46
47`TToolCapabilities` *extends* `ReadonlyArray`\<`string`\> = `ReadonlyArray`\<`string`\>
48
49### TToolCallMetadata
50
51`TToolCallMetadata` = `unknown`
52
53### TSystemPromptMetadata
54
55`TSystemPromptMetadata` = `never`
56
57## Properties
58
59### ~types
60
61```ts
62~types: object;
63```
64
65Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:82](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L82)
66
67**`Internal`**
68
69Type-only properties for inference. Not assigned at runtime.
70
71#### inputModalities
72
73```ts
74inputModalities: TInputModalities;
75```
76
77#### messageMetadataByModality
78
79```ts
80messageMetadataByModality: TMessageMetadataByModality;
81```
82
83#### providerOptions
84
85```ts
86providerOptions: TProviderOptions;
87```
88
89#### systemPromptMetadata
90
91```ts
92systemPromptMetadata: TSystemPromptMetadata;
93```
94
95#### toolCallMetadata
96
97```ts
98toolCallMetadata: TToolCallMetadata;
99```
100
101#### toolCapabilities
102
103```ts
104toolCapabilities: TToolCapabilities;
105```
106
107***
108
109### chatStream()
110
111```ts
112chatStream: (options) => AsyncIterable<AGUIEvent>;
113```
114
115Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:94](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L94)
116
117Stream text completions from the model
118
119#### Parameters
120
121##### options
122
123[`TextOptions`](TextOptions.md)\<`TProviderOptions`\>
124
125#### Returns
126
127`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>
128
129***
130
131### kind
132
133```ts
134readonly kind: "text";
135```
136
137Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:73](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L73)
138
139Discriminator for adapter kind
140
141***
142
143### model
144
145```ts
146readonly model: TModel;
147```
148
149Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:77](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L77)
150
151The model this adapter is configured for
152
153***
154
155### name
156
157```ts
158readonly name: string;
159```
160
161Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:75](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L75)
162
163Provider name identifier (e.g., 'openai', 'anthropic')
164
165***
166
167### structuredOutput()
168
169```ts
170structuredOutput: (options) => Promise<StructuredOutputResult<unknown>>;
171```
172
173Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:106](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L106)
174
175Generate structured output using the provider's native structured output API.
176This method uses stream: false and sends the JSON schema to the provider
177to ensure the response conforms to the expected structure.
178
179#### Parameters
180
181##### options
182
183`StructuredOutputOptions`\<`TProviderOptions`\>
184
185Structured output options containing chat options and JSON schema
186
187#### Returns
188
189`Promise`\<`StructuredOutputResult`\<`unknown`\>\>
190
191Promise with the raw data (validation is done in the chat function)
192
193***
194
195### structuredOutputStream()?
196
197```ts
198optional structuredOutputStream: (options) => AsyncIterable<AGUIEvent>;
199```
200
201Defined in: [packages/typescript/ai/src/activities/chat/adapter.ts:123](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/chat/adapter.ts#L123)
202
203Stream structured output using the provider's native streaming structured
204output API (stream + response_format json_schema in a single request).
205
206Optional — adapters without native streaming JSON omit this method and the
207activity layer synthesizes a stream around the non-streaming
208`structuredOutput` call.
209
210Implementations must emit standard AG-UI lifecycle events (RUN_STARTED,
211TEXT_MESSAGE_*, RUN_FINISHED) carrying raw JSON text deltas, plus a final
212`CUSTOM` event named `structured-output.complete` whose `value` is
213`{ object, raw, reasoning? }`.
214
215#### Parameters
216
217##### options
218
219`StructuredOutputOptions`\<`TProviderOptions`\>
220
221#### Returns
222
223`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>