@ai-sdk/xai 4.0.36 → 4.0.38

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,17 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.38
4
+
5
+ ### Patch Changes
6
+
7
+ - 484293f: feat(xai): support the priority service tier on chat and responses
8
+
9
+ ## 4.0.37
10
+
11
+ ### Patch Changes
12
+
13
+ - a4d386d: feat(xai): add the Grok 4.6 model IDs and support its `xhigh` reasoning effort
14
+
3
15
  ## 4.0.36
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -3,16 +3,21 @@ 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>;
17
+ serviceTier: z.ZodOptional<z.ZodEnum<{
18
+ default: "default";
19
+ priority: "priority";
20
+ }>>;
16
21
  parallel_function_calling: z.ZodOptional<z.ZodBoolean>;
17
22
  searchParameters: z.ZodOptional<z.ZodObject<{
18
23
  mode: z.ZodEnum<{
@@ -72,7 +77,7 @@ declare const xaiFilePartProviderOptions: z.ZodObject<{
72
77
  }, z.core.$strip>;
73
78
  type XaiFilePartProviderOptions = z.infer<typeof xaiFilePartProviderOptions>;
74
79
 
75
- type XaiResponsesModelId = 'grok-4.20-non-reasoning' | 'grok-4.20-reasoning' | 'grok-4.3' | 'grok-4.5' | 'grok-latest' | (string & {});
80
+ type XaiResponsesModelId = 'grok-4.20-non-reasoning' | 'grok-4.20-reasoning' | 'grok-4.3' | 'grok-4.5' | 'grok-4.6' | 'grok-latest' | (string & {});
76
81
  /**
77
82
  * @see https://docs.x.ai/docs/api-reference#create-new-response
78
83
  */
@@ -82,6 +87,7 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
82
87
  low: "low";
83
88
  medium: "medium";
84
89
  high: "high";
90
+ xhigh: "xhigh";
85
91
  }>>;
86
92
  reasoningSummary: z.ZodOptional<z.ZodEnum<{
87
93
  auto: "auto";
@@ -90,6 +96,10 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
90
96
  }>>;
91
97
  logprobs: z.ZodOptional<z.ZodBoolean>;
92
98
  topLogprobs: z.ZodOptional<z.ZodNumber>;
99
+ serviceTier: z.ZodOptional<z.ZodEnum<{
100
+ default: "default";
101
+ priority: "priority";
102
+ }>>;
93
103
  store: z.ZodOptional<z.ZodBoolean>;
94
104
  previousResponseId: z.ZodOptional<z.ZodString>;
95
105
  include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
package/dist/index.js CHANGED
@@ -305,15 +305,17 @@ 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(),
318
+ serviceTier: z2.enum(["default", "priority"]).optional(),
317
319
  /**
318
320
  * Whether to enable parallel function calling during tool use.
319
321
  * When true, the model can call multiple functions in parallel.
@@ -557,7 +559,7 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
557
559
  low: "low",
558
560
  medium: "medium",
559
561
  high: "high",
560
- xhigh: "high"
562
+ xhigh: this.modelId === "grok-4.6" ? "xhigh" : "high"
561
563
  },
562
564
  warnings
563
565
  });
@@ -574,6 +576,8 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
574
576
  top_p: topP,
575
577
  seed,
576
578
  reasoning_effort: reasoningEffort,
579
+ // scheduling priority
580
+ service_tier: options.serviceTier,
577
581
  // parallel function calling
578
582
  parallel_function_calling: options.parallel_function_calling,
579
583
  // response format
@@ -708,6 +712,11 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
708
712
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
709
713
  outputTokens: { total: 0, text: 0, reasoning: 0 }
710
714
  },
715
+ ...response.service_tier != null && {
716
+ providerMetadata: {
717
+ xai: { serviceTier: response.service_tier }
718
+ }
719
+ },
711
720
  request: { body },
712
721
  response: {
713
722
  ...getResponseMetadata(response),
@@ -776,6 +785,7 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
776
785
  raw: void 0
777
786
  };
778
787
  let usage = void 0;
788
+ let serviceTier = void 0;
779
789
  let isFirstChunk = true;
780
790
  const contentBlocks = {};
781
791
  const lastReasoningDeltas = {};
@@ -816,6 +826,9 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
816
826
  if (value.usage != null) {
817
827
  usage = convertXaiChatUsage(value.usage);
818
828
  }
829
+ if (value.service_tier != null) {
830
+ serviceTier = value.service_tier;
831
+ }
819
832
  const choice = value.choices[0];
820
833
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
821
834
  finishReason = {
@@ -930,6 +943,9 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
930
943
  cacheWrite: 0
931
944
  },
932
945
  outputTokens: { total: 0, text: 0, reasoning: 0 }
946
+ },
947
+ ...serviceTier != null && {
948
+ providerMetadata: { xai: { serviceTier } }
933
949
  }
934
950
  });
935
951
  }
@@ -985,6 +1001,7 @@ var xaiChatResponseSchema = z4.object({
985
1001
  object: z4.literal("chat.completion").nullish(),
986
1002
  usage: xaiUsageSchema.nullish(),
987
1003
  citations: z4.array(z4.string().url()).nullish(),
1004
+ service_tier: z4.string().nullish(),
988
1005
  code: z4.string().nullish(),
989
1006
  error: z4.string().nullish()
990
1007
  });
@@ -1014,7 +1031,8 @@ var xaiChatChunkSchema = z4.object({
1014
1031
  })
1015
1032
  ),
1016
1033
  usage: xaiUsageSchema.nullish(),
1017
- citations: z4.array(z4.string().url()).nullish()
1034
+ citations: z4.array(z4.string().url()).nullish(),
1035
+ service_tier: z4.string().nullish()
1018
1036
  });
1019
1037
  var xaiStreamErrorSchema = z4.object({
1020
1038
  code: z4.string(),
@@ -1646,7 +1664,8 @@ var xaiResponsesResponseSchema = z7.object({
1646
1664
  object: z7.literal("response"),
1647
1665
  output: z7.array(outputItemSchema),
1648
1666
  usage: xaiResponsesUsageSchema.nullish(),
1649
- status: z7.string()
1667
+ status: z7.string(),
1668
+ service_tier: z7.string().nullish()
1650
1669
  });
1651
1670
  var xaiResponsesChunkSchema = z7.union([
1652
1671
  z7.object({
@@ -1929,7 +1948,8 @@ var xaiResponsesChunkSchema = z7.union([
1929
1948
  type: z7.literal("response.incomplete"),
1930
1949
  response: z7.object({
1931
1950
  incomplete_details: z7.object({ reason: z7.string() }).nullish(),
1932
- usage: xaiResponsesUsageSchema.nullish()
1951
+ usage: xaiResponsesUsageSchema.nullish(),
1952
+ service_tier: z7.string().nullish()
1933
1953
  })
1934
1954
  }),
1935
1955
  z7.object({
@@ -1966,14 +1986,16 @@ var xaiLanguageModelResponsesOptions = z8.object({
1966
1986
  * Constrains how hard a reasoning model thinks before responding.
1967
1987
  * Possible values are `none` (disables reasoning entirely; supported by
1968
1988
  * `grok-4.3` and newer reasoning models), `low` (uses fewer reasoning
1969
- * tokens), `medium`, and `high` (uses more reasoning tokens).
1989
+ * tokens), `medium`, `high` (uses more reasoning tokens), and `xhigh`
1990
+ * (supported by `grok-4.6`).
1970
1991
  *
1971
1992
  * @see https://docs.x.ai/docs/guides/reasoning
1972
1993
  */
1973
- reasoningEffort: z8.enum(["none", "low", "medium", "high"]).optional(),
1994
+ reasoningEffort: z8.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
1974
1995
  reasoningSummary: z8.enum(["auto", "concise", "detailed"]).optional(),
1975
1996
  logprobs: z8.boolean().optional(),
1976
1997
  topLogprobs: z8.number().int().min(0).max(8).optional(),
1998
+ serviceTier: z8.enum(["default", "priority"]).optional(),
1977
1999
  /**
1978
2000
  * Whether to store the input message(s) and model response for later retrieval.
1979
2001
  * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
@@ -2461,7 +2483,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2461
2483
  low: "low",
2462
2484
  medium: "medium",
2463
2485
  high: "high",
2464
- xhigh: "high"
2486
+ xhigh: this.modelId === "grok-4.6" ? "xhigh" : "high"
2465
2487
  },
2466
2488
  warnings
2467
2489
  });
@@ -2505,6 +2527,9 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2505
2527
  },
2506
2528
  ...options.previousResponseId != null && {
2507
2529
  previous_response_id: options.previousResponseId
2530
+ },
2531
+ ...options.serviceTier != null && {
2532
+ service_tier: options.serviceTier
2508
2533
  }
2509
2534
  };
2510
2535
  if (xaiTools2 && xaiTools2.length > 0) {
@@ -2525,7 +2550,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2525
2550
  };
2526
2551
  }
2527
2552
  async doGenerate(options) {
2528
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2553
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
2529
2554
  const {
2530
2555
  args: body,
2531
2556
  warnings,
@@ -2713,10 +2738,15 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2713
2738
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
2714
2739
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2715
2740
  },
2716
- ...((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null && {
2741
+ ...(((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null || response.service_tier != null) && {
2717
2742
  providerMetadata: {
2718
2743
  xai: {
2719
- costInUsdTicks: response.usage.cost_in_usd_ticks
2744
+ ...((_r = response.usage) == null ? void 0 : _r.cost_in_usd_ticks) != null && {
2745
+ costInUsdTicks: response.usage.cost_in_usd_ticks
2746
+ },
2747
+ ...response.service_tier != null && {
2748
+ serviceTier: response.service_tier
2749
+ }
2720
2750
  }
2721
2751
  }
2722
2752
  },
@@ -2763,6 +2793,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2763
2793
  let hasFunctionCall = false;
2764
2794
  let usage = void 0;
2765
2795
  let costInUsdTicks = void 0;
2796
+ let serviceTier = void 0;
2766
2797
  let isFirstChunk = true;
2767
2798
  const contentBlocks = {};
2768
2799
  const seenToolCalls = /* @__PURE__ */ new Set();
@@ -2776,7 +2807,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2776
2807
  controller.enqueue({ type: "stream-start", warnings });
2777
2808
  },
