@ai-sdk/xai 4.0.0-beta.2 → 4.0.0-beta.21
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 +156 -8
- package/README.md +2 -0
- package/dist/index.d.mts +51 -43
- package/dist/index.d.ts +51 -43
- package/dist/index.js +110 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -50
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +30 -336
- package/package.json +4 -6
- package/src/convert-to-xai-chat-messages.ts +5 -5
- package/src/convert-xai-chat-usage.ts +2 -2
- package/src/map-xai-finish-reason.ts +2 -2
- package/src/responses/convert-to-xai-responses-input.ts +7 -5
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +2 -2
- package/src/responses/xai-responses-api.ts +3 -0
- package/src/responses/xai-responses-language-model.ts +71 -30
- package/src/responses/xai-responses-options.ts +4 -0
- package/src/responses/xai-responses-prepare-tools.ts +6 -6
- package/src/xai-chat-language-model.ts +41 -22
- package/src/xai-chat-options.ts +3 -6
- package/src/xai-image-model.ts +43 -28
- package/src/xai-image-options.ts +2 -0
- package/src/xai-image-settings.ts +0 -2
- package/src/xai-prepare-tools.ts +6 -6
- package/src/xai-provider.ts +18 -21
- package/src/xai-video-model.ts +23 -7
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
|
|
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
|
-
|
|
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');
|
|
@@ -164,7 +126,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
164
126
|
import { generateText } from 'ai';
|
|
165
127
|
|
|
166
128
|
const { text } = await generateText({
|
|
167
|
-
model: xai.responses('grok-
|
|
129
|
+
model: xai.responses('grok-3'),
|
|
168
130
|
messages: [
|
|
169
131
|
{
|
|
170
132
|
role: 'user',
|
|
@@ -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<SearchSource>_
|
|
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 |
|
|
@@ -781,9 +458,6 @@ console.log('Sources:', await result.sources);
|
|
|
781
458
|
| `grok-3-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
782
459
|
| `grok-3-mini` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
783
460
|
| `grok-3-mini-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
784
|
-
| `grok-2-vision` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
785
|
-
| `grok-2-vision-latest` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
786
|
-
| `grok-2-vision-1212` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
787
461
|
|
|
788
462
|
<Note>
|
|
789
463
|
The table above lists popular models. Please see the [xAI
|
|
@@ -800,7 +474,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
800
474
|
import { generateImage } from 'ai';
|
|
801
475
|
|
|
802
476
|
const { image } = await generateImage({
|
|
803
|
-
model: xai.image('grok-
|
|
477
|
+
model: xai.image('grok-imagine-image'),
|
|
804
478
|
prompt: 'A futuristic cityscape at sunset',
|
|
805
479
|
});
|
|
806
480
|
```
|
|
@@ -813,7 +487,7 @@ const { image } = await generateImage({
|
|
|
813
487
|
|
|
814
488
|
### Image Editing
|
|
815
489
|
|
|
816
|
-
xAI supports image editing through the `grok-
|
|
490
|
+
xAI supports image editing through the `grok-imagine-image` model. Pass input images via `prompt.images` to transform or edit existing images.
|
|
817
491
|
|
|
818
492
|
<Note>
|
|
819
493
|
xAI image editing does not support masks. Editing is prompt-driven - describe
|
|
@@ -832,7 +506,7 @@ import { readFileSync } from 'fs';
|
|
|
832
506
|
const imageBuffer = readFileSync('./input-image.png');
|
|
833
507
|
|
|
834
508
|
const { images } = await generateImage({
|
|
835
|
-
model: xai.image('grok-
|
|
509
|
+
model: xai.image('grok-imagine-image'),
|
|
836
510
|
prompt: {
|
|
837
511
|
text: 'Turn the cat into a golden retriever dog',
|
|
838
512
|
images: [imageBuffer],
|
|
@@ -840,6 +514,27 @@ const { images } = await generateImage({
|
|
|
840
514
|
});
|
|
841
515
|
```
|
|
842
516
|
|
|
517
|
+
#### Multi-Image Editing
|
|
518
|
+
|
|
519
|
+
Combine or reference multiple input images (up to 3) in the prompt:
|
|
520
|
+
|
|
521
|
+
```ts
|
|
522
|
+
import { xai } from '@ai-sdk/xai';
|
|
523
|
+
import { generateImage } from 'ai';
|
|
524
|
+
import { readFileSync } from 'fs';
|
|
525
|
+
|
|
526
|
+
const cat = readFileSync('./cat.png');
|
|
527
|
+
const dog = readFileSync('./dog.png');
|
|
528
|
+
|
|
529
|
+
const { images } = await generateImage({
|
|
530
|
+
model: xai.image('grok-imagine-image'),
|
|
531
|
+
prompt: {
|
|
532
|
+
text: 'Combine these two animals into a group photo',
|
|
533
|
+
images: [cat, dog],
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
843
538
|
#### Style Transfer
|
|
844
539
|
|
|
845
540
|
Apply artistic styles to an image:
|
|
@@ -848,7 +543,7 @@ Apply artistic styles to an image:
|
|
|
848
543
|
const imageBuffer = readFileSync('./input-image.png');
|
|
849
544
|
|
|
850
545
|
const { images } = await generateImage({
|
|
851
|
-
model: xai.image('grok-
|
|
546
|
+
model: xai.image('grok-imagine-image'),
|
|
852
547
|
prompt: {
|
|
853
548
|
text: 'Transform this into a watercolor painting style',
|
|
854
549
|
images: [imageBuffer],
|
|
@@ -859,7 +554,7 @@ const { images } = await generateImage({
|
|
|
859
554
|
|
|
860
555
|
<Note>
|
|
861
556
|
Input images can be provided as `Buffer`, `ArrayBuffer`, `Uint8Array`, or
|
|
862
|
-
base64-encoded strings.
|
|
557
|
+
base64-encoded strings. Up to 3 input images are supported per request.
|
|
863
558
|
</Note>
|
|
864
559
|
|
|
865
560
|
### Model-specific options
|
|
@@ -871,7 +566,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
871
566
|
import { generateImage } from 'ai';
|
|
872
567
|
|
|
873
568
|
const { images } = await generateImage({
|
|
874
|
-
model: xai.image('grok-
|
|
569
|
+
model: xai.image('grok-imagine-image'),
|
|
875
570
|
prompt: 'A futuristic cityscape at sunset',
|
|
876
571
|
aspectRatio: '16:9',
|
|
877
572
|
n: 2,
|
|
@@ -882,7 +577,6 @@ const { images } = await generateImage({
|
|
|
882
577
|
|
|
883
578
|
| Model | Aspect Ratios | Image Editing |
|
|
884
579
|
| -------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------- |
|
|
885
|
-
| `grok-2-image` | `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3`, `2:1`, `1:2`, `19.5:9`, `9:19.5`, `20:9`, `9:20`, `auto` | <Check size={18} /> |
|
|
886
580
|
| `grok-imagine-image` | `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3`, `2:1`, `1:2`, `19.5:9`, `9:19.5`, `20:9`, `9:20`, `auto` | <Check size={18} /> |
|
|
887
581
|
|
|
888
582
|
## Video Models
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.21",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/openai-compatible": "3.0.0-beta.
|
|
33
|
-
"@ai-sdk/provider": "4.0.0-beta.
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
32
|
+
"@ai-sdk/openai-compatible": "3.0.0-beta.13",
|
|
33
|
+
"@ai-sdk/provider": "4.0.0-beta.5",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.9"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "20.17.24",
|
|
@@ -65,9 +65,7 @@
|
|
|
65
65
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
66
66
|
"build:watch": "pnpm clean && tsup --watch",
|
|
67
67
|
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
68
|
-
"lint": "eslint \"./**/*.ts*\"",
|
|
69
68
|
"type-check": "tsc --build",
|
|
70
|
-
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
71
69
|
"test": "pnpm test:node && pnpm test:edge",
|
|
72
70
|
"test:update": "pnpm test:node -u",
|
|
73
71
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
SharedV4Warning,
|
|
3
|
+
LanguageModelV4Prompt,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertToBase64 } from '@ai-sdk/provider-utils';
|
|
7
7
|
import { XaiChatPrompt } from './xai-chat-prompt';
|
|
8
8
|
|
|
9
|
-
export function convertToXaiChatMessages(prompt:
|
|
9
|
+
export function convertToXaiChatMessages(prompt: LanguageModelV4Prompt): {
|
|
10
10
|
messages: XaiChatPrompt;
|
|
11
|
-
warnings: Array<
|
|
11
|
+
warnings: Array<SharedV4Warning>;
|
|
12
12
|
} {
|
|
13
13
|
const messages: XaiChatPrompt = [];
|
|
14
|
-
const warnings: Array<
|
|
14
|
+
const warnings: Array<SharedV4Warning> = [];
|
|
15
15
|
|
|
16
16
|
for (const { role, content } of prompt) {
|
|
17
17
|
switch (role) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
import { XaiChatUsage } from './xai-chat-language-model';
|
|
3
3
|
|
|
4
|
-
export function convertXaiChatUsage(usage: XaiChatUsage):
|
|
4
|
+
export function convertXaiChatUsage(usage: XaiChatUsage): LanguageModelV4Usage {
|
|
5
5
|
const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
6
6
|
const reasoningTokens =
|
|
7
7
|
usage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export function mapXaiFinishReason(
|
|
4
4
|
finishReason: string | null | undefined,
|
|
5
|
-
):
|
|
5
|
+
): LanguageModelV4FinishReason['unified'] {
|
|
6
6
|
switch (finishReason) {
|
|
7
7
|
case 'stop':
|
|
8
8
|
return 'stop';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
SharedV4Warning,
|
|
3
|
+
LanguageModelV4Message,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertToBase64 } from '@ai-sdk/provider-utils';
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
export async function convertToXaiResponsesInput({
|
|
13
13
|
prompt,
|
|
14
14
|
}: {
|
|
15
|
-
prompt:
|
|
15
|
+
prompt: LanguageModelV4Message[];
|
|
16
16
|
store?: boolean;
|
|
17
17
|
}): Promise<{
|
|
18
18
|
input: XaiResponsesInput;
|
|
19
|
-
inputWarnings:
|
|
19
|
+
inputWarnings: SharedV4Warning[];
|
|
20
20
|
}> {
|
|
21
21
|
const input: XaiResponsesInput = [];
|
|
22
|
-
const inputWarnings:
|
|
22
|
+
const inputWarnings: SharedV4Warning[] = [];
|
|
23
23
|
|
|
24
24
|
for (const message of prompt) {
|
|
25
25
|
switch (message.role) {
|
|
@@ -124,6 +124,8 @@ export async function convertToXaiResponsesInput({
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
case 'reasoning':
|
|
127
|
+
case 'reasoning-file':
|
|
128
|
+
case 'custom':
|
|
127
129
|
case 'file': {
|
|
128
130
|
inputWarnings.push({
|
|
129
131
|
type: 'other',
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
import { XaiResponsesUsage } from './xai-responses-api';
|
|
3
3
|
|
|
4
4
|
export function convertXaiResponsesUsage(
|
|
5
5
|
usage: XaiResponsesUsage,
|
|
6
|
-
):
|
|
6
|
+
): LanguageModelV4Usage {
|
|
7
7
|
const cacheReadTokens = usage.input_tokens_details?.cached_tokens ?? 0;
|
|
8
8
|
const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
|
|
9
9
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export function mapXaiResponsesFinishReason(
|
|
4
4
|
finishReason: string | null | undefined,
|
|
5
|
-
):
|
|
5
|
+
): LanguageModelV4FinishReason['unified'] {
|
|
6
6
|
switch (finishReason) {
|
|
7
7
|
case 'stop':
|
|
8
8
|
case 'completed':
|
|
@@ -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
|
}),
|