@ai-sdk/xai 3.0.119 → 3.0.121

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/dist/index.mjs CHANGED
@@ -261,6 +261,7 @@ var xaiLanguageModelChatOptions = z2.object({
261
261
  reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
262
262
  logprobs: z2.boolean().optional(),
263
263
  topLogprobs: z2.number().int().min(0).max(8).optional(),
264
+ serviceTier: z2.enum(["default", "priority"]).optional(),
264
265
  /**
265
266
  * Whether to enable parallel function calling during tool use.
266
267
  * When true, the model can call multiple functions in parallel.
@@ -487,6 +488,8 @@ var XaiChatLanguageModel = class {
487
488
  top_p: topP,
488
489
  seed,
489
490
  reasoning_effort: options.reasoningEffort,
491
+ // scheduling priority
492
+ service_tier: options.serviceTier,
490
493
  // parallel function calling
491
494
  parallel_function_calling: options.parallel_function_calling,
492
495
  // response format
@@ -621,6 +624,11 @@ var XaiChatLanguageModel = class {
621
624
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
622
625
  outputTokens: { total: 0, text: 0, reasoning: 0 }
623
626
  },
627
+ ...response.service_tier != null && {
628
+ providerMetadata: {
629
+ xai: { serviceTier: response.service_tier }
630
+ }
631
+ },
624
632
  request: { body },
625
633
  response: {
626
634
  ...getResponseMetadata(response),
@@ -689,6 +697,7 @@ var XaiChatLanguageModel = class {
689
697
  raw: void 0
690
698
  };
691
699
  let usage = void 0;
700
+ let serviceTier = void 0;
692
701
  let isFirstChunk = true;
693
702
  const contentBlocks = {};
694
703
  const lastReasoningDeltas = {};
@@ -729,6 +738,9 @@ var XaiChatLanguageModel = class {
729
738
  if (value.usage != null) {
730
739
  usage = convertXaiChatUsage(value.usage);
731
740
  }
741
+ if (value.service_tier != null) {
742
+ serviceTier = value.service_tier;
743
+ }
732
744
  const choice = value.choices[0];
733
745
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
734
746
  finishReason = {
@@ -843,6 +855,9 @@ var XaiChatLanguageModel = class {
843
855
  cacheWrite: 0
844
856
  },
845
857
  outputTokens: { total: 0, text: 0, reasoning: 0 }
858
+ },
859
+ ...serviceTier != null && {
860
+ providerMetadata: { xai: { serviceTier } }
846
861
  }
847
862
  });
848
863
  }
@@ -898,6 +913,7 @@ var xaiChatResponseSchema = z4.object({
898
913
  object: z4.literal("chat.completion").nullish(),
899
914
  usage: xaiUsageSchema.nullish(),
900
915
  citations: z4.array(z4.string().url()).nullish(),
916
+ service_tier: z4.string().nullish(),
901
917
  code: z4.string().nullish(),
902
918
  error: z4.string().nullish()
903
919
  });
@@ -927,7 +943,8 @@ var xaiChatChunkSchema = z4.object({
927
943
  })
928
944
  ),
929
945
  usage: xaiUsageSchema.nullish(),
930
- citations: z4.array(z4.string().url()).nullish()
946
+ citations: z4.array(z4.string().url()).nullish(),
947
+ service_tier: z4.string().nullish()
931
948
  });
932
949
  var xaiStreamErrorSchema = z4.object({
933
950
  code: z4.string(),
@@ -1512,7 +1529,8 @@ var xaiResponsesResponseSchema = z7.object({
1512
1529
  object: z7.literal("response"),
1513
1530
  output: z7.array(outputItemSchema),
1514
1531
  usage: xaiResponsesUsageSchema.nullish(),
1515
- status: z7.string()
1532
+ status: z7.string(),
1533
+ service_tier: z7.string().nullish()
1516
1534
  });
1517
1535
  var xaiResponsesChunkSchema = z7.union([
1518
1536
  z7.object({
@@ -1780,7 +1798,8 @@ var xaiResponsesChunkSchema = z7.union([
1780
1798
  type: z7.literal("response.incomplete"),
1781
1799
  response: z7.object({
1782
1800
  incomplete_details: z7.object({ reason: z7.string() }).nullish(),
1783
- usage: xaiResponsesUsageSchema.nullish()
1801
+ usage: xaiResponsesUsageSchema.nullish(),
1802
+ service_tier: z7.string().nullish()
1784
1803
  })
1785
1804
  }),
1786
1805
  z7.object({
@@ -1823,6 +1842,7 @@ var xaiLanguageModelResponsesOptions = z8.object({
1823
1842
  reasoningEffort: z8.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
1824
1843
  logprobs: z8.boolean().optional(),
1825
1844
  topLogprobs: z8.number().int().min(0).max(8).optional(),
1845
+ serviceTier: z8.enum(["default", "priority"]).optional(),
1826
1846
  /**
1827
1847
  * Whether to store the input message(s) and model response for later retrieval.
1828
1848
  * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
@@ -2269,6 +2289,9 @@ var XaiResponsesLanguageModel = class {
2269
2289
  },
2270
2290
  ...options.previousResponseId != null && {
2271
2291
  previous_response_id: options.previousResponseId
2292
+ },
2293
+ ...options.serviceTier != null && {
2294
+ service_tier: options.serviceTier
2272
2295
  }
2273
2296
  };
2274
2297
  if (xaiTools2 && xaiTools2.length > 0) {
@@ -2445,6 +2468,11 @@ var XaiResponsesLanguageModel = class {
2445
2468
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
2446
2469
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2447
2470
  },
2471
+ ...response.service_tier != null && {
2472
+ providerMetadata: {
2473
+ xai: { serviceTier: response.service_tier }
2474
+ }
2475
+ },
2448
2476
  request: { body },
2449
2477
  response: {
2450
2478
  ...getResponseMetadata(response),
@@ -2486,6 +2514,7 @@ var XaiResponsesLanguageModel = class {
2486
2514
  };
2487
2515
  let hasFunctionCall = false;
2488
2516
  let usage = void 0;
2517
+ let serviceTier = void 0;
2489
2518
  let isFirstChunk = true;
2490
2519
  const contentBlocks = {};
2491
2520
  const seenToolCalls = /* @__PURE__ */ new Set();
@@ -2499,7 +2528,7 @@ var XaiResponsesLanguageModel = class {
2499
2528
  controller.enqueue({ type: "stream-start", warnings });
2500
2529
  },
2501
2530
  transform(chunk, controller) {
2502
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2531
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2503
2532
  if (options.includeRawChunks) {
2504
2533
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2505
2534
  }
@@ -2629,8 +2658,9 @@ var XaiResponsesLanguageModel = class {
2629
2658
  if (response2.usage) {
2630
2659
  usage = convertXaiResponsesUsage(response2.usage);
2631
2660
  }
2661
+ serviceTier = (_c = response2.service_tier) != null ? _c : void 0;
2632
2662
  if (event.type === "response.incomplete") {
2633
- const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2663
+ const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
2634
2664
  finishReason = {
2635
2665
  unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2636
2666
  raw: reason != null ? reason : "incomplete"
@@ -2644,7 +2674,7 @@ var XaiResponsesLanguageModel = class {
2644
2674
  return;
2645
2675
  }
2646
2676
  if (event.type === "response.failed") {
2647
- const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2677
+ const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
2648
2678
  finishReason = {
2649
2679
  unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2650
2680
  raw: reason != null ? reason : "error"
@@ -2740,13 +2770,13 @@ var XaiResponsesLanguageModel = class {
2740
2770
  toolCallId: part.id,
2741
2771
  toolName,
2742
2772
  result: {
2743
- queries: (_e = part.queries) != null ? _e : [],
2744
- results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2773
+ queries: (_f = part.queries) != null ? _f : [],
2774
+ results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
2745
2775
  fileId: result.file_id,
2746
2776
  filename: result.filename,
2747
2777
  score: result.score,
2748
2778
  text: result.text
2749
- }))) != null ? _g : null
2779
+ }))) != null ? _h : null
2750
2780
  }
2751
2781
  });
