@ai-sdk/xai 4.0.0-beta.2 → 4.0.0-beta.21

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.
@@ -1,9 +1,9 @@
1
1
  import {
2
- type Experimental_VideoModelV3,
3
- ImageModelV3,
4
- LanguageModelV3,
2
+ type Experimental_VideoModelV4,
3
+ ImageModelV4,
4
+ LanguageModelV4,
5
5
  NoSuchModelError,
6
- ProviderV3,
6
+ ProviderV4,
7
7
  } from '@ai-sdk/provider';
8
8
  import {
9
9
  FetchFunction,
@@ -23,46 +23,43 @@ import { VERSION } from './version';
23
23
  import { XaiVideoModel } from './xai-video-model';
24
24
  import { XaiVideoModelId } from './xai-video-settings';
25
25
 
26
- export interface XaiProvider extends ProviderV3 {
27
- /**
28
- * Creates an Xai chat model for text generation.
29
- */
30
- (modelId: XaiChatModelId): LanguageModelV3;
26
+ export interface XaiProvider extends ProviderV4 {
27
+ (modelId: XaiResponsesModelId): LanguageModelV4;
31
28
 
32
29
  /**
33
30
  * Creates an Xai language model for text generation.
34
31
  */
35
- languageModel(modelId: XaiChatModelId): LanguageModelV3;
32
+ languageModel(modelId: XaiResponsesModelId): LanguageModelV4;
36
33
 
37
34
  /**
38
35
  * Creates an Xai chat model for text generation.
39
36
  */
40
- chat: (modelId: XaiChatModelId) => LanguageModelV3;
37
+ chat: (modelId: XaiChatModelId) => LanguageModelV4;
41
38
 
42
39
  /**
43
- * Creates an Xai responses model for agentic tool calling.
40
+ * Creates an Xai responses model for text generation.
44
41
  */
45
- responses: (modelId: XaiResponsesModelId) => LanguageModelV3;
42
+ responses: (modelId: XaiResponsesModelId) => LanguageModelV4;
46
43
 
47
44
  /**
48
45
  * Creates an Xai image model for image generation.
49
46
  */
50
- image(modelId: XaiImageModelId): ImageModelV3;
47
+ image(modelId: XaiImageModelId): ImageModelV4;
51
48
 
52
49
  /**
53
50
  * Creates an Xai image model for image generation.
54
51
  */
55
- imageModel(modelId: XaiImageModelId): ImageModelV3;
52
+ imageModel(modelId: XaiImageModelId): ImageModelV4;
56
53
 
57
54
  /**
58
55
  * Creates an Xai video model for video generation.
59
56
  */
60
- video(modelId: XaiVideoModelId): Experimental_VideoModelV3;
57
+ video(modelId: XaiVideoModelId): Experimental_VideoModelV4;
61
58
 
62
59
  /**
63
60
  * Creates an Xai video model for video generation.
64
61
  */
65
- videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV3;
62
+ videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV4;
66
63
 
67
64
  /**
68
65
  * Server-side agentic tools for use with the responses API.
@@ -153,11 +150,11 @@ export function createXai(options: XaiProviderSettings = {}): XaiProvider {
153
150
  });
154
151
  };
155
152
 
156
- const provider = (modelId: XaiChatModelId) =>
157
- createChatLanguageModel(modelId);
153
+ const provider = (modelId: XaiResponsesModelId) =>
154
+ createResponsesLanguageModel(modelId);
158
155
 
159
- provider.specificationVersion = 'v3' as const;
160
- provider.languageModel = createChatLanguageModel;
156
+ provider.specificationVersion = 'v4' as const;
157
+ provider.languageModel = createResponsesLanguageModel;
161
158
  provider.chat = createChatLanguageModel;
162
159
  provider.responses = createResponsesLanguageModel;
163
160
  provider.embeddingModel = (modelId: string) => {
@@ -1,7 +1,7 @@
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,
@@ -37,8 +37,8 @@ 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
+ export class XaiVideoModel implements Experimental_VideoModelV4 {
41
+ readonly specificationVersion = 'v4';
42
42
  readonly maxVideosPerCall = 1;
43
43
 
44
44
  get provider(): string {
@@ -51,10 +51,10 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
51
51
  ) {}
52
52
 
53
53
  async doGenerate(
54
- options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
55
- ): Promise<Awaited<ReturnType<Experimental_VideoModelV3['doGenerate']>>> {
54
+ options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
55
+ ): Promise<Awaited<ReturnType<Experimental_VideoModelV4['doGenerate']>>> {
56
56
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
57
- const warnings: SharedV3Warning[] = [];
57
+ const warnings: SharedV4Warning[] = [];
58
58
 
59
59
  const xaiOptions = (await parseProviderOptions({
60
60
  provider: 'xai',
@@ -239,6 +239,14 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
239
239
  statusResponse.status === 'done' ||
240
240
  (statusResponse.status == null && statusResponse.video?.url)
241
241
  ) {
242
+ if (statusResponse.video?.respect_moderation === false) {
243
+ throw new AISDKError({
244
+ name: 'XAI_VIDEO_MODERATION_ERROR',
245
+ message:
246
+ 'Video generation was blocked due to a content policy violation.',
247
+ });
248
+ }
249
+
242
250
  if (!statusResponse.video?.url) {
243
251
  throw new AISDKError({
244
252
  name: 'XAI_VIDEO_GENERATION_ERROR',
@@ -268,6 +276,9 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
268
276
  ...(statusResponse.video.duration != null
269
277
  ? { duration: statusResponse.video.duration }
270
278
  : {}),
279
+ ...(statusResponse.usage?.cost_in_usd_ticks != null
280
+ ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks }
281
+ : {}),
271
282
  },
272
283
  },
273
284
  };
@@ -299,4 +310,9 @@ const xaiVideoStatusResponseSchema = z.object({
299
310
  })
300
311
  .nullish(),
301
312
  model: z.string().nullish(),
313
+ usage: z
314
+ .object({
315
+ cost_in_usd_ticks: z.number().nullish(),
316
+ })
317
+ .nullish(),
302
318
  });