@ai-sdk/xai 4.0.0-beta.7 → 4.0.0-beta.75

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +660 -9
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +213 -68
  4. package/dist/index.js +2074 -781
  5. package/dist/index.js.map +1 -1
  6. package/docs/01-xai.mdx +445 -54
  7. package/package.json +15 -15
  8. package/src/convert-to-xai-chat-messages.ts +48 -27
  9. package/src/convert-xai-chat-usage.ts +3 -3
  10. package/src/files/xai-files-api.ts +16 -0
  11. package/src/files/xai-files-options.ts +19 -0
  12. package/src/files/xai-files.ts +94 -0
  13. package/src/index.ts +9 -4
  14. package/src/map-xai-finish-reason.ts +2 -2
  15. package/src/realtime/index.ts +2 -0
  16. package/src/realtime/xai-realtime-event-mapper.ts +399 -0
  17. package/src/realtime/xai-realtime-model-options.ts +3 -0
  18. package/src/realtime/xai-realtime-model.ts +101 -0
  19. package/src/remove-additional-properties.ts +24 -0
  20. package/src/responses/convert-to-xai-responses-input.ts +100 -23
  21. package/src/responses/convert-xai-responses-usage.ts +3 -3
  22. package/src/responses/map-xai-responses-finish-reason.ts +3 -2
  23. package/src/responses/xai-responses-api.ts +31 -1
  24. package/src/responses/{xai-responses-options.ts → xai-responses-language-model-options.ts} +12 -7
  25. package/src/responses/xai-responses-language-model.ts +157 -60
  26. package/src/responses/xai-responses-prepare-tools.ts +10 -8
  27. package/src/tool/code-execution.ts +2 -2
  28. package/src/tool/file-search.ts +2 -2
  29. package/src/tool/mcp-server.ts +2 -2
  30. package/src/tool/view-image.ts +2 -2
  31. package/src/tool/view-x-video.ts +2 -2
  32. package/src/tool/web-search.ts +4 -2
  33. package/src/tool/x-search.ts +2 -2
  34. package/src/{xai-chat-options.ts → xai-chat-language-model-options.ts} +28 -13
  35. package/src/xai-chat-language-model.ts +65 -29
  36. package/src/xai-chat-prompt.ts +2 -1
  37. package/src/xai-error.ts +13 -3
  38. package/src/xai-image-model.ts +28 -11
  39. package/src/xai-prepare-tools.ts +9 -8
  40. package/src/xai-provider.ts +115 -19
  41. package/src/xai-speech-model-options.ts +55 -0
  42. package/src/xai-speech-model.ts +167 -0
  43. package/src/xai-transcription-model-options.ts +70 -0
  44. package/src/xai-transcription-model.ts +166 -0
  45. package/src/xai-video-model-options.ts +145 -0
  46. package/src/xai-video-model.ts +129 -22
  47. package/dist/index.d.mts +0 -377
  48. package/dist/index.mjs +0 -3070
  49. package/dist/index.mjs.map +0 -1
  50. package/src/xai-video-options.ts +0 -23
  51. /package/src/{xai-image-options.ts → xai-image-model-options.ts} +0 -0
@@ -1,24 +1,24 @@
1
1
  import {
2
2
  AISDKError,
3
- type Experimental_VideoModelV3,
4
- type SharedV3Warning,
3
+ type Experimental_VideoModelV4,
4
+ type SharedV4Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
7
  combineHeaders,
8
8
  convertUint8ArrayToBase64,
9
9
  createJsonResponseHandler,
10
10
  delay,
11
- type FetchFunction,
12
11
  getFromApi,
13
12
  parseProviderOptions,
14
13
  postJsonToApi,
14
+ type FetchFunction,
15
15
  } from '@ai-sdk/provider-utils';
16
16
  import { z } from 'zod/v4';
17
17
  import { xaiFailedResponseHandler } from './xai-error';
18
18
  import {
19
- type XaiVideoModelOptions,
20
19
  xaiVideoModelOptionsSchema,
21
- } from './xai-video-options';
20
+ type XaiParsedVideoModelOptions,
21
+ } from './xai-video-model-options';
22
22
  import type { XaiVideoModelId } from './xai-video-settings';
23
23
 
