@ai-sdk/xai 3.0.118 → 3.0.120

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
+ ## 3.0.120
4
+
5
+ ### Patch Changes
6
+
7
+ - 3283e3e: feat(xai): support the priority service tier on chat and responses
8
+
9
+ ## 3.0.119
10
+
11
+ ### Patch Changes
12
+
13
+ - 451d2c3: feat(xai): Add the Grok 4.6 model IDs and support its `xhigh` reasoning effort
14
+
3
15
  ## 3.0.118
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -3,16 +3,21 @@ import { ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3 }
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
- type XaiChatModelId = 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
6
+ type XaiChatModelId = 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (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.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
80
+ type XaiResponsesModelId = 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
76
81
  /**
77
82
  * @see https://docs.x.ai/docs/api-reference#create-new-response
78
83
  */
@@ -82,9 +87,14 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
82
87
  low: "low";
83
88
  medium: "medium";
84
89
  high: "high";
90
+ xhigh: "xhigh";
85
91
  }>>;
86
92
  logprobs: z.ZodOptional<z.ZodBoolean>;
87
93
  topLogprobs: z.ZodOptional<z.ZodNumber>;
94
+ serviceTier: z.ZodOptional<z.ZodEnum<{
95
+ default: "default";
96
+ priority: "priority";
97
+ }>>;
88
98
  store: z.ZodOptional<z.ZodBoolean>;
89
99
  previousResponseId: z.ZodOptional<z.ZodString>;
90
100
  include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
package/dist/index.d.ts CHANGED
@@ -3,16 +3,21 @@ import { ProviderV3, LanguageModelV3, ImageModelV3, Experimental_VideoModelV3 }
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
- type XaiChatModelId = 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
6
+ type XaiChatModelId = 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (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.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
80
+ type XaiResponsesModelId = 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
76
81
  /**
77
82
  * @see https://docs.x.ai/docs/api-reference#create-new-response
78
83
  */
@@ -82,9 +87,14 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
82
87
  low: "low";
83
88
  medium: "medium";
84
89
  high: "high";
90
+ xhigh: "xhigh";
85
91
  }>>;
86
92
  logprobs: z.ZodOptional<z.ZodBoolean>;
87
93
  topLogprobs: z.ZodOptional<z.ZodNumber>;
94
+ serviceTier: z.ZodOptional<z.ZodEnum<{
95
+ default: "default";
96
+ priority: "priority";
97
+ }>>;
88
98
  store: z.ZodOptional<z.ZodBoolean>;
89
99
  previousResponseId: z.ZodOptional<z.ZodString>;
90
100
  include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
package/dist/index.js CHANGED
@@ -274,9 +274,10 @@ var searchSourceSchema = import_v42.z.discriminatedUnion("type", [
274
274
  rssSourceSchema
275
275
  ]);
