@ai-sdk/xai 4.0.0-beta.5 → 4.0.0-beta.7

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
@@ -79,7 +79,7 @@ first argument is the model id, e.g. `grok-3`.
79
79
  const model = xai('grok-3');
80
80
  ```
81
81
 
82
- By default, `xai(modelId)` uses the Chat API. To use the Responses API with server-side agentic tools, explicitly use `xai.responses(modelId)`.
82
+ By default, `xai(modelId)` uses the Responses API. To use the [Chat Completions API](https://docs.x.ai/docs/api-reference#chat-completions) (legacy), use `xai.chat(modelId)`.
83
83
 
84
84
  ### Example
85
85
 
@@ -99,47 +99,9 @@ xAI language models can also be used in the `streamText` function
99
99
  and support structured data generation with [`Output`](/docs/reference/ai-sdk-core/output)
100
100
  (see [AI SDK Core](/docs/ai-sdk-core)).
101
101
 
102
- ### Provider Options
103
-
104
- xAI chat models support additional provider options that are not part of
105
- the [standard call settings](/docs/ai-sdk-core/settings). You can pass them in the `providerOptions` argument:
106
-
107
- ```ts
108
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
109
-
110
- const model = xai('grok-3-mini');
111
-
112
- await generateText({
113
- model,
114
- providerOptions: {
115
- xai: {
116
- reasoningEffort: 'high',
117
- } satisfies XaiLanguageModelChatOptions,
118
- },
119
- });
120
- ```
121
-
122
- The following optional provider options are available for xAI chat models:
123
-
124
- - **reasoningEffort** _'low' | 'high'_
125
-
126
- Reasoning effort for reasoning models.
127
-
128
- - **logprobs** _boolean_
129
-
130
- Return log probabilities for output tokens.
131
-
132
- - **topLogprobs** _number_
133
-
134
- Number of most likely tokens to return per token position (0-8). When set, `logprobs` is automatically enabled.
135
-
136
- - **parallel_function_calling** _boolean_
137
-
138
- 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`.
139
-
140
102
  ## Responses API (Agentic Tools)
141
103
 
142
- 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.
104
+ The xAI Responses API is the default when using `xai(modelId)`. You can also use `xai.responses(modelId)` explicitly. This enables the model to autonomously orchestrate tool calls and research on xAI's servers.
143
105
 