24
24
  interface XaiVideoModelConfig {
@@ -37,8 +37,29 @@ const RESOLUTION_MAP: Record<string, string> = {
37
37
  '640x480': '480p',
38
38
  };
39
39
 
40
- export class XaiVideoModel implements Experimental_VideoModelV3 {
41
- readonly specificationVersion = 'v3';
40
+ function resolveVideoMode(
41
+ options: XaiParsedVideoModelOptions | undefined,
42
+ ): XaiParsedVideoModelOptions['mode'] | undefined {
43
+ if (options?.mode != null) {
44
+ return options.mode;
45
+ }
46
+
47
+ if (options?.videoUrl != null) {
48
+ return 'edit-video';
49
+ }
50
+
51
+ if (
52
+ options?.referenceImageUrls != null &&
53
+ options.referenceImageUrls.length > 0
54
+ ) {
55
+ return 'reference-to-video';
56
+ }
57
+
58
+ return undefined;
59
+ }
60
+
61
+ export class XaiVideoModel implements Experimental_VideoModelV4 {
62
+ readonly specificationVersion = 'v4';
42
63
  readonly maxVideosPerCall = 1;
43
64
 
44
65
  get provider(): string {
@@ -51,18 +72,22 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
51
72
  ) {}
52
73
 
53
74
  async doGenerate(
54
- options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
55
- ): Promise<Awaited<ReturnType<Experimental_VideoModelV3['doGenerate']>>> {
75
+ options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
76
+ ): Promise<Awaited<ReturnType<Experimental_VideoModelV4['doGenerate']>>> {
56
77
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
57
- const warnings: SharedV3Warning[] = [];
78
+ const warnings: SharedV4Warning[] = [];
58
79
 
59
80
  const xaiOptions = (await parseProviderOptions({
60
81
  provider: 'xai',
61
82
  providerOptions: options.providerOptions,
62
83
  schema: xaiVideoModelOptionsSchema,
63
- })) as XaiVideoModelOptions | undefined;
84
+ })) as XaiParsedVideoModelOptions | undefined;
64
85
 
65
- const isEdit = xaiOptions?.videoUrl != null;
86
+ const effectiveMode = resolveVideoMode(xaiOptions);
87
+
88
+ const isEdit = effectiveMode === 'edit-video';
89
+ const isExtension = effectiveMode === 'extend-video';
90
+ const hasReferenceImages = effectiveMode === 'reference-to-video';
66
91
 
67
92
  if (options.fps != null) {
68
93
  warnings.push({
@@ -90,6 +115,7 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
90
115
  });
91
116
  }
92
117
 
118
+ // Edit mode: duration, aspectRatio, resolution not supported
93
119
  if (isEdit && options.duration != null) {
94
120
  warnings.push({
95
121
  type: 'unsupported',
@@ -117,22 +143,46 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
117
143
  });
118
144
  }
119
145
 
146
+ // Extension mode: aspectRatio and resolution not supported
147
+ if (isExtension && options.aspectRatio != null) {
148
+ warnings.push({
149
+ type: 'unsupported',
150
+ feature: 'aspectRatio',
151
+ details: 'xAI video extension does not support custom aspect ratio.',
152
+ });
153
+ }
154
+
155
+ if (
156
+ isExtension &&
157
+ (xaiOptions?.resolution != null || options.resolution != null)
158
+ ) {
159
+ warnings.push({
160
+ type: 'unsupported',
161
+ feature: 'resolution',
162
+ details: 'xAI video extension does not support custom resolution.',
163
+ });
164
+ }
165
+
120
166
  const body: Record<string, unknown> = {
121
167
  model: this.modelId,
122
168
  prompt: options.prompt,
123
169
  };
124
170
 
125
- if (!isEdit && options.duration != null) {
171
+ const allowDuration = !isEdit;
172
+ const allowAspectRatio = !isEdit && !isExtension;
173
+ const allowResolution = !isEdit && !isExtension;
174
+
175
+ if (allowDuration && options.duration != null) {
126
176
  body.duration = options.duration;
127
177
  }
128
178
 
129
- if (!isEdit && options.aspectRatio != null) {
179
+ if (allowAspectRatio && options.aspectRatio != null) {
130
180
  body.aspect_ratio = options.aspectRatio;
131
181
  }
132
182
 
133
- if (!isEdit && xaiOptions?.resolution != null) {
183
+ if (allowResolution && xaiOptions?.resolution != null) {
134
184
  body.resolution = xaiOptions.resolution;
135
- } else if (!isEdit && options.resolution != null) {
185
+ } else if (allowResolution && options.resolution != null) {
136
186
  const mapped = RESOLUTION_MAP[options.resolution];
137
187
  if (mapped != null) {
138
188
  body.resolution = mapped;
@@ -147,12 +197,17 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
147
197
  }
148
198
  }
149
199
 
150
- // Video editing: pass source video URL (nested object like image)
151
- if (xaiOptions?.videoUrl != null) {
152
- body.video = { url: xaiOptions.videoUrl };
200
+ // Video editing: pass source video URL (nested object)
201
+ if (isEdit) {
202
+ body.video = { url: xaiOptions!.videoUrl };
203
+ }
204
+
205
+ // Video extension: pass source video URL (nested object)
206
+ if (isExtension) {
207
+ body.video = { url: xaiOptions!.videoUrl };
153
208
  }
154
209
 
155
- // Image-to-video: convert SDK image to nested image object
210
+ // Convert SDK image input to the nested xAI request image object
156
211
  if (options.image != null) {
157
212
  if (options.image.type === 'url') {
158
213
  body.image = { url: options.image.url };
@@ -167,14 +222,23 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
167
222
  }
168
223
  }
169
224
 
225
+ // Reference images for R2V (reference-to-video) generation
226
+ if (hasReferenceImages) {
227
+ body.reference_images = xaiOptions!.referenceImageUrls!.map(url => ({
228
+ url,
229
+ }));
230
+ }
231
+
170
232
  if (xaiOptions != null) {
171
233
  for (const [key, value] of Object.entries(xaiOptions)) {
172
234
  if (
173
235
  ![
236
+ 'mode',
174
237
  'pollIntervalMs',
175
238
  'pollTimeoutMs',
176
239
  'resolution',
177
240
  'videoUrl',
241
+ 'referenceImageUrls',
178
242
  ].includes(key)
179
243
  ) {
180
244
  body[key] = value;
@@ -184,9 +248,19 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
184
248
 
185
249
  const baseURL = this.config.baseURL ?? 'https://api.x.ai/v1';
186
250
 
187
- // Step 1: Create video generation/edit request
251
+ // Determine endpoint based on mode
252
+ let endpoint: string;
253
+ if (isEdit) {
254
+ endpoint = `${baseURL}/videos/edits`;
255
+ } else if (isExtension) {
256
+ endpoint = `${baseURL}/videos/extensions`;
257
+ } else {
258
+ endpoint = `${baseURL}/videos/generations`;
259
+ }
260
+
261
+ // Step 1: Create video generation/edit/extension request
188
262
  const { value: createResponse } = await postJsonToApi({
189
- url: `${baseURL}/videos/${isEdit ? 'edits' : 'generations'}`,
263
+ url: endpoint,
190
264
  headers: combineHeaders(this.config.headers(), options.headers),
191
265
  body,
192
266
  failedResponseHandler: xaiFailedResponseHandler,
@@ -239,6 +313,14 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
239
313
  statusResponse.status === 'done' ||
240
314
  (statusResponse.status == null && statusResponse.video?.url)
241
315
  ) {
316
+ if (statusResponse.video?.respect_moderation === false) {
317
+ throw new AISDKError({
318
+ name: 'XAI_VIDEO_MODERATION_ERROR',
319
+ message:
320
+ 'Video generation was blocked due to a content policy violation.',
321
+ });
322
+ }
323
+
242
324
  if (!statusResponse.video?.url) {
243
325
  throw new AISDKError({
244
326
  name: 'XAI_VIDEO_GENERATION_ERROR',
@@ -268,6 +350,12 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
268
350
  ...(statusResponse.video.duration != null
269
351
  ? { duration: statusResponse.video.duration }
270
352
  : {}),
353
+ ...(statusResponse.usage?.cost_in_usd_ticks != null
354
+ ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks }
355
+ : {}),
356
+ ...(statusResponse.progress != null
357
+ ? { progress: statusResponse.progress }
358
+ : {}),
271
359
  },
272
360
  },
273
361
  };
@@ -280,6 +368,13 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
280
368
  });
281
369
  }
282
370
 
371
+ if (statusResponse.status === 'failed') {
372
+ throw new AISDKError({
373
+ name: 'XAI_VIDEO_GENERATION_FAILED',
374
+ message: 'Video generation failed.',
375
+ });
376
+ }
377
+
283
378
  // 'pending' → continue polling
284
379
  }
285
380
  }
@@ -299,4 +394,16 @@ const xaiVideoStatusResponseSchema = z.object({
299
394
  })
300
395
  .nullish(),
301
396
  model: z.string().nullish(),
397
+ usage: z
398
+ .object({
399
+ cost_in_usd_ticks: z.number().nullish(),
400
+ })
401
+ .nullish(),
402
+ progress: z.number().nullish(),
403
+ error: z
404
+ .object({
405
+ code: z.string().nullish(),
406
+ message: z.string().nullish(),
407
+ })
408
+ .nullish(),
302
409
  });
package/dist/index.d.mts DELETED
@@ -1,377 +0,0 @@
1
- import { z } from 'zod/v4';
2
- import { ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
3
- import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
- import { FetchFunction } from '@ai-sdk/provider-utils';
5
-
6
- type XaiChatModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | '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-mini' | 'grok-3-mini-latest' | (string & {});
7
- declare const xaiLanguageModelChatOptions: z.ZodObject<{
8
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
9
- low: "low";
10
- high: "high";
11
- }>>;
12
- logprobs: z.ZodOptional<z.ZodBoolean>;
13
- topLogprobs: z.ZodOptional<z.ZodNumber>;
14
- parallel_function_calling: z.ZodOptional<z.ZodBoolean>;
15
- searchParameters: z.ZodOptional<z.ZodObject<{
16
- mode: z.ZodEnum<{
17
- off: "off";
18
- auto: "auto";
19
- on: "on";
20
- }>;
21
- returnCitations: z.ZodOptional<z.ZodBoolean>;
22
- fromDate: z.ZodOptional<z.ZodString>;
23
- toDate: z.ZodOptional<z.ZodString>;
24
- maxSearchResults: z.ZodOptional<z.ZodNumber>;
25
- sources: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
26
- type: z.ZodLiteral<"web">;
27
- country: z.ZodOptional<z.ZodString>;
28
- excludedWebsites: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
- allowedWebsites: z.ZodOptional<z.ZodArray<z.ZodString>>;
30
- safeSearch: z.ZodOptional<z.ZodBoolean>;
31
- }, z.core.$strip>, z.ZodObject<{
32
- type: z.ZodLiteral<"x">;
33
- excludedXHandles: z.ZodOptional<z.ZodArray<z.ZodString>>;
34
- includedXHandles: z.ZodOptional<z.ZodArray<z.ZodString>>;
35
- postFavoriteCount: z.ZodOptional<z.ZodNumber>;
36
- postViewCount: z.ZodOptional<z.ZodNumber>;
37
- xHandles: z.ZodOptional<z.ZodArray<z.ZodString>>;
38
- }, z.core.$strip>, z.ZodObject<{
39
- type: z.ZodLiteral<"news">;
40
- country: z.ZodOptional<z.ZodString>;
41
- excludedWebsites: z.ZodOptional<z.ZodArray<z.ZodString>>;
42
- safeSearch: z.ZodOptional<z.ZodBoolean>;
43
- }, z.core.$strip>, z.ZodObject<{
44
- type: z.ZodLiteral<"rss">;
45
- links: z.ZodArray<z.ZodString>;
46
- }, z.core.$strip>]>>>;
47
- }, z.core.$strip>>;
48
- }, z.core.$strip>;
49
- type XaiLanguageModelChatOptions = z.infer<typeof xaiLanguageModelChatOptions>;
50
-
51
- declare const xaiErrorDataSchema: z.ZodObject<{
52
- error: z.ZodObject<{
53
- message: z.ZodString;
54
- type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
55
- param: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
56
- code: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
57
- }, z.core.$strip>;
58
- }, z.core.$strip>;
59
- type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
60
-
61
- type XaiResponsesModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | (string & {});
62
- /**
63
- * @see https://docs.x.ai/docs/api-reference#create-new-response
64
- */
65
- declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
66
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
67
- low: "low";
68
- high: "high";
69
- medium: "medium";
70
- }>>;
71
- reasoningSummary: z.ZodOptional<z.ZodEnum<{
72
- auto: "auto";
73
- concise: "concise";
74
- detailed: "detailed";
75
- }>>;
76
- logprobs: z.ZodOptional<z.ZodBoolean>;
77
- topLogprobs: z.ZodOptional<z.ZodNumber>;
78
- store: z.ZodOptional<z.ZodBoolean>;
79
- previousResponseId: z.ZodOptional<z.ZodString>;
80
- include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
81
- "file_search_call.results": "file_search_call.results";
82
- }>>>>;
83
- }, z.core.$strip>;
84
- type XaiLanguageModelResponsesOptions = z.infer<typeof xaiLanguageModelResponsesOptions>;
85
-
86
- declare const xaiImageModelOptions: z.ZodObject<{
87
- aspect_ratio: z.ZodOptional<z.ZodString>;
88
- output_format: z.ZodOptional<z.ZodString>;
89
- sync_mode: z.ZodOptional<z.ZodBoolean>;
90
- resolution: z.ZodOptional<z.ZodEnum<{
91
- "1k": "1k";
92
- "2k": "2k";
93
- }>>;
94
- quality: z.ZodOptional<z.ZodEnum<{
95
- low: "low";
96
- high: "high";
97
- medium: "medium";
98
- }>>;
99
- user: z.ZodOptional<z.ZodString>;
100
- }, z.core.$strip>;
101
- type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
102
-
103
- type XaiVideoModelId = 'grok-imagine-video' | (string & {});
104
-
105
- type XaiVideoModelOptions = {
106
- pollIntervalMs?: number | null;
107
- pollTimeoutMs?: number | null;
108
- resolution?: '480p' | '720p' | null;
109
- videoUrl?: string | null;
110
- [key: string]: unknown;
111
- };
112
-
113
- type XaiImageModelId = 'grok-imagine-image' | 'grok-imagine-image-pro' | (string & {});
114
-
115
- declare const codeExecutionToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
116
- output: string;
117
- error?: string | undefined;
118
- }, object>;
119
- declare const codeExecution: (args?: Parameters<typeof codeExecutionToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
120
- output: string;
121
- error?: string | undefined;
122
- }>;
123
-
124
- declare const mcpServerToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
125
- name: string;
126
- arguments: string;
127
- result: unknown;
128
- }, {
129
- serverUrl: string;
130
- serverLabel?: string;
131
- serverDescription?: string;
132
- allowedTools?: string[];
133
- headers?: Record<string, string>;
134
- authorization?: string;
135
- }>;
136
- declare const mcpServer: (args: Parameters<typeof mcpServerToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
137
- name: string;
138
- arguments: string;
139
- result: unknown;
140
- }>;
141
-
142
- declare const viewImageToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
143
- description: string;
144
- objects?: string[] | undefined;
145
- }, object>;
146
- declare const viewImage: (args?: Parameters<typeof viewImageToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
147
- description: string;
148
- objects?: string[] | undefined;
149
- }>;
150
-
151
- declare const viewXVideoToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
152
- description: string;
153
- transcript?: string | undefined;
154
- duration?: number | undefined;
155
- }, object>;
156
- declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
157
- description: string;
158
- transcript?: string | undefined;
159
- duration?: number | undefined;
160
- }>;
161
-
162
- declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
163
- query: string;
164
- sources: Array<{
165
- title: string;
166
- url: string;
167
- snippet: string;
168
- }>;
169
- }, {
170
- allowedDomains?: string[];
171
- excludedDomains?: string[];
172
- enableImageUnderstanding?: boolean;
173
- }>;
174
- declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
175
- query: string;
176
- sources: Array<{
177
- title: string;
178
- url: string;
179
- snippet: string;
180
- }>;
181
- }>;
182
-
183
- declare const xSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
184
- query: string;
185
- posts: Array<{
186
- author: string;
187
- text: string;
188
- url: string;
189
- likes: number;
190
- }>;
191
- }, {
192
- allowedXHandles?: string[];
193
- excludedXHandles?: string[];
194
- fromDate?: string;
195
- toDate?: string;
196
- enableImageUnderstanding?: boolean;
197
- enableVideoUnderstanding?: boolean;
198
- }>;
199
- declare const xSearch: (args?: Parameters<typeof xSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
200
- query: string;
201
- posts: Array<{
202
- author: string;
203
- text: string;
204
- url: string;
205
- likes: number;
206
- }>;
207
- }>;
208
-
209
- declare const xaiTools: {
210
- codeExecution: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
211
- output: string;
212
- error?: string | undefined;
213
- }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
214
- output: string;
215
- error?: string | undefined;
216
- }>;
217
- fileSearch: (args: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
218
- queries: string[];
219
- results: null | {
220
- fileId: string;
221
- filename: string;
222
- score: number;
223
- text: string;
224
- }[];
225
- }, {
226
- vectorStoreIds: string[];
227
- maxNumResults?: number;
228
- }>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
229
- queries: string[];
230
- results: null | {
231
- fileId: string;
232
- filename: string;
233
- score: number;
234
- text: string;
235
- }[];
236
- }>;
237
- mcpServer: (args: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
238
- name: string;
239
- arguments: string;
240
- result: unknown;
241
- }, {
242
- serverUrl: string;
243
- serverLabel?: string;
244
- serverDescription?: string;
245
- allowedTools?: string[];
246
- headers?: Record<string, string>;
247
- authorization?: string;
248
- }>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
249
- name: string;
250
- arguments: string;
251
- result: unknown;
252
- }>;
253
- viewImage: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
254
- description: string;
255
- objects?: string[] | undefined;
256
- }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
257
- description: string;
258
- objects?: string[] | undefined;
259
- }>;
260
- viewXVideo: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
261
- description: string;
262
- transcript?: string | undefined;
263
- duration?: number | undefined;
264
- }, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
265
- description: string;
266
- transcript?: string | undefined;
267
- duration?: number | undefined;
268
- }>;
269
- webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
270
- query: string;
271
- sources: Array<{
272
- title: string;
273
- url: string;
274
- snippet: string;
275
- }>;
276
- }, {
277
- allowedDomains?: string[];
278
- excludedDomains?: string[];
279
- enableImageUnderstanding?: boolean;
280
- }>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
281
- query: string;
282
- sources: Array<{
283
- title: string;
284
- url: string;
285
- snippet: string;
286
- }>;
287
- }>;
288
- xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
289
- query: string;
290
- posts: Array<{
291
- author: string;
292
- text: string;
293
- url: string;
294
- likes: number;
295
- }>;
296
- }, {
297
- allowedXHandles?: string[];
298
- excludedXHandles?: string[];
299
- fromDate?: string;
300
- toDate?: string;
301
- enableImageUnderstanding?: boolean;
302
- enableVideoUnderstanding?: boolean;
303
- }>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
304
- query: string;
305
- posts: Array<{
306
- author: string;
307
- text: string;
308
- url: string;
309
- likes: number;
310
- }>;
311
- }>;
312
- };
313
-
314
- interface XaiProvider extends ProviderV3 {
315
- (modelId: XaiResponsesModelId): LanguageModelV3;
316
- /**
317
- * Creates an Xai language model for text generation.
318
- */
319
- languageModel(modelId: XaiResponsesModelId): LanguageModelV3;
320
- /**
321
- * Creates an Xai chat model for text generation.
322
- */
323
- chat: (modelId: XaiChatModelId) => LanguageModelV3;
324
- /**
325
- * Creates an Xai responses model for text generation.
326
- */
327
- responses: (modelId: XaiResponsesModelId) => LanguageModelV3;
328
- /**
329
- * Creates an Xai image model for image generation.
330
- */
331
- image(modelId: XaiImageModelId): ImageModelV3;
332
- /**
333
- * Creates an Xai image model for image generation.
334
- */
335
- imageModel(modelId: XaiImageModelId): ImageModelV3;
336
- /**
337
- * Creates an Xai video model for video generation.
338
- */
339
- video(modelId: XaiVideoModelId): Experimental_VideoModelV3;
340
- /**
341
- * Creates an Xai video model for video generation.
342
- */
343
- videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV3;
344
- /**
345
- * Server-side agentic tools for use with the responses API.
346
- */
347
- tools: typeof xaiTools;
348
- /**
349
- * @deprecated Use `embeddingModel` instead.
350
- */
351
- textEmbeddingModel(modelId: string): never;
352
- }
353
- interface XaiProviderSettings {
354
- /**
355
- * Base URL for the xAI API calls.
356
- */
357
- baseURL?: string;
358
- /**
359
- * API key for authenticating requests.
360
- */
361
- apiKey?: string;
362
- /**
363
- * Custom headers to include in the requests.
364
- */
365
- headers?: Record<string, string>;
366
- /**
367
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
368
- * or to provide a custom fetch implementation for e.g. testing.
369
- */
370
- fetch?: FetchFunction;
371
- }
372
- declare function createXai(options?: XaiProviderSettings): XaiProvider;
373
- declare const xai: XaiProvider;
374
-
375
- declare const VERSION: string;
376
-
377
- export { VERSION, type XaiErrorData, type XaiImageModelOptions, type XaiImageModelOptions as XaiImageProviderOptions, type XaiLanguageModelChatOptions, type XaiLanguageModelResponsesOptions, type XaiProvider, type XaiLanguageModelChatOptions as XaiProviderOptions, type XaiProviderSettings, type XaiLanguageModelResponsesOptions as XaiResponsesProviderOptions, type XaiVideoModelId, type XaiVideoModelOptions, type XaiVideoModelOptions as XaiVideoProviderOptions, codeExecution, createXai, mcpServer, viewImage, viewXVideo, webSearch, xSearch, xai, xaiTools };