@ai-sdk/xai 4.0.35 → 4.0.37

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,18 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.37
4
+
5
+ ### Patch Changes
6
+
7
+ - a4d386d: feat(xai): add the Grok 4.6 model IDs and support its `xhigh` reasoning effort
8
+
9
+ ## 4.0.36
10
+
11
+ ### Patch Changes
12
+
13
+ - 8edc775: feat (provider/xai): support Grok Imagine Video 1.5. Adds the `grok-imagine-video-1.5` model id and native `1080p` for text-to-video and image-to-video (the standard `resolution: '1920x1080'` now maps to `1080p`). Reference-to-video remains capped at `720p`, so a `1080p` request in that mode is downgraded with a warning. Also fixes reference routing: previously any non-empty `inputReferences` array selected reference-to-video, so an array holding only a non-image reference sent `reference_images: []` with no usable references.
14
+ - 3d05053: feat (provider/xai): add `referenceVoiceIds` for reference-to-video reference audio. Pass up to 3 xAI preset voice ids (e.g. `['eve']`) and reference them from the prompt with `<AUDIO_0>`–`<AUDIO_2>`; they are sent as `reference_audios: [{ voice_id }]` on `POST /v1/videos/generations`.
15
+
3
16
  ## 4.0.35
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -3,13 +3,14 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { InferSchema, FetchFunction, WebSocketConstructor } from '@ai-sdk/provider-utils';
4
4
  import { ProviderV4, LanguageModelV4, ImageModelV4, Experimental_VideoModelV4, Experimental_RealtimeFactoryV4, SpeechModelV4, TranscriptionModelV4, FilesV4, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientSecretOptions, Experimental_RealtimeModelV4ClientSecretResult, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4SessionConfig } from '@ai-sdk/provider';
5
5
 
6
- type XaiChatModelId = 'grok-4.20-non-reasoning' | 'grok-4.20-reasoning' | 'grok-4.3' | 'grok-4.5' | 'grok-latest' | (string & {});
6
+ type XaiChatModelId = 'grok-4.20-non-reasoning' | 'grok-4.20-reasoning' | 'grok-4.3' | 'grok-4.5' | 'grok-4.6' | 'grok-latest' | (string & {});
7
7
  declare const xaiLanguageModelChatOptions: z.ZodObject<{
8
8
  reasoningEffort: z.ZodOptional<z.ZodEnum<{
9
9
  none: "none";
10
10
  low: "low";
11
11
  medium: "medium";
12
12
  high: "high";
13
+ xhigh: "xhigh";
13
14
  }>>;
14
15
  logprobs: z.ZodOptional<z.ZodBoolean>;
15
16
  topLogprobs: z.ZodOptional<z.ZodNumber>;
@@ -72,7 +73,7 @@ declare const xaiFilePartProviderOptions: z.ZodObject<{
72
73
  }, z.core.$strip>;
73
74
  type XaiFilePartProviderOptions = z.infer<typeof xaiFilePartProviderOptions>;
74
75
 
75
- type XaiResponsesModelId = 'grok-4.20-non-reasoning' | 'grok-4.20-reasoning' | 'grok-4.3' | 'grok-4.5' | 'grok-latest' | (string & {});
76
+ type XaiResponsesModelId = 'grok-4.20-non-reasoning' | 'grok-4.20-reasoning' | 'grok-4.3' | 'grok-4.5' | 'grok-4.6' | 'grok-latest' | (string & {});
76
77
  /**
77
78
  * @see https://docs.x.ai/docs/api-reference#create-new-response
78
79
  */
@@ -82,6 +83,7 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
82
83
  low: "low";
83
84
  medium: "medium";
84
85
  high: "high";
86
+ xhigh: "xhigh";
85
87
  }>>;
86
88
  reasoningSummary: z.ZodOptional<z.ZodEnum<{
87
89
  auto: "auto";
@@ -115,11 +117,12 @@ declare const xaiImageModelOptions: z.ZodObject<{
115
117
  }, z.core.$strip>;
116
118
  type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
117
119
 
118
- type XaiVideoModelId = 'grok-imagine-video' | (string & {});
120
+ type XaiVideoModelId = 'grok-imagine-video' | 'grok-imagine-video-1.5' | (string & {});
119
121
 
120
122
  declare const resolutionSchema: z.ZodEnum<{
121
123
  "480p": "480p";
122
124
  "720p": "720p";
125
+ "1080p": "1080p";
123
126
  }>;
124
127
  type XaiVideoResolution = z.infer<typeof resolutionSchema>;
125
128
  interface XaiVideoSharedOptions {
@@ -156,6 +159,10 @@ interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVide
156
159
  mode: 'reference-to-video';
157
160
  /** Reference image URLs (1-7) for R2V generation. */
158
161
  referenceImageUrls: string[];
162
+ /**
163
+ * Preset voice ids (up to 3) that give the subject a voice.
164
+ */
165
+ referenceVoiceIds?: string[];
159
166
  }
160
167
  interface XaiVideoGenerationOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
161
168
  mode?: undefined;
@@ -177,6 +184,10 @@ interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVid
177
184
  */
178
185
  mode?: undefined;
179
186
  referenceImageUrls: string[];
187
+ /**
188
+ * Preset voice ids (up to 3) that give the subject a voice.
189
+ */
190
+ referenceVoiceIds?: string[];
180
191
  }