2778
2809
  transform(chunk, controller) {
2779
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2810
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2780
2811
  if (options.includeRawChunks) {
2781
2812
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2782
2813
  }
@@ -2907,8 +2938,9 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2907
2938
  usage = convertXaiResponsesUsage(response2.usage);
2908
2939
  costInUsdTicks = (_c2 = response2.usage.cost_in_usd_ticks) != null ? _c2 : void 0;
2909
2940
  }
2941
+ serviceTier = (_d = response2.service_tier) != null ? _d : void 0;
2910
2942
  if (event.type === "response.incomplete") {
2911
- const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
2943
+ const reason = "incomplete_details" in response2 ? (_e = response2.incomplete_details) == null ? void 0 : _e.reason : void 0;
2912
2944
  finishReason = {
2913
2945
  unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2914
2946
  raw: reason != null ? reason : "incomplete"
@@ -2922,7 +2954,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2922
2954
  return;
2923
2955
  }
2924
2956
  if (event.type === "response.failed") {
2925
- const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
2957
+ const reason = (_f = event.response.incomplete_details) == null ? void 0 : _f.reason;
2926
2958
  finishReason = {
2927
2959
  unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2928
2960
  raw: reason != null ? reason : "error"
@@ -3046,13 +3078,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
3046
3078
  toolCallId: part.id,
3047
3079
  toolName,
3048
3080
  result: {
3049
- queries: (_f = part.queries) != null ? _f : [],
3050
- results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
3081
+ queries: (_g = part.queries) != null ? _g : [],
3082
+ results: (_i = (_h = part.results) == null ? void 0 : _h.map((result) => ({
3051
3083
  fileId: result.file_id,
3052
3084
  filename: result.filename,
3053
3085
  score: result.score,
3054
3086
  text: result.text
3055
- }))) != null ? _h : null
3087
+ }))) != null ? _i : null
3056
3088
  }