276
276
  var xaiLanguageModelChatOptions = import_v42.z.object({
277
- reasoningEffort: import_v42.z.enum(["none", "low", "medium", "high"]).optional(),
277
+ reasoningEffort: import_v42.z.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
278
278
  logprobs: import_v42.z.boolean().optional(),
279
279
  topLogprobs: import_v42.z.number().int().min(0).max(8).optional(),
280
+ serviceTier: import_v42.z.enum(["default", "priority"]).optional(),
280
281
  /**
281
282
  * Whether to enable parallel function calling during tool use.
282
283
  * When true, the model can call multiple functions in parallel.
@@ -501,6 +502,8 @@ var XaiChatLanguageModel = class {
501
502
  top_p: topP,
502
503
  seed,
503
504
  reasoning_effort: options.reasoningEffort,
505
+ // scheduling priority
506
+ service_tier: options.serviceTier,
504
507
  // parallel function calling
505
508
  parallel_function_calling: options.parallel_function_calling,
506
509
  // response format
@@ -635,6 +638,11 @@ var XaiChatLanguageModel = class {
635
638
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
636
639
  outputTokens: { total: 0, text: 0, reasoning: 0 }
637
640
  },
641
+ ...response.service_tier != null && {
642
+ providerMetadata: {
643
+ xai: { serviceTier: response.service_tier }
644
+ }
645
+ },
638
646
  request: { body },
639
647
  response: {
640
648
  ...getResponseMetadata(response),
@@ -703,6 +711,7 @@ var XaiChatLanguageModel = class {
703
711
  raw: void 0
704
712
  };
705
713
  let usage = void 0;
714
+ let serviceTier = void 0;
706
715
  let isFirstChunk = true;
707
716
  const contentBlocks = {};
708
717
  const lastReasoningDeltas = {};
@@ -743,6 +752,9 @@ var XaiChatLanguageModel = class {
743
752
  if (value.usage != null) {
744
753
  usage = convertXaiChatUsage(value.usage);
745
754
  }
755
+ if (value.service_tier != null) {
756
+ serviceTier = value.service_tier;
757
+ }
746
758
  const choice = value.choices[0];
747
759
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
748
760
  finishReason = {
@@ -857,6 +869,9 @@ var XaiChatLanguageModel = class {
857
869
  cacheWrite: 0
858
870
  },
859
871
  outputTokens: { total: 0, text: 0, reasoning: 0 }
872
+ },
873
+ ...serviceTier != null && {
874
+ providerMetadata: { xai: { serviceTier } }
860
875
  }
861
876
  });
862
877
  }
@@ -912,6 +927,7 @@ var xaiChatResponseSchema = import_v44.z.object({
912
927
  object: import_v44.z.literal("chat.completion").nullish(),
913
928
  usage: xaiUsageSchema.nullish(),
914
929
  citations: import_v44.z.array(import_v44.z.string().url()).nullish(),
930
+ service_tier: import_v44.z.string().nullish(),
915
931
  code: import_v44.z.string().nullish(),
916
932
  error: import_v44.z.string().nullish()
917
933
  });
@@ -941,7 +957,8 @@ var xaiChatChunkSchema = import_v44.z.object({
941
957
  })
942
958
  ),
943
959
  usage: xaiUsageSchema.nullish(),
944
- citations: import_v44.z.array(import_v44.z.string().url()).nullish()
960
+ citations: import_v44.z.array(import_v44.z.string().url()).nullish(),
961
+ service_tier: import_v44.z.string().nullish()
945
962
  });
946
963
  var xaiStreamErrorSchema = import_v44.z.object({
947
964
  code: import_v44.z.string(),
@@ -1509,7 +1526,8 @@ var xaiResponsesResponseSchema = import_v47.z.object({
1509
1526
  object: import_v47.z.literal("response"),
1510
1527
  output: import_v47.z.array(outputItemSchema),
1511
1528
  usage: xaiResponsesUsageSchema.nullish(),
1512
- status: import_v47.z.string()
1529
+ status: import_v47.z.string(),
1530
+ service_tier: import_v47.z.string().nullish()
1513
1531
  });
1514
1532
  var xaiResponsesChunkSchema = import_v47.z.union([
1515
1533
  import_v47.z.object({
@@ -1777,7 +1795,8 @@ var xaiResponsesChunkSchema = import_v47.z.union([
1777
1795
  type: import_v47.z.literal("response.incomplete"),
1778
1796
  response: import_v47.z.object({
1779
1797
  incomplete_details: import_v47.z.object({ reason: import_v47.z.string() }).nullish(),
1780
- usage: xaiResponsesUsageSchema.nullish()
1798
+ usage: xaiResponsesUsageSchema.nullish(),
1799
+ service_tier: import_v47.z.string().nullish()
1781
1800
  })
1782
1801
  }),
1783
1802
  import_v47.z.object({
@@ -1813,12 +1832,14 @@ var xaiLanguageModelResponsesOptions = import_v48.z.object({
1813
1832
  /**
1814
1833
  * Constrains how hard a reasoning model thinks before responding.
1815
1834
  * Possible values are `none` (disables reasoning), `low` (uses fewer reasoning
1816
- * tokens), `medium` and `high` (uses more reasoning tokens). Not all models
1817
- * support reasoning effort; see xAI's docs for the values each model accepts.
1835
+ * tokens), `medium`, `high`, and `xhigh` (uses more reasoning tokens). Not all
1836
+ * models support reasoning effort; see xAI's docs for the values each model
1837
+ * accepts. `xhigh` is currently only supported by `grok-4.6`.
1818
1838
  */
1819
- reasoningEffort: import_v48.z.enum(["none", "low", "medium", "high"]).optional(),
1839
+ reasoningEffort: import_v48.z.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
1820
1840
  logprobs: import_v48.z.boolean().optional(),
1821
1841
  topLogprobs: import_v48.z.number().int().min(0).max(8).optional(),
1842
+ serviceTier: import_v48.z.enum(["default", "priority"]).optional(),
1822
1843
  /**
1823
1844
  * Whether to store the input message(s) and model response for later retrieval.
1824
1845
  * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
@@ -2247,6 +2268,9 @@ var XaiResponsesLanguageModel = class {
2247
2268
  },
2248
2269
  ...options.previousResponseId != null && {
2249
2270
  previous_response_id: options.previousResponseId
2271
+ },
2272
+ ...options.serviceTier != null && {
2273
+ service_tier: options.serviceTier
2250
2274
  }
2251
2275
  };
2252
2276
  if (xaiTools2 && xaiTools2.length > 0) {
@@ -2423,6 +2447,11 @@ var XaiResponsesLanguageModel = class {
2423
2447
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
2424
2448
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2425
2449
  },
2450
+ ...response.service_tier != null && {
2451
+ providerMetadata: {
2452
+ xai: { serviceTier: response.service_tier }
2453
+ }
2454
+ },
2426
2455
  request: { body },
2427
2456
  response: {
2428
2457
  ...getResponseMetadata(response),
@@ -2464,6 +2493,7 @@ var XaiResponsesLanguageModel = class {
2464
2493
  };
2465
2494
  let hasFunctionCall = false;
2466
2495
  let usage = void 0;
2496
+ let serviceTier = void 0;
2467
2497
  let isFirstChunk = true;
2468
2498
  const contentBlocks = {};
2469
2499
  const seenToolCalls = /* @__PURE__ */ new Set();
@@ -2477,7 +2507,7 @@ var XaiResponsesLanguageModel = class {
2477
2507
  controller.enqueue({ type: "stream-start", warnings });
2478
2508
  },
2479
2509
  transform(chunk, controller) {
2480
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2510
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2481
2511
  if (options.includeRawChunks) {
2482
2512
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2483
2513
  }
@@ -2607,8 +2637,9 @@ var XaiResponsesLanguageModel = class {
2607
2637
  if (response2.usage) {
2608
2638
  usage = convertXaiResponsesUsage(response2.usage);
2609
2639
  }
2640
+ serviceTier = (_c = response2.service_tier) != null ? _c : void 0;
2610
2641
  if (event.type === "response.incomplete") {
2611
- const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2642
+ const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
2612
2643
  finishReason = {
2613
2644
  unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2614
2645
  raw: reason != null ? reason : "incomplete"
@@ -2622,7 +2653,7 @@ var XaiResponsesLanguageModel = class {
2622
2653
  return;
2623
2654
  }
2624
2655
  if (event.type === "response.failed") {
2625
- const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2656
+ const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
2626
2657
  finishReason = {
2627
2658
  unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2628
2659
  raw: reason != null ? reason : "error"
@@ -2718,13 +2749,13 @@ var XaiResponsesLanguageModel = class {
2718
2749
  toolCallId: part.id,
2719
2750
  toolName,
2720
2751
  result: {
2721
- queries: (_e = part.queries) != null ? _e : [],
2722
- results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2752
+ queries: (_f = part.queries) != null ? _f : [],
2753
+ results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
2723
2754
  fileId: result.file_id,
2724
2755
  filename: result.filename,
2725
2756
  score: result.score,
2726
2757
  text: result.text
2727
- }))) != null ? _g : null
2758
+ }))) != null ? _h : null
2728
2759
  }
2729
2760
  });
