@ai-sdk/xai 3.0.119 → 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
@@ -160,6 +160,37 @@ The following optional provider options are available for xAI chat models:
160
160
 
161
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`.
162
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
+
163
194
  ## Responses API (Agentic Tools)
164
195
 
165
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.
@@ -537,6 +568,10 @@ The following provider options are available:
537
568
 
538
569
  The ID of the previous response from the model. You can use it to continue a conversation.
539
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
+
540
575
  <Note>
541
576
  The Responses API only supports server-side tools. You cannot mix server-side
542
577
  tools with client-side function tools in the same request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/xai",
3
- "version": "3.0.119",
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
  }),
@@ -26,6 +26,7 @@ export const xaiLanguageModelResponsesOptions = z.object({
26
26
  .optional(),
27
27
  logprobs: z.boolean().optional(),
28
28
  topLogprobs: z.number().int().min(0).max(8).optional(),
29
+ serviceTier: z.enum(['default', 'priority']).optional(),
29
30
  /**
30
31
  * Whether to store the input message(s) and model response for later retrieval.
31
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({
@@ -59,6 +59,8 @@ export const xaiLanguageModelChatOptions = z.object({
59
59
  logprobs: z.boolean().optional(),
60
60
  topLogprobs: z.number().int().min(0).max(8).optional(),
61
61
 
62
+ serviceTier: z.enum(['default', 'priority']).optional(),
63
+
62
64
  /**
63
65
  * Whether to enable parallel function calling during tool use.
64
66
  * When true, the model can call multiple functions in parallel.