@ai-sdk/xai 2.0.34 → 2.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 2.0.36
4
+
5
+ ### Patch Changes
6
+
7
+ - 97b820b: fix(xai): responses model fixes
8
+
9
+ ## 2.0.35
10
+
11
+ ### Patch Changes
12
+
13
+ - 4b86c09: feat: xai server-side tool calling
14
+
3
15
  ## 2.0.34
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod/v4';
2
2
  import { ProviderV2, LanguageModelV2, ImageModelV2 } from '@ai-sdk/provider';
3
+ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
4
5
 
5
6
  type XaiChatModelId = 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-code-fast-1' | 'grok-4' | 'grok-4-0709' | 'grok-4-latest' | 'grok-3' | 'grok-3-latest' | 'grok-3-fast' | 'grok-3-fast-latest' | 'grok-3-mini' | 'grok-3-mini-latest' | 'grok-3-mini-fast' | 'grok-3-mini-fast-latest' | 'grok-2-vision-1212' | 'grok-2-vision' | 'grok-2-vision-latest' | 'grok-2-image-1212' | 'grok-2-image' | 'grok-2-image-latest' | 'grok-2-1212' | 'grok-2' | 'grok-2-latest' | 'grok-vision-beta' | 'grok-beta' | (string & {});
@@ -55,8 +56,168 @@ declare const xaiErrorDataSchema: z.ZodObject<{
55
56
  }, z.core.$strip>;
56
57
  type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
57
58
 
59
+ type XaiResponsesModelId = 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
60
+ /**
61
+ * @see https://docs.x.ai/docs/api-reference#create-new-response
62
+ */
63
+ declare const xaiResponsesProviderOptions: z.ZodObject<{
64
+ reasoningEffort: z.ZodOptional<z.ZodEnum<{
65
+ low: "low";
66
+ high: "high";
67
+ medium: "medium";
68
+ }>>;
69
+ store: z.ZodOptional<z.ZodBoolean>;
70
+ previousResponseId: z.ZodOptional<z.ZodString>;
71
+ }, z.core.$strip>;
72
+ type XaiResponsesProviderOptions = z.infer<typeof xaiResponsesProviderOptions>;
73
+
58
74
  type XaiImageModelId = 'grok-2-image' | (string & {});
59
75
 
