@ai-sdk/xai 4.0.38 → 4.0.39
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 +6 -0
- package/README.md +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +16 -16
- package/package.json +3 -3
- package/src/xai-video-model.ts +19 -8
package/docs/01-xai.mdx
CHANGED
|
@@ -59,10 +59,10 @@ You can use the following optional settings to customize the xAI provider instan
|
|
|
59
59
|
## Language Models
|
|
60
60
|
|
|
61
61
|
You can create [xAI models](https://console.x.ai) using a provider instance. The
|
|
62
|
-
first argument is the model id, e.g. `grok-4.
|
|
62
|
+
first argument is the model id, e.g. `grok-4.6`.
|
|
63
63
|
|
|
64
64
|
```ts
|
|
65
|
-
const model = xai('grok-4.
|
|
65
|
+
const model = xai('grok-4.6');
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
<Note>
|
|
@@ -81,7 +81,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
81
81
|
import { generateText } from 'ai';
|
|
82
82
|
|
|
83
83
|
const { text } = await generateText({
|
|
84
|
-
model: xai('grok-4.
|
|
84
|
+
model: xai('grok-4.6'),
|
|
85
85
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
86
86
|
});
|
|
87
87
|
```
|
|
@@ -199,7 +199,7 @@ calling pattern.
|
|
|
199
199
|
The xAI Responses API is the default when using `xai(modelId)` (since AI SDK 7). You can also use `xai.responses(modelId)` explicitly. This enables the model to autonomously orchestrate tool calls and research on xAI's servers.
|
|
200
200
|
|
|
201
201
|
```ts
|
|
202
|
-
const model = xai.responses('grok-4.
|
|
202
|
+
const model = xai.responses('grok-4.6');
|
|
203
203
|
```
|
|
204
204
|
|
|
205
205
|
The Responses API provides server-side tools that the model can autonomously execute during its reasoning process:
|
|
@@ -221,7 +221,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
221
221
|
import { generateText } from 'ai';
|
|
222
222
|
|
|
223
223
|
const { text } = await generateText({
|
|
224
|
-
model: xai.responses('grok-
|
|
224
|
+
model: xai.responses('grok-4.6'),
|
|
225
225
|
messages: [
|
|
226
226
|
{
|
|
227
227
|
role: 'user',
|
|
@@ -246,7 +246,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
246
246
|
import { generateText } from 'ai';
|
|
247
247
|
|
|
248
248
|
const { text } = await generateText({
|
|
249
|
-
model: xai('grok-4.
|
|
249
|
+
model: xai('grok-4.6'),
|
|
250
250
|
messages: [
|
|
251
251
|
{
|
|
252
252
|
role: 'user',
|
|
@@ -283,7 +283,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
283
283
|
import { generateText } from 'ai';
|
|
284
284
|
|
|
285
285
|
const { text, sources } = await generateText({
|
|
286
|
-
model: xai.responses('grok-4.
|
|
286
|
+
model: xai.responses('grok-4.6'),
|
|
287
287
|
prompt: 'What are the latest developments in AI?',
|
|
288
288
|
tools: {
|
|
289
289
|
web_search: xai.tools.webSearch({
|
|
@@ -321,7 +321,7 @@ The X search tool enables searching X (Twitter) for posts, with filtering by han
|
|
|
321
321
|
|
|
322
322
|
```ts
|
|
323
323
|
const { text, sources } = await generateText({
|
|
324
|
-
model: xai.responses('grok-4.
|
|
324
|
+
model: xai.responses('grok-4.6'),
|
|
325
325
|
prompt: 'What are people saying about AI on X this week?',
|
|
326
326
|
tools: {
|
|
327
327
|
x_search: xai.tools.xSearch({
|
|
@@ -367,7 +367,7 @@ The code execution tool enables the model to write and execute Python code for c
|
|
|
367
367
|
|
|
368
368
|
```ts
|
|
369
369
|
const { text } = await generateText({
|
|
370
|
-
model: xai.responses('grok-4.
|
|
370
|
+
model: xai.responses('grok-4.6'),
|
|
371
371
|
prompt:
|
|
372
372
|
'Calculate the compound interest for $10,000 at 5% annually for 10 years',
|
|
373
373
|
tools: {
|
|
@@ -382,7 +382,7 @@ The view image tool enables the model to view and analyze images:
|
|
|
382
382
|
|
|
383
383
|
```ts
|
|
384
384
|
const { text } = await generateText({
|
|
385
|
-
model: xai.responses('grok-4.
|
|
385
|
+
model: xai.responses('grok-4.6'),
|
|
386
386
|
prompt: 'Describe what you see in the image',
|
|
387
387
|
tools: {
|
|
388
388
|
view_image: xai.tools.viewImage(),
|
|
@@ -396,7 +396,7 @@ The view X video tool enables the model to view and analyze videos from X (Twitt
|
|
|
396
396
|
|
|
397
397
|
```ts
|
|
398
398
|
const { text } = await generateText({
|
|
399
|
-
model: xai.responses('grok-4.
|
|
399
|
+
model: xai.responses('grok-4.6'),
|
|
400
400
|
prompt: 'Summarize the content of this X video',
|
|
401
401
|
tools: {
|
|
402
402
|
view_x_video: xai.tools.viewXVideo(),
|
|
@@ -413,7 +413,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
413
413
|
import { generateText } from 'ai';
|
|
414
414
|
|
|
415
415
|
const result = await generateText({
|
|
416
|
-
model: xai.responses('grok-4.
|
|
416
|
+
model: xai.responses('grok-4.6'),
|
|
417
417
|
prompt:
|
|
418
418
|
'Generate an image of a corgi surfing a big wave, in the style of a Japanese woodblock print',
|
|
419
419
|
tools: {
|
|
@@ -451,7 +451,7 @@ The MCP server tool enables the model to connect to remote [Model Context Protoc
|
|
|
451
451
|
|
|
452
452
|
```ts
|
|
453
453
|
const { text } = await generateText({
|
|
454
|
-
model: xai.responses('grok-4.
|
|
454
|
+
model: xai.responses('grok-4.6'),
|
|
455
455
|
prompt: 'Use the weather tool to check conditions in San Francisco',
|
|
456
456
|
tools: {
|
|
457
457
|
weather_server: xai.tools.mcpServer({
|
|
@@ -499,7 +499,7 @@ import { xai, type XaiLanguageModelResponsesOptions } from '@ai-sdk/xai';
|
|
|
499
499
|
import { streamText } from 'ai';
|
|
500
500
|
|
|
501
501
|
const result = streamText({
|
|
502
|
-
model: xai.responses('grok-4.
|
|
502
|
+
model: xai.responses('grok-4.6'),
|
|
503
503
|
prompt: 'What documents do you have access to?',
|
|
504
504
|
tools: {
|
|
505
505
|
file_search: xai.tools.fileSearch({
|
|
@@ -546,7 +546,7 @@ import { xai } from '@ai-sdk/xai';
|
|
|
546
546
|
import { streamText } from 'ai';
|
|
547
547
|
|
|
548
548
|
const { stream } = streamText({
|
|
549
|
-
model: xai.responses('grok-4.
|
|
549
|
+
model: xai.responses('grok-4.6'),
|
|
550
550
|
prompt: 'Research AI safety developments and calculate risk metrics',
|
|
551
551
|
tools: {
|
|
552
552
|
web_search: xai.tools.webSearch(),
|
|
@@ -580,7 +580,7 @@ import { xai, type XaiLanguageModelResponsesOptions } from '@ai-sdk/xai';
|
|
|
580
580
|
import { generateText } from 'ai';
|
|
581
581
|
|
|
582
582
|
const result = await generateText({
|
|
583
|
-
model: xai.responses('grok-4.
|
|
583
|
+
model: xai.responses('grok-4.6'),
|
|
584
584
|
providerOptions: {
|
|
585
585
|
xai: {
|
|
586
586
|
reasoningEffort: 'high',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/provider
|
|
33
|
-
"@ai-sdk/provider": "
|
|
32
|
+
"@ai-sdk/provider": "4.0.7",
|
|
33
|
+
"@ai-sdk/provider-utils": "5.0.27"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "22.19.19",
|
package/src/xai-video-model.ts
CHANGED
|
@@ -581,19 +581,30 @@ export class XaiVideoModel implements VideoModelV4 {
|
|
|
581
581
|
statusResponse.status === 'done' ||
|
|
582
582
|
(statusResponse.status == null && statusResponse.video?.url)
|
|
583
583
|
) {
|
|
584
|
+
// Terminal outcomes, so they are reported the same way as an upstream `failed`
|
|
584
585
|
if (statusResponse.video?.respect_moderation === false) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
586
|
+
return {
|
|
587
|
+
status: 'error' as const,
|
|
588
|
+
error:
|
|
588
589
|
'Video generation was blocked due to a content policy violation.',
|
|
589
|
-
|
|
590
|
+
response: {
|
|
591
|
+
timestamp: currentDate,
|
|
592
|
+
modelId: this.modelId,
|
|
593
|
+
headers: responseHeaders,
|
|
594
|
+
},
|
|
595
|
+
};
|
|
590
596
|
}
|
|
591
597
|
|
|
592
598
|
if (!statusResponse.video?.url) {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
599
|
+
return {
|
|
600
|
+
status: 'error' as const,
|
|
601
|
+
error: 'Video generation completed but no video URL was returned.',
|
|
602
|
+
response: {
|
|
603
|
+
timestamp: currentDate,
|
|
604
|
+
modelId: this.modelId,
|
|
605
|
+
headers: responseHeaders,
|
|
606
|
+
},
|
|
607
|
+
};
|
|
597
608
|
}
|
|
598
609
|
|
|
599
610
|
return {
|