2752
2782
  }
@@ -2764,17 +2794,17 @@ var XaiResponsesLanguageModel = class {
2764
2794
  "x_semantic_search",
2765
2795
  "x_thread_fetch"
2766
2796
  ];
2767
- let toolName = (_h = part.name) != null ? _h : "";
2768
- if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2797
+ let toolName = (_i = part.name) != null ? _i : "";
2798
+ if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
2769
2799
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2770
- } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2800
+ } else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
2771
2801
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2772
2802
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2773
2803
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2774
2804
  } else if (part.type === "mcp_call") {
2775
- toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2805
+ toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
2776
2806
  }
2777
- const toolInput = part.type === "custom_tool_call" ? (_l = part.input) != null ? _l : "" : part.type === "mcp_call" ? (_m = part.arguments) != null ? _m : "" : (_n = part.arguments) != null ? _n : "";
2807
+ const toolInput = part.type === "custom_tool_call" ? (_m = part.input) != null ? _m : "" : part.type === "mcp_call" ? (_n = part.arguments) != null ? _n : "" : (_o = part.arguments) != null ? _o : "";
2778
2808
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2779
2809
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2780
2810
  seenToolCalls.add(part.id);
@@ -2835,7 +2865,7 @@ var XaiResponsesLanguageModel = class {
2835
2865
  sourceType: "url",
2836
2866
  id: self.config.generateId(),
2837
2867
  url: annotation.url,
2838
- title: (_o = annotation.title) != null ? _o : annotation.url
2868
+ title: (_p = annotation.title) != null ? _p : annotation.url
2839
2869
  });