76
+ declare const codeExecutionToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
77
+ output: string;
78
+ error?: string | undefined;
79
+ }, object>;
80
+ declare const codeExecution: (args?: Parameters<typeof codeExecutionToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
81
+ output: string;
82
+ error?: string | undefined;
83
+ }>;
84
+
85
+ declare const viewImageToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
86
+ description: string;
87
+ objects?: string[] | undefined;
88
+ }, object>;
89
+ declare const viewImage: (args?: Parameters<typeof viewImageToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
90
+ description: string;
91
+ objects?: string[] | undefined;
92
+ }>;
93
+
94
+ declare const viewXVideoToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
95
+ description: string;
96
+ transcript?: string | undefined;
97
+ duration?: number | undefined;
98
+ }, object>;
99
+ declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
100
+ description: string;
101
+ transcript?: string | undefined;
102
+ duration?: number | undefined;
103
+ }>;
104
+
105
+ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
106
+ query: string;
107
+ sources: Array<{
108
+ title: string;
109
+ url: string;
110
+ snippet: string;
111
+ }>;
112
+ }, {
113
+ allowedDomains?: string[];
114
+ excludedDomains?: string[];
115
+ enableImageUnderstanding?: boolean;
116
+ }>;
117
+ declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
118
+ query: string;
119
+ sources: Array<{
120
+ title: string;
121
+ url: string;
122
+ snippet: string;
123
+ }>;
124
+ }>;
125
+
126
+ declare const xSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
127
+ query: string;
128
+ posts: Array<{
129
+ author: string;
130
+ text: string;
131
+ url: string;
132
+ likes: number;
133
+ }>;
134
+ }, {
135
+ allowedXHandles?: string[];
136
+ excludedXHandles?: string[];
137
+ fromDate?: string;
138
+ toDate?: string;
139
+ enableImageUnderstanding?: boolean;
140
+ enableVideoUnderstanding?: boolean;
141
+ }>;
142
+ declare const xSearch: (args?: Parameters<typeof xSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
143
+ query: string;
144
+ posts: Array<{
145
+ author: string;
146
+ text: string;
147
+ url: string;
148
+ likes: number;
149
+ }>;
150
+ }>;
151
+
152
+ declare const xaiTools: {
153
+ codeExecution: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
154
+ output: string;
155
+ error?: string | undefined;
156
+ }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
157
+ output: string;
158
+ error?: string | undefined;
159
+ }>;
160
+ viewImage: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
161
+ description: string;
162
+ objects?: string[] | undefined;
163
+ }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
164
+ description: string;
165
+ objects?: string[] | undefined;
166
+ }>;
167
+ viewXVideo: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
168
+ description: string;
169
+ transcript?: string | undefined;
170
+ duration?: number | undefined;
171
+ }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
172
+ description: string;
173
+ transcript?: string | undefined;
174
+ duration?: number | undefined;
175
+ }>;
176
+ webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
177
+ query: string;
178
+ sources: Array<{
179
+ title: string;
180
+ url: string;
181
+ snippet: string;
182
+ }>;
183
+ }, {
184
+ allowedDomains?: string[];
185
+ excludedDomains?: string[];
186
+ enableImageUnderstanding?: boolean;
187
+ }>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
188
+ query: string;
189
+ sources: Array<{
190
+ title: string;
191
+ url: string;
192
+ snippet: string;
193
+ }>;
194
+ }>;
195
+ xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
196
+ query: string;
197
+ posts: Array<{
198
+ author: string;
199
+ text: string;
200
+ url: string;
201
+ likes: number;
202
+ }>;
203
+ }, {
204
+ allowedXHandles?: string[];
205
+ excludedXHandles?: string[];
206
+ fromDate?: string;
207
+ toDate?: string;
208
+ enableImageUnderstanding?: boolean;
209
+ enableVideoUnderstanding?: boolean;
210
+ }>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
211
+ query: string;
212
+ posts: Array<{
213
+ author: string;
214
+ text: string;
215
+ url: string;
216
+ likes: number;
217
+ }>;
218
+ }>;
219
+ };
220
+
60
221
  interface XaiProvider extends ProviderV2 {
61
222
  /**
62
223
  Creates an Xai chat model for text generation.
@@ -71,6 +232,10 @@ interface XaiProvider extends ProviderV2 {
71
232
  */
72
233
  chat: (modelId: XaiChatModelId) => LanguageModelV2;
73
234
  /**
235
+ Creates an Xai responses model for agentic tool calling.
236
+ */
237
+ responses: (modelId: XaiResponsesModelId) => LanguageModelV2;
238
+ /**
74
239
  Creates an Xai image model for image generation.
75
240
  */
76
241
  image(modelId: XaiImageModelId): ImageModelV2;
@@ -78,6 +243,10 @@ interface XaiProvider extends ProviderV2 {
78
243
  Creates an Xai image model for image generation.
79
244
  */
80
245
  imageModel(modelId: XaiImageModelId): ImageModelV2;
246
+ /**
247
+ Server-side agentic tools for use with the responses API.
248
+ */
249
+ tools: typeof xaiTools;
81
250
  }
82
251
  interface XaiProviderSettings {
83
252
  /**
@@ -103,4 +272,4 @@ declare const xai: XaiProvider;
103
272
 
104
273
  declare const VERSION: string;
105
274
 
106
- export { VERSION, type XaiErrorData, type XaiProvider, type XaiProviderOptions, type XaiProviderSettings, createXai, xai };
275
+ export { VERSION, type XaiErrorData, type XaiProvider, type XaiProviderOptions, type XaiProviderSettings, type XaiResponsesProviderOptions, codeExecution, createXai, viewImage, viewXVideo, webSearch, xSearch, xai, xaiTools };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod/v4';
2
2
  import { ProviderV2, LanguageModelV2, ImageModelV2 } from '@ai-sdk/provider';
3
+ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
4
5
 
5
6
  type XaiChatModelId = 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-code-fast-1' | 'grok-4' | 'grok-4-0709' | 'grok-4-latest' | 'grok-3' | 'grok-3-latest' | 'grok-3-fast' | 'grok-3-fast-latest' | 'grok-3-mini' | 'grok-3-mini-latest' | 'grok-3-mini-fast' | 'grok-3-mini-fast-latest' | 'grok-2-vision-1212' | 'grok-2-vision' | 'grok-2-vision-latest' | 'grok-2-image-1212' | 'grok-2-image' | 'grok-2-image-latest' | 'grok-2-1212' | 'grok-2' | 'grok-2-latest' | 'grok-vision-beta' | 'grok-beta' | (string & {});
@@ -55,8 +56,168 @@ declare const xaiErrorDataSchema: z.ZodObject<{
55
56
  }, z.core.$strip>;
56
57
  type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
57
58
 
59
+ type XaiResponsesModelId = 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
60
+ /**
61
+ * @see https://docs.x.ai/docs/api-reference#create-new-response
62
+ */
63
+ declare const xaiResponsesProviderOptions: z.ZodObject<{
64
+ reasoningEffort: z.ZodOptional<z.ZodEnum<{
65
+ low: "low";
66
+ high: "high";
67
+ medium: "medium";
68
+ }>>;
69
+ store: z.ZodOptional<z.ZodBoolean>;
70
+ previousResponseId: z.ZodOptional<z.ZodString>;
71
+ }, z.core.$strip>;
72
+ type XaiResponsesProviderOptions = z.infer<typeof xaiResponsesProviderOptions>;
73
+
58
74
  type XaiImageModelId = 'grok-2-image' | (string & {});
59
75
 
76
+ declare const codeExecutionToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
77
+ output: string;
78
+ error?: string | undefined;
79
+ }, object>;
80
+ declare const codeExecution: (args?: Parameters<typeof codeExecutionToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
81
+ output: string;
82
+ error?: string | undefined;
83
+ }>;
84
+
85
+ declare const viewImageToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
86
+ description: string;
87
+ objects?: string[] | undefined;
88
+ }, object>;
89
+ declare const viewImage: (args?: Parameters<typeof viewImageToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
90
+ description: string;
91
+ objects?: string[] | undefined;
92
+ }>;
93
+
94
+ declare const viewXVideoToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
95
+ description: string;
96
+ transcript?: string | undefined;
97
+ duration?: number | undefined;
98
+ }, object>;
99
+ declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
100
+ description: string;
101
+ transcript?: string | undefined;
102
+ duration?: number | undefined;
103
+ }>;
104
+
105
+ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
106
+ query: string;
107
+ sources: Array<{
108
+ title: string;
109
+ url: string;
110
+ snippet: string;
111
+ }>;
112
+ }, {
113
+ allowedDomains?: string[];
114
+ excludedDomains?: string[];
115
+ enableImageUnderstanding?: boolean;
116
+ }>;
117
+ declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
118
+ query: string;
119
+ sources: Array<{
120
+ title: string;
121
+ url: string;
122
+ snippet: string;
123
+ }>;
124
+ }>;
125
+
126
+ declare const xSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
127
+ query: string;
128
+ posts: Array<{
129
+ author: string;
130
+ text: string;
131
+ url: string;
132
+ likes: number;
133
+ }>;
134
+ }, {
135
+ allowedXHandles?: string[];
136
+ excludedXHandles?: string[];
137
+ fromDate?: string;
138
+ toDate?: string;
139
+ enableImageUnderstanding?: boolean;
140
+ enableVideoUnderstanding?: boolean;
141
+ }>;
142
+ declare const xSearch: (args?: Parameters<typeof xSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
143
+ query: string;
144
+ posts: Array<{
145
+ author: string;
146
+ text: string;
147
+ url: string;
148
+ likes: number;
149
+ }>;
150
+ }>;
151
+
152
+ declare const xaiTools: {
153
+ codeExecution: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
154
+ output: string;
155
+ error?: string | undefined;
156
+ }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
157
+ output: string;
158
+ error?: string | undefined;
159
+ }>;
160
+ viewImage: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
161
+ description: string;
162
+ objects?: string[] | undefined;
163
+ }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
164
+ description: string;
165
+ objects?: string[] | undefined;
166
+ }>;
167
+ viewXVideo: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
168
+ description: string;
169
+ transcript?: string | undefined;
170
+ duration?: number | undefined;
171
+ }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
172
+ description: string;
173
+ transcript?: string | undefined;
174
+ duration?: number | undefined;
175
+ }>;
176
+ webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
177
+ query: string;
178
+ sources: Array<{
179
+ title: string;
180
+ url: string;
181
+ snippet: string;
182
+ }>;
183
+ }, {
184
+ allowedDomains?: string[];
185
+ excludedDomains?: string[];
186
+ enableImageUnderstanding?: boolean;
187
+ }>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
188
+ query: string;
189
+ sources: Array<{
190
+ title: string;
191
+ url: string;
192
+ snippet: string;
193
+ }>;
194
+ }>;
195
+ xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
196
+ query: string;
197
+ posts: Array<{
198
+ author: string;
199
+ text: string;
200
+ url: string;
201
+ likes: number;
202
+ }>;
203
+ }, {
204
+ allowedXHandles?: string[];
205
+ excludedXHandles?: string[];
206
+ fromDate?: string;
207
+ toDate?: string;
208
+ enableImageUnderstanding?: boolean;
209
+ enableVideoUnderstanding?: boolean;
210
+ }>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
211
+ query: string;
212
+ posts: Array<{
213
+ author: string;
214
+ text: string;
215
+ url: string;
216
+ likes: number;
217
+ }>;
218
+ }>;
219
+ };
220
+
60
221
  interface XaiProvider extends ProviderV2 {
61
222
  /**
62
223
  Creates an Xai chat model for text generation.
@@ -71,6 +232,10 @@ interface XaiProvider extends ProviderV2 {
71
232
  */
72
233
  chat: (modelId: XaiChatModelId) => LanguageModelV2;
73
234
  /**
235
+ Creates an Xai responses model for agentic tool calling.
236
+ */
237
+ responses: (modelId: XaiResponsesModelId) => LanguageModelV2;
238
+ /**
74
239
  Creates an Xai image model for image generation.
75
240
  */
76
241
  image(modelId: XaiImageModelId): ImageModelV2;
@@ -78,6 +243,10 @@ interface XaiProvider extends ProviderV2 {
78
243
  Creates an Xai image model for image generation.
79
244
  */
80
245
  imageModel(modelId: XaiImageModelId): ImageModelV2;
246
+ /**
247
+ Server-side agentic tools for use with the responses API.
248
+ */
249
+ tools: typeof xaiTools;
81
250
  }
82
251
  interface XaiProviderSettings {
83
252
  /**
@@ -103,4 +272,4 @@ declare const xai: XaiProvider;
103
272
 
104
273
  declare const VERSION: string;
105
274
 
106
- export { VERSION, type XaiErrorData, type XaiProvider, type XaiProviderOptions, type XaiProviderSettings, createXai, xai };
275
+ export { VERSION, type XaiErrorData, type XaiProvider, type XaiProviderOptions, type XaiProviderSettings, type XaiResponsesProviderOptions, codeExecution, createXai, viewImage, viewXVideo, webSearch, xSearch, xai, xaiTools };