144
106
  ```ts
145
107
  const model = xai.responses('grok-4-fast-non-reasoning');
@@ -479,291 +441,6 @@ The following provider options are available:
479
441
  tools with client-side function tools in the same request.
480
442
  </Note>
481
443
 
482
- ## Live Search
483
-
484
- xAI models support Live Search functionality, allowing them to query real-time data from various sources and include it in responses with citations.
485
-
486
- ### Basic Search
487
-
488
- To enable search, specify `searchParameters` with a search mode:
489
-
490
- ```ts
491
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
492
- import { generateText } from 'ai';
493
-
494
- const { text, sources } = await generateText({
495
- model: xai('grok-3-latest'),
496
- prompt: 'What are the latest developments in AI?',
497
- providerOptions: {
498
- xai: {
499
- searchParameters: {
500
- mode: 'auto', // 'auto', 'on', or 'off'
501
- returnCitations: true,
502
- maxSearchResults: 5,
503
- },
504
- } satisfies XaiLanguageModelChatOptions,
505
- },
506
- });
507
-
508
- console.log(text);
509
- console.log('Sources:', sources);
510
- ```
511
-
512
- ### Search Parameters
513
-
514
- The following search parameters are available:
515
-
516
- - **mode** _'auto' | 'on' | 'off'_
517
-
518
- Search mode preference:
519
-
520
- - `'auto'` (default): Model decides whether to search
521
- - `'on'`: Always enables search
522
- - `'off'`: Disables search completely
523
-
524
- - **returnCitations** _boolean_
525
-
526
- Whether to return citations in the response. Defaults to `true`.
527
-
528
- - **fromDate** _string_
529
-
530
- Start date for search data in ISO8601 format (`YYYY-MM-DD`).
531
-
532
- - **toDate** _string_
533
-
534
- End date for search data in ISO8601 format (`YYYY-MM-DD`).
535
-
536
- - **maxSearchResults** _number_
537
-
538
- Maximum number of search results to consider. Defaults to 20, max 50.
539
-
540
- - **sources** _Array&lt;SearchSource&gt;_
541
-
542
- Data sources to search from. Defaults to `["web", "x"]` if not specified.
543
-
544
- ### Search Sources
545
-
546
- You can specify different types of data sources for search:
547
-
548
- #### Web Search
549
-
550
- ```ts
551
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
552
-
553
- const result = await generateText({
554
- model: xai('grok-3-latest'),
555
- prompt: 'Best ski resorts in Switzerland',
556
- providerOptions: {
557
- xai: {
558
- searchParameters: {
559
- mode: 'on',
560
- sources: [
561
- {
562
- type: 'web',
563
- country: 'CH', // ISO alpha-2 country code
564
- allowedWebsites: ['ski.com', 'snow-forecast.com'],
565
- safeSearch: true,
566
- },
567
- ],
568
- },
569
- } satisfies XaiLanguageModelChatOptions,
570
- },
571
- });
572
- ```
573
-
574
- #### Web source parameters
575
-
576
- - **country** _string_: ISO alpha-2 country code
577
- - **allowedWebsites** _string[]_: Max 5 allowed websites
578
- - **excludedWebsites** _string[]_: Max 5 excluded websites
579
- - **safeSearch** _boolean_: Enable safe search (default: true)
580
-
581
- #### X (Twitter) Search
582
-
583
- ```ts
584
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
585
-
586
- const result = await generateText({
587
- model: xai('grok-3-latest'),
588
- prompt: 'Latest updates on Grok AI',
589
- providerOptions: {
590
- xai: {
591
- searchParameters: {
592
- mode: 'on',
593
- sources: [
594
- {
595
- type: 'x',
596
- includedXHandles: ['grok', 'xai'],
597
- excludedXHandles: ['openai'],
598
- postFavoriteCount: 10,
599
- postViewCount: 100,
600
- },
601
- ],
602
- },
603
- } satisfies XaiLanguageModelChatOptions,
604
- },
605
- });
606
- ```
607
-
608
- #### X source parameters
609
-
610
- - **includedXHandles** _string[]_: Array of X handles to search (without @ symbol)
611
- - **excludedXHandles** _string[]_: Array of X handles to exclude from search (without @ symbol)
612
- - **postFavoriteCount** _number_: Minimum favorite count of the X posts to consider.
613
- - **postViewCount** _number_: Minimum view count of the X posts to consider.
614
-
615
- #### News Search
616
-
617
- ```ts
618
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
619
-
620
- const result = await generateText({
621
- model: xai('grok-3-latest'),
622
- prompt: 'Recent tech industry news',
623
- providerOptions: {
624
- xai: {
625
- searchParameters: {
626
- mode: 'on',
627
- sources: [
628
- {
629
- type: 'news',
630
- country: 'US',
631
- excludedWebsites: ['tabloid.com'],
632
- safeSearch: true,
633
- },
634
- ],
635
- },
636
- } satisfies XaiLanguageModelChatOptions,
637
- },
638
- });
639
- ```
640
-
641
- #### News source parameters
642
-
643
- - **country** _string_: ISO alpha-2 country code
644
- - **excludedWebsites** _string[]_: Max 5 excluded websites
645
- - **safeSearch** _boolean_: Enable safe search (default: true)
646
-
647
- #### RSS Feed Search
648
-
649
- ```ts
650
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
651
-
652
- const result = await generateText({
653
- model: xai('grok-3-latest'),
654
- prompt: 'Latest status updates',
655
- providerOptions: {
656
- xai: {
657
- searchParameters: {
658
- mode: 'on',
659
- sources: [
660
- {
661
- type: 'rss',
662
- links: ['https://status.x.ai/feed.xml'],
663
- },
664
- ],
665
- },
666
- } satisfies XaiLanguageModelChatOptions,
667
- },
668
- });
669
- ```
670
-
671
- #### RSS source parameters
672
-
673
- - **links** _string[]_: Array of RSS feed URLs (max 1 currently supported)
674
-
675
- ### Multiple Sources
676
-
677
- You can combine multiple data sources in a single search:
678
-
679
- ```ts
680
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
681
-
682
- const result = await generateText({
683
- model: xai('grok-3-latest'),
684
- prompt: 'Comprehensive overview of recent AI breakthroughs',
685
- providerOptions: {
686
- xai: {
687
- searchParameters: {
688
- mode: 'on',
689
- returnCitations: true,
690
- maxSearchResults: 15,
691
- sources: [
692
- {
693
- type: 'web',
694
- allowedWebsites: ['arxiv.org', 'openai.com'],
695
- },
696
- {
697
- type: 'news',
698
- country: 'US',
699
- },
700
- {
701
- type: 'x',
702
- includedXHandles: ['openai', 'deepmind'],
703
- },
704
- ],
705
- },
706
- } satisfies XaiLanguageModelChatOptions,
707
- },
708
- });
709
- ```
710
-
711
- ### Sources and Citations
712
-
713
- When search is enabled with `returnCitations: true`, the response includes sources that were used to generate the answer:
714
-
715
- ```ts
716
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
717
-
718
- const { text, sources } = await generateText({
719
- model: xai('grok-3-latest'),
720
- prompt: 'What are the latest developments in AI?',
721
- providerOptions: {
722
- xai: {
723
- searchParameters: {
724
- mode: 'auto',
725
- returnCitations: true,
726
- },
727
- } satisfies XaiLanguageModelChatOptions,
728
- },
729
- });
730
-
731
- // Access the sources used
732
- for (const source of sources) {
733
- if (source.sourceType === 'url') {
734
- console.log('Source:', source.url);
735
- }
736
- }
737
- ```
738
-
739
- ### Streaming with Search
740
-
741
- Live Search works with streaming responses. Citations are included when the stream completes:
742
-
743
- ```ts
744
- import { xai, type XaiLanguageModelChatOptions } from '@ai-sdk/xai';
745
- import { streamText } from 'ai';
746
-
747
- const result = streamText({
748
- model: xai('grok-3-latest'),
749
- prompt: 'What has happened in tech recently?',
750
- providerOptions: {
751
- xai: {
752
- searchParameters: {
753
- mode: 'auto',
754
- returnCitations: true,
755
- },
756
- } satisfies XaiLanguageModelChatOptions,
757
- },
758
- });
759
-
760
- for await (const textPart of result.textStream) {
761
- process.stdout.write(textPart);
762
- }
763
-
764
- console.log('Sources:', await result.sources);
765
- ```
766
-
767
444
  ## Model Capabilities
768
445
 
769
446
  | Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Reasoning |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/xai",
3
- "version": "4.0.0-beta.5",
3
+ "version": "4.0.0-beta.7",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -223,6 +223,9 @@ const outputItemSchema = z.discriminatedUnion('type', [
223
223
  type: z.literal('reasoning'),
224
224
  id: z.string(),
225
225
  summary: z.array(reasoningSummaryPartSchema),
226
+ content: z
227
+ .array(z.object({ type: z.string(), text: z.string() }))
228
+ .nullish(),
226
229
  status: z.string(),
227
230
  encrypted_content: z.string().nullish(),
228
231
  }),
@@ -165,8 +165,16 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
165
165
  : { type: 'json_object' },
166
166
  },
167
167
  }),
168
- ...(options.reasoningEffort != null && {
169
- reasoning: { effort: options.reasoningEffort },
168
+ ...((options.reasoningEffort != null ||
169
+ options.reasoningSummary != null) && {
170
+ reasoning: {
171
+ ...(options.reasoningEffort != null && {
172
+ effort: options.reasoningEffort,
173
+ }),
174
+ ...(options.reasoningSummary != null && {
175
+ summary: options.reasoningSummary,
176
+ }),
177
+ },
170
178
  }),
171
179
  ...(options.store === false && {
172
180
  store: options.store,
@@ -360,12 +368,16 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
360
368
  }
361
369
 
362
370
  case 'reasoning': {
363
- const summaryTexts = part.summary
364
- .map(s => s.text)
365
- .filter(text => text && text.length > 0);
371
+ const texts =
372
+ part.summary.length > 0
373
+ ? part.summary.map(s => s.text)
374
+ : (part.content ?? []).map(c => c.text);
375
+
376
+ const reasoningText = texts
377
+ .filter(text => text && text.length > 0)
378
+ .join('');
366
379
 
367
- if (summaryTexts.length > 0) {
368
- const reasoningText = summaryTexts.join('');
380
+ if (reasoningText) {
369
381
  if (part.encrypted_content || part.id) {
370
382
  content.push({
371
383
  type: 'reasoning',
@@ -17,6 +17,7 @@ export const xaiLanguageModelResponsesOptions = z.object({
17
17
  * Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
18
18
  */
19
19
  reasoningEffort: z.enum(['low', 'medium', 'high']).optional(),
20
+ reasoningSummary: z.enum(['auto', 'concise', 'detailed']).optional(),
20
21
  logprobs: z.boolean().optional(),
21
22
  topLogprobs: z.number().int().min(0).max(8).optional(),
22
23
  /**
@@ -24,15 +24,12 @@ import { XaiVideoModel } from './xai-video-model';
24
24
  import { XaiVideoModelId } from './xai-video-settings';
25
25
 
26
26
  export interface XaiProvider extends ProviderV3 {
27
- /**
28
- * Creates an Xai chat model for text generation.
29
- */
30
- (modelId: XaiChatModelId): LanguageModelV3;
27
+ (modelId: XaiResponsesModelId): LanguageModelV3;
31
28
 
32
29
  /**
33
30
  * Creates an Xai language model for text generation.
34
31
  */
35
- languageModel(modelId: XaiChatModelId): LanguageModelV3;
32
+ languageModel(modelId: XaiResponsesModelId): LanguageModelV3;
36
33
 
37
34
  /**
38
35
  * Creates an Xai chat model for text generation.
@@ -40,7 +37,7 @@ export interface XaiProvider extends ProviderV3 {
40
37
  chat: (modelId: XaiChatModelId) => LanguageModelV3;
41
38
 
42
39
  /**
43
- * Creates an Xai responses model for agentic tool calling.
40
+ * Creates an Xai responses model for text generation.
44
41
  */
45
42
  responses: (modelId: XaiResponsesModelId) => LanguageModelV3;
46
43
 
@@ -153,11 +150,11 @@ export function createXai(options: XaiProviderSettings = {}): XaiProvider {
153
150
  });
154
151
  };
155
152
 
156
- const provider = (modelId: XaiChatModelId) =>
157
- createChatLanguageModel(modelId);
153
+ const provider = (modelId: XaiResponsesModelId) =>
154
+ createResponsesLanguageModel(modelId);
158
155
 
159
156
  provider.specificationVersion = 'v3' as const;
160
- provider.languageModel = createChatLanguageModel;
157
+ provider.languageModel = createResponsesLanguageModel;
161
158
  provider.chat = createChatLanguageModel;
162
159
  provider.responses = createResponsesLanguageModel;
163
160
  provider.embeddingModel = (modelId: string) => {