2840
2870
  }
2841
2871
  }
@@ -2889,6 +2919,9 @@ var XaiResponsesLanguageModel = class {
2889
2919
  cacheWrite: 0
2890
2920
  },
2891
2921
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2922
+ },
2923
+ ...serviceTier != null && {
2924
+ providerMetadata: { xai: { serviceTier } }
2892
2925
  }
2893
2926
  });
2894
2927
  }
@@ -2955,7 +2988,7 @@ var xaiTools = {
2955
2988
  };
2956
2989
 
2957
2990
  // src/version.ts
2958
- var VERSION = true ? "3.0.119" : "0.0.0-test";
2991
+ var VERSION = true ? "3.0.121" : "0.0.0-test";
2959
2992
 
2960
2993
  // src/xai-video-model.ts
2961
2994
  import {
@@ -2979,7 +3012,7 @@ import { z as z17 } from "zod/v4";
2979
3012
  import { lazySchema as lazySchema5, zodSchema as zodSchema5 } from "@ai-sdk/provider-utils";
2980
3013
  import { z as z16 } from "zod/v4";
2981
3014
  var nonEmptyStringSchema = z16.string().min(1);
2982
- var resolutionSchema = z16.enum(["480p", "720p"]);
3015
+ var resolutionSchema = z16.enum(["480p", "720p", "1080p"]);
2983
3016
  var modeSchema = z16.enum(["edit-video", "extend-video", "reference-to-video"]);
2984
3017
  var baseFields = {
2985
3018
  pollIntervalMs: z16.number().positive().nullish(),
@@ -2989,22 +3022,28 @@ var baseFields = {
2989
3022
  var userField = {
2990
3023
  user: z16.string().optional()
2991
3024
  };
3025
+ var referenceVoiceIdsField = {
3026
+ referenceVoiceIds: z16.array(nonEmptyStringSchema).max(3).optional()
3027
+ };
2992
3028
  var editVideoSchema = z16.object({
2993
3029
  ...baseFields,
2994
3030
  ...userField,
2995
3031
  mode: z16.literal("edit-video"),
2996
3032
  videoUrl: nonEmptyStringSchema,
2997
- referenceImageUrls: z16.undefined().optional()
3033
+ referenceImageUrls: z16.undefined().optional(),
3034
+ referenceVoiceIds: z16.undefined().optional()
2998
3035
  });
2999
3036
  var extendVideoSchema = z16.object({
3000
3037
  ...baseFields,
3001
3038
  mode: z16.literal("extend-video"),
3002
3039
  videoUrl: nonEmptyStringSchema,
3003
- referenceImageUrls: z16.undefined().optional()
3040
+ referenceImageUrls: z16.undefined().optional(),
3041
+ referenceVoiceIds: z16.undefined().optional()
3004
3042
  });
3005
3043
  var referenceToVideoSchema = z16.object({
3006
3044
  ...baseFields,
3007
3045
  ...userField,
3046
+ ...referenceVoiceIdsField,
3008
3047
  mode: z16.literal("reference-to-video"),
3009
3048
  referenceImageUrls: z16.array(nonEmptyStringSchema).min(1).max(7),
3010
3049
  videoUrl: z16.undefined().optional()
@@ -3012,6 +3051,7 @@ var referenceToVideoSchema = z16.object({
3012
3051
  var autoDetectSchema = z16.object({
3013
3052
  ...baseFields,
3014
3053
  ...userField,
3054
+ ...referenceVoiceIdsField,
3015
3055
  mode: z16.undefined().optional(),
3016
3056
  videoUrl: nonEmptyStringSchema.optional(),
3017
3057
  referenceImageUrls: z16.array(nonEmptyStringSchema).min(1).max(7).optional()
@@ -3026,6 +3066,7 @@ var runtimeSchema = z16.object({
3026
3066
  mode: modeSchema.optional(),
3027
3067
  videoUrl: nonEmptyStringSchema.optional(),
3028
3068
  referenceImageUrls: z16.array(nonEmptyStringSchema).min(1).max(7).optional(),
3069
+ referenceVoiceIds: z16.array(nonEmptyStringSchema).max(3).optional(),
3029
3070
  user: z16.string().optional(),
3030
3071
  ...baseFields
3031
3072
  }).passthrough();
@@ -3035,6 +3076,7 @@ var xaiVideoModelOptionsSchema = lazySchema5(
3035
3076
 
3036
3077
  // src/xai-video-model.ts
3037
3078
  var RESOLUTION_MAP = {
3079
+ "1920x1080": "1080p",
3038
3080
  "1280x720": "720p",
3039
3081
  "854x480": "480p",
3040
3082
  "640x480": "480p"
@@ -3056,6 +3098,7 @@ function getTopLevelMediaType(mediaType) {
3056
3098
  return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
3057
3099
  }
3058
3100
  var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType(file.mediaType) === "video";
3101
+ var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType(file.mediaType) === "image";
3059
3102
  function fileToXaiImageUrl(file) {
3060
3103
  if (file.type === "url") {
3061
3104
  return file.url;
@@ -3065,26 +3108,29 @@ function fileToXaiImageUrl(file) {
3065
3108
  }
3066
3109
  function resolveReferenceImages(options, xaiOptions, warnings) {
3067
3110
  if (options.inputReferences != null && options.inputReferences.length > 0) {
3068
- const imageReferences = options.inputReferences.filter((reference) => {
3069
- if (isVideoFile(reference)) {
3111
+ const imageFiles = [];
3112
+ for (const reference of options.inputReferences) {
3113
+ if (!isImageReference(reference)) {
3070
3114
  warnings.push({
3071
3115
  type: "unsupported",
3072
3116
  feature: "inputReferences",
3073
- 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.'
3117
+ 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."
3074
3118
  });
3075
- return false;
3119
+ continue;
3076
3120
  }
3077
- return true;
3078
- });
3079
- return imageReferences.map((reference) => ({
3080
- url: fileToXaiImageUrl(reference)
3081
- }));
3121
+ imageFiles.push(reference);
3122
+ }
3123
+ return imageFiles.length > 0 ? imageFiles.map((reference) => ({ url: fileToXaiImageUrl(reference) })) : void 0;
3082
3124
  }
3083
3125
  if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
3084
3126
  return xaiOptions.referenceImageUrls.map((url) => ({ url }));
3085
3127
  }
3086
3128
  return void 0;
3087
3129
  }
3130
+ function hasImageInputReference(options) {
3131
+ var _a, _b;
3132
+ return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
3133
+ }
3088
3134
  function resolveVideoMode(options, xaiOptions) {
3089
3135
  if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
3090
3136
  return xaiOptions.mode;
@@ -3093,9 +3139,8 @@ function resolveVideoMode(options, xaiOptions) {
3093
3139
  return "edit-video";
3094
3140
  }
3095
3141
  const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
3096
- const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
3097
3142
  const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
3098
- if (!hasFrameImages && (hasInputReferences || hasLegacyReferenceUrls)) {
3143
+ if (!hasFrameImages && (hasImageInputReference(options) || hasLegacyReferenceUrls)) {
3099
3144
  return "reference-to-video";
3100
3145
  }
3101
3146
  return void 0;
@@ -3202,7 +3247,7 @@ var XaiVideoModel = class {
3202
3247
  warnings.push({
3203
3248
  type: "unsupported",
3204
3249
  feature: "resolution",
3205
- details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p" or "720p" instead.`
3250
+ details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p", "720p", or "1080p" instead.`
3206
3251
  });
3207
3252
  }
3208
3253
  }
@@ -3241,13 +3286,47 @@ var XaiVideoModel = class {
3241
3286
  );
3242
3287
  if (referenceImages != null) {
3243
3288
  body.reference_images = referenceImages;
3289
+ } else {
3290
+ warnings.push({
3291
+ type: "unsupported",
3292
+ feature: "referenceImages",
3293
+ details: "xAI reference-to-video requires at least one image reference. The video will be generated without reference images."
3294
+ });
3295
+ }
3296
+ const referenceVoiceIds = xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds;
3297
+ if (referenceVoiceIds != null && referenceVoiceIds.length > 0) {
3298
+ body.reference_audios = referenceVoiceIds.map((voiceId) => ({
3299
+ voice_id: voiceId
3300
+ }));
3301
+ }
3302
+ if (body.resolution === "1080p") {
3303
+ warnings.push({
3304
+ type: "unsupported",
3305
+ feature: "resolution",
3306
+ details: "xAI reference-to-video is limited to 720p. The request was downgraded from 1080p to 720p."
3307
+ });
3308
+ body.resolution = "720p";
3244
3309
  }
3245
3310
  }
3311
+ if (body.resolution === "1080p" && this.modelId === "grok-imagine-video") {
3312
+ warnings.push({
3313
+ type: "unsupported",
3314
+ feature: "resolution",
3315
+ 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.'
3316
+ });
3317
+ }
3246
3318
  if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
3247
3319
  warnings.push({
3248
3320
  type: "unsupported",
3249
3321
  feature: "inputReferences",
3250
- details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
3322
+ 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."
3323
+ });
3324
+ }
3325
+ if ((xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds) != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
3326
+ warnings.push({
3327
+ type: "unsupported",
3328
+ feature: "referenceVoiceIds",
3329
+ details: "xAI only supports reference voices for reference-to-video generation. The reference voices were ignored."
3251
3330
  });
3252
3331
  }
3253
3332
  if (!isExtension && (xaiOptions == null ? void 0 : xaiOptions.user) !== void 0) {
@@ -3262,6 +3341,7 @@ var XaiVideoModel = class {
3262
3341
  "resolution",
3263
3342
  "videoUrl",
3264
3343
  "referenceImageUrls",
3344
+ "referenceVoiceIds",
3265
3345
  "user"
3266
3346
  ].includes(key)) {
3267
3347
  body[key] = value;