@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/docs/01-xai.mdx CHANGED
@@ -73,10 +73,10 @@ You can use the following optional settings to customize the xAI provider instan
73
73
  ## Language Models
74
74
 
75
75
  You can create [xAI models](https://console.x.ai) using a provider instance. The
76
- first argument is the model id, e.g. `grok-4.5`.
76
+ first argument is the model id, e.g. `grok-4.6`.
77
77
 
78
78
  ```ts
79
- const model = xai('grok-4.5');
79
+ const model = xai('grok-4.6');
80
80
  ```
81
81
 
82
82
  By default, `xai(modelId)` uses the Chat API. To use the Responses API with server-side agentic tools, explicitly use `xai.responses(modelId)`.
@@ -90,7 +90,7 @@ import { xai } from '@ai-sdk/xai';
90
90
  import { generateText } from 'ai';
91
91
 
92
92
  const { text } = await generateText({
93
- model: xai('grok-4.5'),
93
+ model: xai('grok-4.6'),
94
94
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
95
95
  });
96
96
  ```
@@ -104,16 +104,19 @@ and support structured data generation with [`Output`](/docs/reference/ai-sdk-co
104
104
  For models with configurable reasoning, you can control how much effort the
105
105
  model spends thinking before responding with
106
106
  `providerOptions.xai.reasoningEffort`. The AI SDK option accepts `'none'`,
107
- `'low'`, `'medium'`, and `'high'`, but each xAI model supports a subset.
107
+ `'low'`, `'medium'`, `'high'`, and `'xhigh'`, but each xAI model supports a
108
+ subset.
108
109
 
109
110
  <Note>
110
- Support and defaults are model-specific. `grok-4.3` supports `'none'`,
111
- `'low'`, `'medium'`, and `'high'`. `grok-4.5` supports `'low'`, `'medium'`,
112
- and `'high'`, defaults to `'high'`, and cannot disable reasoning. The
113
- `grok-4.20-reasoning` and `grok-4.20-non-reasoning` variants do not accept
114
- this option, and neither does `grok-build-0.1`. For
115
- `grok-4.20-multi-agent`, `'low'`, `'medium'`, and `'high'` control the number
116
- of agents instead of reasoning depth. See xAI's [reasoning
111
+ Support and defaults are model-specific. `grok-4.6` supports `'low'`,
112
+ `'medium'`, `'high'`, and `'xhigh'`, defaults to `'high'`, and cannot disable
113
+ reasoning. `grok-4.3` supports `'none'`, `'low'`, `'medium'`, and `'high'`.
114
+ `grok-4.5` supports `'low'`, `'medium'`, and `'high'`, defaults to `'high'`,
115
+ and cannot disable reasoning. The `grok-4.20-reasoning` and
116
+ `grok-4.20-non-reasoning` variants do not accept this option, and neither does
117
+ `grok-build-0.1`. For `grok-4.20-multi-agent`, `'low'`, `'medium'`, and
118
+ `'high'` control the number of agents instead of reasoning depth. See xAI's
119
+ [reasoning
117
120
  docs](https://docs.x.ai/developers/model-capabilities/text/reasoning) and
118
121
  [Grok 4.3 model page](https://docs.x.ai/developers/models/grok-4.3) for
119
122
  current details.
@@ -127,7 +130,7 @@ the [standard call settings](/docs/ai-sdk-core/settings). You can pass them in t
127
130
  ```ts
128
131
  import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
129
132
 
130
- const model = xai('grok-4.5');
133
+ const model = xai('grok-4.6');
131
134
 
132
135
  await generateText({
133
136
  model,
@@ -157,12 +160,43 @@ The following optional provider options are available for xAI chat models:
157
160
 
158
161
  Whether to enable parallel function calling during tool use. When true, the model can call multiple functions in parallel. When false, the model will call functions sequentially. Defaults to `true`.
159
162
 
163
+ ### Priority Processing
164
+
165
+ `providerOptions.xai.serviceTier` requests higher scheduling priority, which
166
+ typically lowers time-to-first-token and speeds up inter-token latency. This
167
+ works for both the Responses API (default) and the Chat Completions API
168
+ (`xai.chat()`).
169
+
170
+ ```ts
171
+ import { xai } from '@ai-sdk/xai';
172
+ import { generateText } from 'ai';
173
+
174
+ const { providerMetadata } = await generateText({
175
+ model: xai('grok-4.6'),
176
+ prompt: 'Explain quantum entanglement.',
177
+ providerOptions: {
178
+ xai: { serviceTier: 'priority' },
179
+ },
180
+ });
181
+
182
+ // 'priority' when the request was served at the priority tier,
183
+ // 'default' when priority capacity was unavailable.
184
+ console.log(providerMetadata?.xai?.serviceTier);
185
+ ```
186
+
187
+ Priority requests are billed at a premium per-token rate, and xAI only charges
188
+ that rate when the response confirms the priority tier — so read the applied
189
+ tier back from `providerMetadata.xai.serviceTier` rather than assuming the
190
+ request you sent is the tier you got. Omitting the option is equivalent to
191
+ `'default'`. See xAI's [priority processing
192
+ docs](https://docs.x.ai/developers/advanced-api-usage/priority-processing).
193
+
160
194
  ## Responses API (Agentic Tools)
161
195
 
162
196
  You can use the xAI Responses API with the `xai.responses(modelId)` factory method for server-side agentic tool calling. This enables the model to autonomously orchestrate tool calls and research on xAI's servers.
163
197
 
164
198
  ```ts
165
- const model = xai.responses('grok-4.5');
199
+ const model = xai.responses('grok-4.6');
166
200
  ```
167
201
 
168
202
  The Responses API provides server-side tools that the model can autonomously execute during its reasoning process:
@@ -498,7 +532,7 @@ import { xai, type XaiLanguageModelResponsesOptions } from '@ai-sdk/xai';
498
532
  import { generateText } from 'ai';
499
533
 
500
534
  const result = await generateText({
501
- model: xai.responses('grok-4.5'),
535
+ model: xai.responses('grok-4.6'),
502
536
  providerOptions: {
503
537
  xai: {
504
538
  reasoningEffort: 'high',
@@ -510,7 +544,7 @@ const result = await generateText({
510
544
 
511
545
  The following provider options are available:
512
546
 
513
- - **reasoningEffort** _'none' | 'low' | 'medium' | 'high'_
547
+ - **reasoningEffort** _'none' | 'low' | 'medium' | 'high' | 'xhigh'_
514
548
 
515
549
  Control the reasoning effort for supported models. See [Reasoning Effort](#reasoning-effort) for model-specific values and defaults.
516
550
 
@@ -534,6 +568,10 @@ The following provider options are available:
534
568
 
535
569
  The ID of the previous response from the model. You can use it to continue a conversation.
536
570
 
571
+ - **serviceTier** _'default' | 'priority'_
572
+
573
+ Scheduling priority for the request. `'priority'` buys lower time-to-first-token and faster inter-token latency at a premium per-token price. The tier xAI actually applied comes back on `providerMetadata.xai.serviceTier`, and is `'default'` when priority capacity was unavailable. See [Priority Processing](https://docs.x.ai/developers/advanced-api-usage/priority-processing).
574
+
537
575
  <Note>
538
576
  The Responses API only supports server-side tools. You cannot mix server-side
539
577
  tools with client-side function tools in the same request.
@@ -828,6 +866,7 @@ console.log('Sources:', await result.sources);
828
866
 
829
867
  | Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Reasoning |
830
868
  | ----------------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
869
+ | `grok-4.6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
831
870
  | `grok-4.5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
832
871
  | `grok-4.20-reasoning` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
833
872
  | `grok-4.20-non-reasoning` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/xai",
3
- "version": "3.0.118",
3
+ "version": "3.0.120",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@ai-sdk/openai-compatible": "2.0.67",
33
- "@ai-sdk/provider": "3.0.15",
34
- "@ai-sdk/provider-utils": "4.0.45"
33
+ "@ai-sdk/provider-utils": "4.0.45",
34
+ "@ai-sdk/provider": "3.0.15"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "20.17.24",
@@ -274,6 +274,7 @@ export const xaiResponsesResponseSchema = z.object({
274
274
  output: z.array(outputItemSchema),
275
275
  usage: xaiResponsesUsageSchema.nullish(),
276
276
  status: z.string(),
277
+ service_tier: z.string().nullish(),
277
278
  });
278
279
 
279
280
  export const xaiResponsesChunkSchema = z.union([
@@ -543,6 +544,7 @@ export const xaiResponsesChunkSchema = z.union([
543
544
  response: z.object({
544
545
  incomplete_details: z.object({ reason: z.string() }).nullish(),
545
546
  usage: xaiResponsesUsageSchema.nullish(),
547
+ service_tier: z.string().nullish(),
546
548
  }),
547
549
  }),
548
550
  z.object({
@@ -197,6 +197,9 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
197
197
  ...(options.previousResponseId != null && {
198
198
  previous_response_id: options.previousResponseId,
199
199
  }),
200
+ ...(options.serviceTier != null && {
201
+ service_tier: options.serviceTier,
202
+ }),
200
203
  };
201
204
 
202
205
  if (xaiTools && xaiTools.length > 0) {
@@ -432,6 +435,11 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
432
435
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
433
436
  outputTokens: { total: 0, text: 0, reasoning: 0 },
434
437
  },
438
+ ...(response.service_tier != null && {
439
+ providerMetadata: {
440
+ xai: { serviceTier: response.service_tier },
441
+ },
442
+ }),
435
443
  request: { body },
436
444
  response: {
437
445
  ...getResponseMetadata(response),
@@ -477,6 +485,7 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
477
485
  };
478
486
  let hasFunctionCall = false;
479
487
  let usage: LanguageModelV3Usage | undefined = undefined;
488
+ let serviceTier: string | undefined = undefined;
480
489
  let isFirstChunk = true;
481
490
  const contentBlocks: Record<string, { type: 'text' }> = {};
482
491
  const seenToolCalls = new Set<string>();
@@ -670,6 +679,8 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
670
679
  usage = convertXaiResponsesUsage(response.usage);
671
680
  }
672
681
 
682
+ serviceTier = response.service_tier ?? undefined;
683
+
673
684
  if (event.type === 'response.incomplete') {
674
685
  const reason =
675
686
  'incomplete_details' in response
@@ -1022,6 +1033,9 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
1022
1033
  },
1023
1034
  outputTokens: { total: 0, text: 0, reasoning: 0 },
1024
1035
  },
1036
+ ...(serviceTier != null && {
1037
+ providerMetadata: { xai: { serviceTier } },
1038
+ }),
1025
1039
  });
1026
1040
  },
1027
1041
  }),
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod/v4';
2
2
 
3
3
  export type XaiResponsesModelId =
4
+ | 'grok-4.6'
4
5
  | 'grok-4.5'
5
6
  | 'grok-4.3'
6
7
  | 'grok-4.20-0309-reasoning'
@@ -16,12 +17,16 @@ export const xaiLanguageModelResponsesOptions = z.object({
16
17
  /**
17
18
  * Constrains how hard a reasoning model thinks before responding.
18
19
  * Possible values are `none` (disables reasoning), `low` (uses fewer reasoning
19
- * tokens), `medium` and `high` (uses more reasoning tokens). Not all models
20
- * support reasoning effort; see xAI's docs for the values each model accepts.
20
+ * tokens), `medium`, `high`, and `xhigh` (uses more reasoning tokens). Not all
21
+ * models support reasoning effort; see xAI's docs for the values each model
22
+ * accepts. `xhigh` is currently only supported by `grok-4.6`.
21
23
  */
22
- reasoningEffort: z.enum(['none', 'low', 'medium', 'high']).optional(),
24
+ reasoningEffort: z
25
+ .enum(['none', 'low', 'medium', 'high', 'xhigh'])
26
+ .optional(),
23
27
  logprobs: z.boolean().optional(),
24
28
  topLogprobs: z.number().int().min(0).max(8).optional(),
29
+ serviceTier: z.enum(['default', 'priority']).optional(),
25
30
  /**
26
31
  * Whether to store the input message(s) and model response for later retrieval.
27
32
  * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
@@ -135,6 +135,9 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
135
135
  seed,
136
136
  reasoning_effort: options.reasoningEffort,
137
137
 
138
+ // scheduling priority
139
+ service_tier: options.serviceTier,
140
+
138
141
  // parallel function calling
139
142
  parallel_function_calling: options.parallel_function_calling,
140
143
 
@@ -301,6 +304,11 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
301
304
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
302
305
  outputTokens: { total: 0, text: 0, reasoning: 0 },
303
306
  },
307
+ ...(response.service_tier != null && {
308
+ providerMetadata: {
309
+ xai: { serviceTier: response.service_tier },
310
+ },
311
+ }),
304
312
  request: { body },
305
313
  response: {
306
314
  ...getResponseMetadata(response),
@@ -380,6 +388,7 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
380
388
  raw: undefined,
381
389
  };
382
390
  let usage: LanguageModelV3Usage | undefined = undefined;
391
+ let serviceTier: string | undefined = undefined;
383
392
  let isFirstChunk = true;
384
393
  const contentBlocks: Record<
385
394
  string,
@@ -439,6 +448,11 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
439
448
  usage = convertXaiChatUsage(value.usage);
440
449
  }
441
450
 
451
+ // the applied tier is repeated on every chunk; keep the latest
452
+ if (value.service_tier != null) {
453
+ serviceTier = value.service_tier;
454
+ }
455
+
442
456
  const choice = value.choices[0];
443
457
 
444
458
  // update finish reason if present
@@ -598,6 +612,9 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
598
612
  },
599
613
  outputTokens: { total: 0, text: 0, reasoning: 0 },
600
614
  },
615
+ ...(serviceTier != null && {
616
+ providerMetadata: { xai: { serviceTier } },
617
+ }),
601
618
  });
602
619
  },
603
620
  }),
@@ -665,6 +682,7 @@ const xaiChatResponseSchema = z.object({
665
682
  object: z.literal('chat.completion').nullish(),
666
683
  usage: xaiUsageSchema.nullish(),
667
684
  citations: z.array(z.string().url()).nullish(),
685
+ service_tier: z.string().nullish(),
668
686
  code: z.string().nullish(),
669
687
  error: z.string().nullish(),
670
688
  });
@@ -698,6 +716,7 @@ const xaiChatChunkSchema = z.object({
698
716
  ),
699
717
  usage: xaiUsageSchema.nullish(),
700
718
  citations: z.array(z.string().url()).nullish(),
719
+ service_tier: z.string().nullish(),
701
720
  });
702
721
 
703
722
  const xaiStreamErrorSchema = z.object({
@@ -2,6 +2,7 @@ import { z } from 'zod/v4';
2
2
 
3
3
  // https://docs.x.ai/docs/models
4
4
  export type XaiChatModelId =
5
+ | 'grok-4.6'
5
6
  | 'grok-4.5'
6
7
  | 'grok-4.3'
7
8
  | 'grok-4.20-0309-reasoning'
@@ -52,10 +53,14 @@ const searchSourceSchema = z.discriminatedUnion('type', [
52
53
 
53
54
  // xai-specific provider options
54
55
  export const xaiLanguageModelChatOptions = z.object({
55
- reasoningEffort: z.enum(['none', 'low', 'medium', 'high']).optional(),
56
+ reasoningEffort: z
57
+ .enum(['none', 'low', 'medium', 'high', 'xhigh'])
58
+ .optional(),
56
59
  logprobs: z.boolean().optional(),
57
60
  topLogprobs: z.number().int().min(0).max(8).optional(),
58
61
 
62
+ serviceTier: z.enum(['default', 'priority']).optional(),
63
+
59
64
  /**
60
65
  * Whether to enable parallel function calling during tool use.
61
66
  * When true, the model can call multiple functions in parallel.