@ai-sdk/xai 3.0.36 → 3.0.38
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 +14 -0
- package/dist/index.d.mts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +70 -31
- package/package.json +3 -3
- package/src/xai-provider.ts +14 -14
package/docs/01-xai.mdx
CHANGED
|
@@ -118,17 +118,13 @@ await generateText({
|
|
|
118
118
|
|
|
119
119
|
The following optional provider options are available for xAI chat models:
|
|
120
120
|
|
|
121
|
-
- **reasoningEffort** _'low' | '
|
|
121
|
+
- **reasoningEffort** _'low' | 'high'_
|
|
122
122
|
|
|
123
123
|
Reasoning effort for reasoning models.
|
|
124
124
|
|
|
125
|
-
- **
|
|
125
|
+
- **parallel_function_calling** _boolean_
|
|
126
126
|
|
|
127
|
-
Whether to
|
|
128
|
-
|
|
129
|
-
- **previousResponseId** _string_
|
|
130
|
-
|
|
131
|
-
The ID of the previous response. You can use it to continue a conversation. Defaults to `undefined`.
|
|
127
|
+
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`.
|
|
132
128
|
|
|
133
129
|
## Responses API (Agentic Tools)
|
|
134
130
|
|
|
@@ -143,6 +139,8 @@ The Responses API provides server-side tools that the model can autonomously exe
|
|
|
143
139
|
- **web_search**: Real-time web search and page browsing
|
|
144
140
|
- **x_search**: Search X (Twitter) posts, users, and threads
|
|
145
141
|
- **code_execution**: Execute Python code for calculations and data analysis
|
|
142
|
+
- **view_image**: View and analyze images
|
|
143
|
+
- **view_x_video**: View and analyze videos from X posts
|
|
146
144
|
- **mcp_server**: Connect to remote MCP servers and use their tools
|
|
147
145
|
|
|
148
146
|
### Vision
|
|
@@ -265,6 +263,34 @@ const { text } = await generateText({
|
|
|
265
263
|
});
|
|
266
264
|
```
|
|
267
265
|
|
|
266
|
+
### View Image Tool
|
|
267
|
+
|
|
268
|
+
The view image tool enables the model to view and analyze images:
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
const { text } = await generateText({
|
|
272
|
+
model: xai.responses('grok-4-fast'),
|
|
273
|
+
prompt: 'Describe what you see in the image',
|
|
274
|
+
tools: {
|
|
275
|
+
view_image: xai.tools.viewImage(),
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### View X Video Tool
|
|
281
|
+
|
|
282
|
+
The view X video tool enables the model to view and analyze videos from X (Twitter) posts:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
const { text } = await generateText({
|
|
286
|
+
model: xai.responses('grok-4-fast'),
|
|
287
|
+
prompt: 'Summarize the content of this X video',
|
|
288
|
+
tools: {
|
|
289
|
+
view_x_video: xai.tools.viewXVideo(),
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
268
294
|
### MCP Server Tool
|
|
269
295
|
|
|
270
296
|
The MCP server tool enables the model to connect to remote [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers and use their tools:
|
|
@@ -290,7 +316,7 @@ const { text } = await generateText({
|
|
|
290
316
|
|
|
291
317
|
The URL of the remote MCP server.
|
|
292
318
|
|
|
293
|
-
- **serverLabel** _string_
|
|
319
|
+
- **serverLabel** _string_
|
|
294
320
|
|
|
295
321
|
A label to identify the MCP server.
|
|
296
322
|
|
|
@@ -393,10 +419,18 @@ const result = await generateText({
|
|
|
393
419
|
|
|
394
420
|
The following provider options are available:
|
|
395
421
|
|
|
396
|
-
- **reasoningEffort** _'low' | 'high'_
|
|
422
|
+
- **reasoningEffort** _'low' | 'medium' | 'high'_
|
|
397
423
|
|
|
398
424
|
Control the reasoning effort for the model. Higher effort may produce more thorough results at the cost of increased latency and token usage.
|
|
399
425
|
|
|
426
|
+
- **store** _boolean_
|
|
427
|
+
|
|
428
|
+
Whether to store the input message(s) and model response for later retrieval. Defaults to `true`.
|
|
429
|
+
|
|
430
|
+
- **previousResponseId** _string_
|
|
431
|
+
|
|
432
|
+
The ID of the previous response from the model. You can use it to continue a conversation.
|
|
433
|
+
|
|
400
434
|
<Note>
|
|
401
435
|
The Responses API only supports server-side tools. You cannot mix server-side
|
|
402
436
|
tools with client-side function tools in the same request.
|
|
@@ -676,28 +710,33 @@ console.log('Sources:', await result.sources);
|
|
|
676
710
|
|
|
677
711
|
## Model Capabilities
|
|
678
712
|
|
|
679
|
-
| Model
|
|
680
|
-
|
|
|
681
|
-
| `grok-4-
|
|
682
|
-
| `grok-4-fast-reasoning` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
683
|
-
| `grok-
|
|
684
|
-
| `grok-4`
|
|
685
|
-
| `grok-
|
|
686
|
-
| `grok-
|
|
687
|
-
| `grok-
|
|
688
|
-
| `grok-
|
|
689
|
-
| `grok-
|
|
690
|
-
| `grok-3
|
|
691
|
-
| `grok-3-
|
|
692
|
-
| `grok-3-
|
|
693
|
-
| `grok-
|
|
694
|
-
| `grok-
|
|
695
|
-
| `grok-
|
|
696
|
-
| `grok-
|
|
697
|
-
| `grok-
|
|
698
|
-
| `grok-2
|
|
699
|
-
| `grok-
|
|
700
|
-
| `grok-
|
|
713
|
+
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Reasoning |
|
|
714
|
+
| ----------------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
|
|
715
|
+
| `grok-4-1` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
716
|
+
| `grok-4-1-fast-reasoning` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
717
|
+
| `grok-4-1-fast-non-reasoning` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
718
|
+
| `grok-4-fast-non-reasoning` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
719
|
+
| `grok-4-fast-reasoning` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
720
|
+
| `grok-code-fast-1` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
721
|
+
| `grok-4` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
722
|
+
| `grok-4-0709` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
723
|
+
| `grok-4-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
724
|
+
| `grok-3` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
725
|
+
| `grok-3-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
726
|
+
| `grok-3-fast` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
727
|
+
| `grok-3-fast-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
728
|
+
| `grok-3-mini` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
729
|
+
| `grok-3-mini-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
730
|
+
| `grok-3-mini-fast` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
731
|
+
| `grok-3-mini-fast-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
732
|
+
| `grok-2` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
733
|
+
| `grok-2-latest` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
734
|
+
| `grok-2-1212` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
735
|
+
| `grok-2-vision` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
736
|
+
| `grok-2-vision-latest` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
737
|
+
| `grok-2-vision-1212` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
738
|
+
| `grok-beta` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
|
|
739
|
+
| `grok-vision-beta` | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
|
|
701
740
|
|
|
702
741
|
<Note>
|
|
703
742
|
The table above lists popular models. Please see the [xAI
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.38",
|
|
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": "2.0.
|
|
32
|
+
"@ai-sdk/openai-compatible": "2.0.21",
|
|
33
33
|
"@ai-sdk/provider": "3.0.5",
|
|
34
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
34
|
+
"@ai-sdk/provider-utils": "4.0.10"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "20.17.24",
|
package/src/xai-provider.ts
CHANGED
|
@@ -31,37 +31,37 @@ const xaiErrorStructure: ProviderErrorStructure<XaiErrorData> = {
|
|
|
31
31
|
|
|
32
32
|
export interface XaiProvider extends ProviderV3 {
|
|
33
33
|
/**
|
|
34
|
-
Creates an Xai chat model for text generation.
|
|
34
|
+
* Creates an Xai chat model for text generation.
|
|
35
35
|
*/
|
|
36
36
|
(modelId: XaiChatModelId): LanguageModelV3;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
Creates an Xai language model for text generation.
|
|
39
|
+
* Creates an Xai language model for text generation.
|
|
40
40
|
*/
|
|
41
41
|
languageModel(modelId: XaiChatModelId): LanguageModelV3;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
Creates an Xai chat model for text generation.
|
|
44
|
+
* Creates an Xai chat model for text generation.
|
|
45
45
|
*/
|
|
46
46
|
chat: (modelId: XaiChatModelId) => LanguageModelV3;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
Creates an Xai responses model for agentic tool calling.
|
|
49
|
+
* Creates an Xai responses model for agentic tool calling.
|
|
50
50
|
*/
|
|
51
51
|
responses: (modelId: XaiResponsesModelId) => LanguageModelV3;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
Creates an Xai image model for image generation.
|
|
54
|
+
* Creates an Xai image model for image generation.
|
|
55
55
|
*/
|
|
56
56
|
image(modelId: XaiImageModelId): ImageModelV3;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
Creates an Xai image model for image generation.
|
|
59
|
+
* Creates an Xai image model for image generation.
|
|
60
60
|
*/
|
|
61
61
|
imageModel(modelId: XaiImageModelId): ImageModelV3;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
Server-side agentic tools for use with the responses API.
|
|
64
|
+
* Server-side agentic tools for use with the responses API.
|
|
65
65
|
*/
|
|
66
66
|
tools: typeof xaiTools;
|
|
67
67
|
|
|
@@ -73,24 +73,24 @@ Server-side agentic tools for use with the responses API.
|
|
|
73
73
|
|
|
74
74
|
export interface XaiProviderSettings {
|
|
75
75
|
/**
|
|
76
|
-
Base URL for the xAI API calls.
|
|
77
|
-
|
|
76
|
+
* Base URL for the xAI API calls.
|
|
77
|
+
*/
|
|
78
78
|
baseURL?: string;
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
API key for authenticating requests.
|
|
81
|
+
* API key for authenticating requests.
|
|
82
82
|
*/
|
|
83
83
|
apiKey?: string;
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
Custom headers to include in the requests.
|
|
86
|
+
* Custom headers to include in the requests.
|
|
87
87
|
*/
|
|
88
88
|
headers?: Record<string, string>;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
92
|
-
or to provide a custom fetch implementation for e.g. testing.
|
|
93
|
-
|
|
91
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
92
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
93
|
+
*/
|
|
94
94
|
fetch?: FetchFunction;
|
|
95
95
|
}
|
|
96
96
|
|