3057
3089
  });
3058
3090
  }
@@ -3119,17 +3151,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
3119
3151
  "x_semantic_search",
3120
3152
  "x_thread_fetch"
3121
3153
  ];
3122
- let toolName = (_i = part.name) != null ? _i : "";
3123
- if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
3154
+ let toolName = (_j = part.name) != null ? _j : "";
3155
+ if (webSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "web_search_call") {
3124
3156
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
3125
- } else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
3157
+ } else if (xSearchSubTools.includes((_l = part.name) != null ? _l : "") || part.type === "x_search_call") {
3126
3158
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
3127
3159
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
3128
3160
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
3129
3161
  } else if (part.type === "mcp_call") {
3130
- toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
3162
+ toolName = (_m = mcpToolName != null ? mcpToolName : part.name) != null ? _m : "mcp";
3131
3163
  }
3132
- 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 : "";
3164
+ const toolInput = part.type === "custom_tool_call" ? (_n = part.input) != null ? _n : "" : part.type === "mcp_call" ? (_o = part.arguments) != null ? _o : "" : (_p = part.arguments) != null ? _p : "";
3133
3165
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
3134
3166
  if (shouldEmit && !seenToolCalls.has(part.id)) {
3135
3167
  seenToolCalls.add(part.id);
@@ -3190,7 +3222,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
3190
3222
  sourceType: "url",
3191
3223
  id: self.config.generateId(),
3192
3224
  url: annotation.url,
3193
- title: (_p = annotation.title) != null ? _p : annotation.url
3225
+ title: (_q = annotation.title) != null ? _q : annotation.url
3194
3226
  });
3195
3227
  }
3196
3228
  }
@@ -3245,10 +3277,11 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
3245
3277
  },
3246
3278
  outputTokens: { total: 0, text: 0, reasoning: 0 }
3247
3279
  },
3248
- ...costInUsdTicks != null && {
3280
+ ...(costInUsdTicks != null || serviceTier != null) && {
3249
3281
  providerMetadata: {
3250
3282
  xai: {
3251
- costInUsdTicks
3283
+ ...costInUsdTicks != null && { costInUsdTicks },
3284
+ ...serviceTier != null && { serviceTier }
3252
3285
  }
3253
3286
  }
3254
3287
  }
@@ -3687,7 +3720,7 @@ var xaiTools = {
3687
3720
  };
3688
3721
 
3689
3722
  // src/version.ts
3690
- var VERSION = true ? "4.0.36" : "0.0.0-test";
3723
+ var VERSION = true ? "4.0.38" : "0.0.0-test";
3691
3724
 
3692
3725
  // src/files/xai-files.ts
3693
3726
  import {