181
192
  /**
182
193
  * Provider options for xAI video generation.
package/dist/index.js CHANGED
@@ -305,13 +305,14 @@ var xaiLanguageModelChatOptions = z2.object({
305
305
  * - `low` (default): Uses some reasoning tokens, but still fast.
306
306
  * - `medium`: More thinking for less-latency-sensitive applications.
307
307
  * - `high`: Uses more reasoning tokens for deeper thinking.
308
+ * - `xhigh`: Uses the most reasoning tokens (supported by `grok-4.6`).
308
309
  *
309
310
  * Note: Not every Grok model accepts every value. Refer to xAI's docs for
310
311
  * the values supported by your selected model.
311
312
  *
312
313
  * @see https://docs.x.ai/docs/guides/reasoning
313
314
  */
314
- reasoningEffort: z2.enum(["none", "low", "medium", "high"]).optional(),
315
+ reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
315
316
  logprobs: z2.boolean().optional(),
316
317
  topLogprobs: z2.number().int().min(0).max(8).optional(),
317
318
  /**
@@ -557,7 +558,7 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
557
558
  low: "low",
558
559
  medium: "medium",
559
560
  high: "high",
560
- xhigh: "high"
561
+ xhigh: this.modelId === "grok-4.6" ? "xhigh" : "high"
561
562
  },
562
563
  warnings
563
564
  });
@@ -1966,11 +1967,12 @@ var xaiLanguageModelResponsesOptions = z8.object({
1966
1967
  * Constrains how hard a reasoning model thinks before responding.
1967
1968
  * Possible values are `none` (disables reasoning entirely; supported by
1968
1969
  * `grok-4.3` and newer reasoning models), `low` (uses fewer reasoning
1969
- * tokens), `medium`, and `high` (uses more reasoning tokens).
1970
+ * tokens), `medium`, `high` (uses more reasoning tokens), and `xhigh`
1971
+ * (supported by `grok-4.6`).
1970
1972
  *
1971
1973
  * @see https://docs.x.ai/docs/guides/reasoning
1972
1974
  */
1973
- reasoningEffort: z8.enum(["none", "low", "medium", "high"]).optional(),
1975
+ reasoningEffort: z8.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
1974
1976
  reasoningSummary: z8.enum(["auto", "concise", "detailed"]).optional(),
1975
1977
  logprobs: z8.boolean().optional(),
1976
1978
  topLogprobs: z8.number().int().min(0).max(8).optional(),
@@ -2461,7 +2463,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2461
2463
  low: "low",
2462
2464
  medium: "medium",
2463
2465
  high: "high",
2464
- xhigh: "high"
2466
+ xhigh: this.modelId === "grok-4.6" ? "xhigh" : "high"
2465
2467
  },
2466
2468
  warnings
2467
2469
  });
@@ -3687,7 +3689,7 @@ var xaiTools = {
3687
3689
  };
3688
3690
 
3689
3691
  // src/version.ts
3690
- var VERSION = true ? "4.0.35" : "0.0.0-test";
3692
+ var VERSION = true ? "4.0.37" : "0.0.0-test";
3691
3693
 
3692
3694
  // src/files/xai-files.ts