2730
2761
  }
@@ -2742,17 +2773,17 @@ var XaiResponsesLanguageModel = class {
2742
2773
  "x_semantic_search",
2743
2774
  "x_thread_fetch"
2744
2775
  ];
2745
- let toolName = (_h = part.name) != null ? _h : "";
2746
- if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2776
+ let toolName = (_i = part.name) != null ? _i : "";
2777
+ if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
2747
2778
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2748
- } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2779
+ } else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
2749
2780
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2750
2781
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2751
2782
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2752
2783
  } else if (part.type === "mcp_call") {
2753
- toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2784
+ toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
2754
2785
  }
2755
- 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 : "";
2786
+ 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 : "";
2756
2787
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2757
2788
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2758
2789
  seenToolCalls.add(part.id);
@@ -2813,7 +2844,7 @@ var XaiResponsesLanguageModel = class {
2813
2844
  sourceType: "url",
2814
2845
  id: self.config.generateId(),
2815
2846
  url: annotation.url,
2816
- title: (_o = annotation.title) != null ? _o : annotation.url
2847
+ title: (_p = annotation.title) != null ? _p : annotation.url
2817
2848
  });
2818
2849
  }
2819
2850
  }
@@ -2867,6 +2898,9 @@ var XaiResponsesLanguageModel = class {
2867
2898
  cacheWrite: 0
2868
2899
  },
2869
2900
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2901
+ },
2902
+ ...serviceTier != null && {
2903
+ providerMetadata: { xai: { serviceTier } }
2870
2904
  }
2871
2905
  });
2872
2906
  }
@@ -2933,7 +2967,7 @@ var xaiTools = {
2933
2967
  };
2934
2968
 
2935
2969
  // src/version.ts
2936
- var VERSION = true ? "3.0.118" : "0.0.0-test";
2970
+ var VERSION = true ? "3.0.120" : "0.0.0-test";
2937
2971
 
2938
2972
  // src/xai-video-model.ts
2939
2973
  var import_provider6 = require("@ai-sdk/provider");