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