3693
3695
  import {
@@ -3812,53 +3814,18 @@ import { z as z20 } from "zod/v4";
3812
3814
  import { lazySchema as lazySchema8, zodSchema as zodSchema8 } from "@ai-sdk/provider-utils";
3813
3815
  import { z as z19 } from "zod/v4";
3814
3816
  var nonEmptyStringSchema = z19.string().min(1);
3815
- var resolutionSchema = z19.enum(["480p", "720p"]);
3817
+ var resolutionSchema = z19.enum(["480p", "720p", "1080p"]);
3816
3818
  var modeSchema = z19.enum(["edit-video", "extend-video", "reference-to-video"]);
3817
3819
  var baseFields = {
3818
3820
  pollIntervalMs: z19.number().positive().nullish(),
3819
3821
  pollTimeoutMs: z19.number().positive().nullish(),
3820
3822
  resolution: resolutionSchema.nullish()
3821
3823
  };
3822
- var userField = {
3823
- user: z19.string().optional()
3824
- };
3825
- var editVideoSchema = z19.object({
3826
- ...baseFields,
3827
- ...userField,
3828
- mode: z19.literal("edit-video"),
3829
- videoUrl: nonEmptyStringSchema,
3830
- referenceImageUrls: z19.undefined().optional()
3831
- });
3832
- var extendVideoSchema = z19.object({
3833
- ...baseFields,
3834
- mode: z19.literal("extend-video"),
3835
- videoUrl: nonEmptyStringSchema,
3836
- referenceImageUrls: z19.undefined().optional()
3837
- });
3838
- var referenceToVideoSchema = z19.object({
3839
- ...baseFields,
3840
- ...userField,
3841
- mode: z19.literal("reference-to-video"),
3842
- referenceImageUrls: z19.array(nonEmptyStringSchema).min(1).max(7),
3843
- videoUrl: z19.undefined().optional()
3844
- });
3845
- var autoDetectSchema = z19.object({
3846
- ...baseFields,
3847
- ...userField,
3848
- mode: z19.undefined().optional(),
3849
- videoUrl: nonEmptyStringSchema.optional(),
3850
- referenceImageUrls: z19.array(nonEmptyStringSchema).min(1).max(7).optional()
3851
- });
3852
- var xaiVideoModelOptions = z19.union([
3853
- editVideoSchema,
3854
- extendVideoSchema,
3855
- referenceToVideoSchema,
3856
- autoDetectSchema
3857
- ]);
3858
3824
  var runtimeSchema = z19.looseObject({
3859
3825
  mode: modeSchema.optional(),
3860
3826
  videoUrl: nonEmptyStringSchema.optional(),
3861
3827
  referenceImageUrls: z19.array(nonEmptyStringSchema).min(1).max(7).optional(),
3828
+ referenceVoiceIds: z19.array(nonEmptyStringSchema).max(3).optional(),
3862
3829
  user: z19.string().optional(),
3863
3830
  ...baseFields
3864
3831
  });
@@ -3868,6 +3835,7 @@ var xaiVideoModelOptionsSchema = lazySchema8(
3868
3835
 
3869
3836
  // src/xai-video-model.ts
3870
3837
  var RESOLUTION_MAP = {
3838
+ "1920x1080": "1080p",
3871
3839
  "1280x720": "720p",
3872
3840
  "854x480": "480p",
3873
3841
  "640x480": "480p"
@@ -3885,35 +3853,39 @@ function resolveStartImage(options) {
3885
3853
  return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
3886
3854
  }
3887
3855
  var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType3(file.mediaType) === "video";
3888
- function fileToXaiImageUrl(file) {
3856
+ var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType3(file.mediaType) === "image";
3857
+ function fileToXaiUrl(file) {
3889
3858
  if (file.type === "url") {
3890
3859
  return file.url;
3891
3860
  }
3892
3861
  const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data);
3893
3862
  return `data:${file.mediaType};base64,${base64Data}`;
3894
3863
  }
3895
- function resolveReferenceImages(options, xaiOptions, warnings) {
3864
+ function resolveReferences(options, xaiOptions, warnings) {
3896
3865
  if (options.inputReferences != null && options.inputReferences.length > 0) {
3897
- const imageReferences = options.inputReferences.filter((reference) => {
3898
- if (isVideoFile(reference)) {
3866
+ const imageFiles = [];
3867
+ for (const reference of options.inputReferences) {
3868
+ if (!isImageReference(reference)) {
3899
3869
  warnings.push({
3900
3870
  type: "unsupported",
3901
3871
  feature: "inputReferences",
3902
- details: 'xAI reference-to-video accepts image references only. The video reference was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video.'
3872
+ details: isVideoFile(reference) ? 'xAI reference-to-video accepts image references only. The video reference was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video.' : "xAI reference-to-video accepts image references only. The non-image reference was ignored."
3903
3873
  });
3904
- return false;
3874
+ continue;
3905
3875
  }
3906
- return true;
3907
- });
3908
- return imageReferences.map((reference) => ({
3909
- url: fileToXaiImageUrl(reference)
3910
- }));
3876
+ imageFiles.push(reference);
3877
+ }
3878
+ return imageFiles.length > 0 ? imageFiles.map((reference) => ({ url: fileToXaiUrl(reference) })) : void 0;
3911
3879
  }
3912
3880
  if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
3913
3881
  return xaiOptions.referenceImageUrls.map((url) => ({ url }));
3914
3882
  }
3915
3883
  return void 0;
3916
3884
  }
3885
+ function hasImageInputReference(options) {
3886
+ var _a, _b;
3887
+ return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
3888
+ }
3917
3889
  function resolveVideoMode(options, xaiOptions) {
3918
3890
  if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
3919
3891
  return xaiOptions.mode;
@@ -3922,9 +3894,8 @@ function resolveVideoMode(options, xaiOptions) {
3922
3894
  return "edit-video";
3923
3895
  }
3924
3896
  const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
3925
- const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
3926
3897
  const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
3927
- if (!hasFrameImages && (hasInputReferences || hasLegacyReferenceUrls)) {
3898
+ if (!hasFrameImages && (hasImageInputReference(options) || hasLegacyReferenceUrls)) {
3928
3899
  return "reference-to-video";
3929
3900
  }
3930
3901
  return void 0;
@@ -4029,7 +4000,7 @@ var XaiVideoModel = class {
4029
4000
  warnings.push({
4030
4001
  type: "unsupported",
4031
4002
  feature: "resolution",
4032
- details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p" or "720p" instead.`
4003
+ details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p", "720p", or "1080p" instead.`
4033
4004
  });
4034
4005
  }
4035
4006
  }
@@ -4049,7 +4020,7 @@ var XaiVideoModel = class {
4049
4020
  details: 'xAI does not accept a video as a start/frame image. The video was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video instead.'
4050
4021
  });
4051
4022
  } else {
4052
- body.image = { url: fileToXaiImageUrl(startImage) };
4023
+ body.image = { url: fileToXaiUrl(startImage) };
4053
4024
  }
4054
4025
  }
4055
4026
  const lastFrameImage = getLastFrameImage(options);
@@ -4061,20 +4032,50 @@ var XaiVideoModel = class {
4061
4032
  });
4062
4033
  }
