@ai-sdk/xai 4.0.0-beta.21 → 4.0.0-beta.23
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 +16 -0
- package/dist/index.d.mts +82 -8
- package/dist/index.d.ts +82 -8
- package/dist/index.js +264 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +275 -44
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +166 -47
- package/package.json +4 -4
- package/src/convert-to-xai-chat-messages.ts +17 -1
- package/src/files/xai-files-api.ts +16 -0
- package/src/files/xai-files-options.ts +15 -0
- package/src/files/xai-files.ts +93 -0
- package/src/index.ts +1 -0
- package/src/responses/convert-to-xai-responses-input.ts +14 -2
- package/src/responses/xai-responses-api.ts +2 -1
- package/src/xai-chat-prompt.ts +2 -1
- package/src/xai-provider.ts +16 -0
- package/src/xai-video-model.ts +104 -13
- package/src/xai-video-options.ts +136 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
|
|
8
|
+
- Updated dependencies [c29a26f]
|
|
9
|
+
- @ai-sdk/openai-compatible@3.0.0-beta.14
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.0-beta.10
|
|
11
|
+
- @ai-sdk/provider@4.0.0-beta.6
|
|
12
|
+
|
|
13
|
+
## 4.0.0-beta.22
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- f51c95e: feat(provider/xai): add video extension and reference-to-video (R2V) support
|
|
18
|
+
|
|
3
19
|
## 4.0.0-beta.21
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import { ProviderV4, LanguageModelV4, ImageModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
3
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
|
+
import { ProviderV4, LanguageModelV4, ImageModelV4, Experimental_VideoModelV4, FilesV4 } from '@ai-sdk/provider';
|
|
5
5
|
|
|
6
6
|
type XaiChatModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-0309-reasoning' | 'grok-4.20-multi-agent-0309' | '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
7
|
declare const xaiLanguageModelChatOptions: z.ZodObject<{
|
|
@@ -102,13 +102,83 @@ type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
|
|
|
102
102
|
|
|
103
103
|
type XaiVideoModelId = 'grok-imagine-video' | (string & {});
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
declare const resolutionSchema: z.ZodEnum<{
|
|
106
|
+
"480p": "480p";
|
|
107
|
+
"720p": "720p";
|
|
108
|
+
}>;
|
|
109
|
+
type XaiVideoResolution = z.infer<typeof resolutionSchema>;
|
|
110
|
+
interface XaiVideoSharedOptions {
|
|
106
111
|
pollIntervalMs?: number | null;
|
|
107
112
|
pollTimeoutMs?: number | null;
|
|
108
|
-
resolution?:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
resolution?: XaiVideoResolution | null;
|
|
114
|
+
}
|
|
115
|
+
interface XaiVideoEditModeOptions extends XaiVideoSharedOptions {
|
|
116
|
+
/**
|
|
117
|
+
* Select edit-video mode explicitly for best autocomplete and narrowing.
|
|
118
|
+
*/
|
|
119
|
+
mode: 'edit-video';
|
|
120
|
+
/** Source video URL to edit. */
|
|
121
|
+
videoUrl: string;
|
|
122
|
+
}
|
|
123
|
+
interface XaiVideoExtendModeOptions extends XaiVideoSharedOptions {
|
|
124
|
+
/**
|
|
125
|
+
* Select extend-video mode explicitly for best autocomplete and narrowing.
|
|
126
|
+
*/
|
|
127
|
+
mode: 'extend-video';
|
|
128
|
+
/** Source video URL to extend from its last frame. */
|
|
129
|
+
videoUrl: string;
|
|
130
|
+
}
|
|
131
|
+
interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions {
|
|
132
|
+
/**
|
|
133
|
+
* Select reference-to-video mode explicitly for best autocomplete and narrowing.
|
|
134
|
+
*/
|
|
135
|
+
mode: 'reference-to-video';
|
|
136
|
+
/** Reference image URLs (1-7) for R2V generation. */
|
|
137
|
+
referenceImageUrls: string[];
|
|
138
|
+
}
|
|
139
|
+
interface XaiVideoGenerationOptions extends XaiVideoSharedOptions {
|
|
140
|
+
mode?: undefined;
|
|
141
|
+
videoUrl?: undefined;
|
|
142
|
+
referenceImageUrls?: undefined;
|
|
143
|
+
}
|
|
144
|
+
interface XaiLegacyEditVideoOptions extends XaiVideoSharedOptions {
|
|
145
|
+
/**
|
|
146
|
+
* Legacy backward-compatible shape: omitting `mode` while providing
|
|
147
|
+
* `videoUrl` behaves like edit-video.
|
|
148
|
+
*/
|
|
149
|
+
mode?: undefined;
|
|
150
|
+
videoUrl: string;
|
|
151
|
+
}
|
|
152
|
+
interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Legacy backward-compatible shape: omitting `mode` while providing
|
|
155
|
+
* `referenceImageUrls` behaves like reference-to-video.
|
|
156
|
+
*/
|
|
157
|
+
mode?: undefined;
|
|
158
|
+
referenceImageUrls: string[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Provider options for xAI video generation.
|
|
162
|
+
*
|
|
163
|
+
* Use the `mode` option to select the operation:
|
|
164
|
+
*
|
|
165
|
+
* - `'edit-video'` + `videoUrl` -- video editing (`POST /v1/videos/edits`)
|
|
166
|
+
* - `'extend-video'` + `videoUrl` -- video extension (`POST /v1/videos/extensions`)
|
|
167
|
+
* - `'reference-to-video'` + `referenceImageUrls` -- R2V generation (`POST /v1/videos/generations`)
|
|
168
|
+
* - no `mode` -- standard generation from text prompts or image input
|
|
169
|
+
*
|
|
170
|
+
* Runtime remains backward compatible with legacy auto-detected provider
|
|
171
|
+
* options, but the public TypeScript type is intentionally explicit so editors
|
|
172
|
+
* can suggest valid modes and flag invalid field combinations.
|
|
173
|
+
*/
|
|
174
|
+
type XaiVideoModelOptions = XaiVideoGenerationOptions | XaiVideoEditModeOptions | XaiVideoExtendModeOptions | XaiVideoReferenceToVideoOptions | XaiLegacyEditVideoOptions | XaiLegacyReferenceToVideoOptions;
|
|
175
|
+
|
|
176
|
+
declare const xaiFilesOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
177
|
+
[x: string]: unknown;
|
|
178
|
+
teamId?: string | undefined;
|
|
179
|
+
filePath?: string | undefined;
|
|
180
|
+
}>;
|
|
181
|
+
type XaiFilesOptions = InferSchema<typeof xaiFilesOptionsSchema>;
|
|
112
182
|
|
|
113
183
|
type XaiImageModelId = 'grok-imagine-image' | 'grok-imagine-image-pro' | (string & {});
|
|
114
184
|
|
|
@@ -341,6 +411,10 @@ interface XaiProvider extends ProviderV4 {
|
|
|
341
411
|
* Creates an Xai video model for video generation.
|
|
342
412
|
*/
|
|
343
413
|
videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
414
|
+
/**
|
|
415
|
+
* Returns the xAI files interface for uploading files.
|
|
416
|
+
*/
|
|
417
|
+
files(): FilesV4;
|
|
344
418
|
/**
|
|
345
419
|
* Server-side agentic tools for use with the responses API.
|
|
346
420
|
*/
|
|
@@ -374,4 +448,4 @@ declare const xai: XaiProvider;
|
|
|
374
448
|
|
|
375
449
|
declare const VERSION: string;
|
|
376
450
|
|
|
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 };
|
|
451
|
+
export { VERSION, type XaiErrorData, type XaiFilesOptions, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import { ProviderV4, LanguageModelV4, ImageModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
3
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
|
+
import { ProviderV4, LanguageModelV4, ImageModelV4, Experimental_VideoModelV4, FilesV4 } from '@ai-sdk/provider';
|
|
5
5
|
|
|
6
6
|
type XaiChatModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-0309-reasoning' | 'grok-4.20-multi-agent-0309' | '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
7
|
declare const xaiLanguageModelChatOptions: z.ZodObject<{
|
|
@@ -102,13 +102,83 @@ type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
|
|
|
102
102
|
|
|
103
103
|
type XaiVideoModelId = 'grok-imagine-video' | (string & {});
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
declare const resolutionSchema: z.ZodEnum<{
|
|
106
|
+
"480p": "480p";
|
|
107
|
+
"720p": "720p";
|
|
108
|
+
}>;
|
|
109
|
+
type XaiVideoResolution = z.infer<typeof resolutionSchema>;
|
|
110
|
+
interface XaiVideoSharedOptions {
|
|
106
111
|
pollIntervalMs?: number | null;
|
|
107
112
|
pollTimeoutMs?: number | null;
|
|
108
|
-
resolution?:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
resolution?: XaiVideoResolution | null;
|
|
114
|
+
}
|
|
115
|
+
interface XaiVideoEditModeOptions extends XaiVideoSharedOptions {
|
|
116
|
+
/**
|
|
117
|
+
* Select edit-video mode explicitly for best autocomplete and narrowing.
|
|
118
|
+
*/
|
|
119
|
+
mode: 'edit-video';
|
|
120
|
+
/** Source video URL to edit. */
|
|
121
|
+
videoUrl: string;
|
|
122
|
+
}
|
|
123
|
+
interface XaiVideoExtendModeOptions extends XaiVideoSharedOptions {
|
|
124
|
+
/**
|
|
125
|
+
* Select extend-video mode explicitly for best autocomplete and narrowing.
|
|
126
|
+
*/
|
|
127
|
+
mode: 'extend-video';
|
|
128
|
+
/** Source video URL to extend from its last frame. */
|
|
129
|
+
videoUrl: string;
|
|
130
|
+
}
|
|
131
|
+
interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions {
|
|
132
|
+
/**
|
|
133
|
+
* Select reference-to-video mode explicitly for best autocomplete and narrowing.
|
|
134
|
+
*/
|
|
135
|
+
mode: 'reference-to-video';
|
|
136
|
+
/** Reference image URLs (1-7) for R2V generation. */
|
|
137
|
+
referenceImageUrls: string[];
|
|
138
|
+
}
|
|
139
|
+
interface XaiVideoGenerationOptions extends XaiVideoSharedOptions {
|
|
140
|
+
mode?: undefined;
|
|
141
|
+
videoUrl?: undefined;
|
|
142
|
+
referenceImageUrls?: undefined;
|
|
143
|
+
}
|
|
144
|
+
interface XaiLegacyEditVideoOptions extends XaiVideoSharedOptions {
|
|
145
|
+
/**
|
|
146
|
+
* Legacy backward-compatible shape: omitting `mode` while providing
|
|
147
|
+
* `videoUrl` behaves like edit-video.
|
|
148
|
+
*/
|
|
149
|
+
mode?: undefined;
|
|
150
|
+
videoUrl: string;
|
|
151
|
+
}
|
|
152
|
+
interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Legacy backward-compatible shape: omitting `mode` while providing
|
|
155
|
+
* `referenceImageUrls` behaves like reference-to-video.
|
|
156
|
+
*/
|
|
157
|
+
mode?: undefined;
|
|
158
|
+
referenceImageUrls: string[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Provider options for xAI video generation.
|
|
162
|
+
*
|
|
163
|
+
* Use the `mode` option to select the operation:
|
|
164
|
+
*
|
|
165
|
+
* - `'edit-video'` + `videoUrl` -- video editing (`POST /v1/videos/edits`)
|
|
166
|
+
* - `'extend-video'` + `videoUrl` -- video extension (`POST /v1/videos/extensions`)
|
|
167
|
+
* - `'reference-to-video'` + `referenceImageUrls` -- R2V generation (`POST /v1/videos/generations`)
|
|
168
|
+
* - no `mode` -- standard generation from text prompts or image input
|
|
169
|
+
*
|
|
170
|
+
* Runtime remains backward compatible with legacy auto-detected provider
|
|
171
|
+
* options, but the public TypeScript type is intentionally explicit so editors
|
|
172
|
+
* can suggest valid modes and flag invalid field combinations.
|
|
173
|
+
*/
|
|
174
|
+
type XaiVideoModelOptions = XaiVideoGenerationOptions | XaiVideoEditModeOptions | XaiVideoExtendModeOptions | XaiVideoReferenceToVideoOptions | XaiLegacyEditVideoOptions | XaiLegacyReferenceToVideoOptions;
|
|
175
|
+
|
|
176
|
+
declare const xaiFilesOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
177
|
+
[x: string]: unknown;
|
|
178
|
+
teamId?: string | undefined;
|
|
179
|
+
filePath?: string | undefined;
|
|
180
|
+
}>;
|
|
181
|
+
type XaiFilesOptions = InferSchema<typeof xaiFilesOptionsSchema>;
|
|
112
182
|
|
|
113
183
|
type XaiImageModelId = 'grok-imagine-image' | 'grok-imagine-image-pro' | (string & {});
|
|
114
184
|
|
|
@@ -341,6 +411,10 @@ interface XaiProvider extends ProviderV4 {
|
|
|
341
411
|
* Creates an Xai video model for video generation.
|
|
342
412
|
*/
|
|
343
413
|
videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
414
|
+
/**
|
|
415
|
+
* Returns the xAI files interface for uploading files.
|
|
416
|
+
*/
|
|
417
|
+
files(): FilesV4;
|
|
344
418
|
/**
|
|
345
419
|
* Server-side agentic tools for use with the responses API.
|
|
346
420
|
*/
|
|
@@ -374,4 +448,4 @@ declare const xai: XaiProvider;
|
|
|
374
448
|
|
|
375
449
|
declare const VERSION: string;
|
|
376
450
|
|
|
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 };
|
|
451
|
+
export { VERSION, type XaiErrorData, type XaiFilesOptions, 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 };
|