Open History to see the last commit
1---
2id: createModel
3title: createModel
4---
5
6## Call Signature
7
8```ts
9function createModel<TName, TInput>(name, input): ExtendedModelDef<TName, TInput>;
10```
11
12Defined in: packages/ai/src/extend-adapter.ts:91
13
14Creates a custom model definition for use with `extendAdapter`.
15
16This is a helper function that provides proper type inference without
17requiring manual `as const` casts on individual properties.
18
19### Type Parameters
20
21#### TName
22
23`TName` *extends* `string`
24
25The model name (inferred from argument)
26
27#### TInput
28
29`TInput` *extends* readonly (`"text"` \| `"image"` \| `"audio"` \| `"video"` \| `"document"`)[]
30
31The input modalities array (inferred from argument)
32
33### Parameters
34
35#### name
36
37`TName`
38
39The model name identifier (literal string)
40
41#### input
42
43`TInput`
44
45Array of supported input modalities
46
47### Returns
48
49[`ExtendedModelDef`](../interfaces/ExtendedModelDef.md)\<`TName`, `TInput`\>
50
51A properly typed model definition for use with `extendAdapter`
52
53### Examples
54
55```typescript
56import { extendAdapter, createModel } from '@tanstack/ai'
57import { openaiText } from '@tanstack/ai-openai'
58
59// Define custom models with full type inference
60const customModels = [
61 createModel('my-fine-tuned-gpt4', ['text', 'image']),
62 createModel('local-llama', ['text']),
63] as const
64
65const myOpenai = extendAdapter(openaiText, customModels)
66```
67
68```typescript
69// Capabilities object form - declare features and provider tools
70const reasoner = createModel('reasoner', {
71 input: ['text'],
72 features: ['reasoning', 'structured_outputs'],
73 tools: ['web_search'],
74})
75```
76
77## Call Signature
78
79```ts
80function createModel<TName, TCaps>(name, capabilities): ExtendedModelDef<TName, TCaps["input"] extends readonly ("text" | "image" | "audio" | "video" | "document")[] ? any[any] : readonly ("text" | "image" | "audio" | "video" | "document")[], TCaps["modelOptions"], TCaps["features"] extends readonly string[] ? any[any] : readonly string[], TCaps["tools"] extends readonly string[] ? any[any] : readonly string[]>;
81```
82
83Defined in: packages/ai/src/extend-adapter.ts:96
84
85Creates a custom model definition for use with `extendAdapter`.
86
87This is a helper function that provides proper type inference without
88requiring manual `as const` casts on individual properties.
89
90### Type Parameters
91
92#### TName
93
94`TName` *extends* `string`
95
96The model name (inferred from argument)
97
98#### TCaps
99
100`TCaps` *extends* [`ModelCapabilities`](../interfaces/ModelCapabilities.md)\<readonly (`"text"` \| `"image"` \| `"audio"` \| `"video"` \| `"document"`)[], readonly `string`[], readonly `string`[], `unknown`\>
101
102### Parameters
103
104#### name
105
106`TName`
107
108The model name identifier (literal string)
109
110#### capabilities
111
112`TCaps`
113
114### Returns
115
116[`ExtendedModelDef`](../interfaces/ExtendedModelDef.md)\<`TName`, `TCaps`\[`"input"`\] *extends* readonly (`"text"` \| `"image"` \| `"audio"` \| `"video"` \| `"document"`)[] ? `any`\[`any`\] : readonly (`"text"` \| `"image"` \| `"audio"` \| `"video"` \| `"document"`)[], `TCaps`\[`"modelOptions"`\], `TCaps`\[`"features"`\] *extends* readonly `string`[] ? `any`\[`any`\] : readonly `string`[], `TCaps`\[`"tools"`\] *extends* readonly `string`[] ? `any`\[`any`\] : readonly `string`[]\>
117
118A properly typed model definition for use with `extendAdapter`
119
120### Examples
121
122```typescript
123import { extendAdapter, createModel } from '@tanstack/ai'
124import { openaiText } from '@tanstack/ai-openai'
125
126// Define custom models with full type inference
127const customModels = [
128 createModel('my-fine-tuned-gpt4', ['text', 'image']),
129 createModel('local-llama', ['text']),
130] as const
131
132const myOpenai = extendAdapter(openaiText, customModels)
133```
134
135```typescript
136// Capabilities object form - declare features and provider tools
137const reasoner = createModel('reasoner', {
138 input: ['text'],
139 features: ['reasoning', 'structured_outputs'],
140 tools: ['web_search'],
141})
142```