4063
4034
  if (hasReferenceImages) {
4064
- const referenceImages = resolveReferenceImages(
4065
- options,
4066
- xaiOptions,
4067
- warnings
4068
- );
4035
+ const referenceImages = resolveReferences(options, xaiOptions, warnings);
4069
4036
  if (referenceImages != null) {
4070
4037
  body.reference_images = referenceImages;
4038
+ } else {
4039
+ warnings.push({
4040
+ type: "unsupported",
4041
+ feature: "referenceImages",
4042
+ details: "xAI reference-to-video requires at least one image reference. The video will be generated without reference images."
4043
+ });
4044
+ }
4045
+ const referenceVoiceIds = xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds;
4046
+ if (referenceVoiceIds != null && referenceVoiceIds.length > 0) {
4047
+ body.reference_audios = referenceVoiceIds.map((voiceId) => ({
4048
+ voice_id: voiceId
4049
+ }));
4050
+ }
4051
+ if (body.resolution === "1080p") {
4052
+ warnings.push({
4053
+ type: "unsupported",
4054
+ feature: "resolution",
4055
+ details: "xAI reference-to-video is limited to 720p. The request was downgraded from 1080p to 720p."
4056
+ });
4057
+ body.resolution = "720p";
4071
4058
  }
4072
4059
  }
4060
+ if (body.resolution === "1080p" && this.modelId === "grok-imagine-video") {
4061
+ warnings.push({
4062
+ type: "unsupported",
4063
+ feature: "resolution",
4064
+ details: 'xAI model "grok-imagine-video" does not support 1080p. Use "grok-imagine-video-1.5" for 1080p, or a lower resolution. The request was sent with 1080p.'
4065
+ });
4066
+ }
4073
4067
  if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
4074
4068
  warnings.push({
4075
4069
  type: "unsupported",
4076
4070
  feature: "inputReferences",
4077
- details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
4071
+ details: hasImageInputReference(options) ? "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored." : "xAI reference-to-video requires at least one image reference. The references were ignored."
4072
+ });
4073
+ }
4074
+ if ((xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds) != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
4075
+ warnings.push({
4076
+ type: "unsupported",
4077
+ feature: "referenceVoiceIds",
4078
+ details: "xAI only supports reference voices for reference-to-video generation. The reference voices were ignored."
4078
4079
  });
4079
4080
  }
4080
4081
  if (!isExtension && (xaiOptions == null ? void 0 : xaiOptions.user) !== void 0) {
@@ -4089,6 +4090,7 @@ var XaiVideoModel = class {
4089
4090
  "resolution",
4090
4091
  "videoUrl",
4091
4092
  "referenceImageUrls",
4093
+ "referenceVoiceIds",
4092
4094
  "user"
4093
4095
  ].includes(key)) {
4094
4096
  body[key] = value;