@ai-sdk/xai 4.0.55 → 4.0.56
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 +8 -0
- package/dist/index.js +1 -1
- package/docs/01-xai.mdx +6 -55
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
package/docs/01-xai.mdx
CHANGED
|
@@ -625,65 +625,16 @@ The following provider options are available:
|
|
|
625
625
|
tools with client-side function tools in the same request.
|
|
626
626
|
</Note>
|
|
627
627
|
|
|
628
|
-
##
|
|
628
|
+
## Batch
|
|
629
629
|
|
|
630
630
|
<Note type="warning">
|
|
631
|
-
|
|
631
|
+
Batch support is experimental and the API may change in patch releases.
|
|
632
632
|
</Note>
|
|
633
633
|
|
|
634
|
-
The xAI provider supports asynchronous text generation through the
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
```ts
|
|
640
|
-
import { xai } from '@ai-sdk/xai';
|
|
641
|
-
import {
|
|
642
|
-
experimental_getBatchResults as getBatchResults,
|
|
643
|
-
experimental_getBatchStatus as getBatchStatus,
|
|
644
|
-
experimental_startBatch as startBatch,
|
|
645
|
-
} from 'ai';
|
|
646
|
-
import { setTimeout } from 'node:timers/promises';
|
|
647
|
-
|
|
648
|
-
const model = 'grok-4.3';
|
|
649
|
-
|
|
650
|
-
const batch = await startBatch({
|
|
651
|
-
provider: xai,
|
|
652
|
-
requests: [
|
|
653
|
-
{
|
|
654
|
-
id: 'capital-france',
|
|
655
|
-
type: 'text',
|
|
656
|
-
model,
|
|
657
|
-
prompt: 'What is the capital of France?',
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
id: 'capital-germany',
|
|
661
|
-
type: 'text',
|
|
662
|
-
model: 'grok-4.20-non-reasoning',
|
|
663
|
-
prompt: 'What is the capital of Germany?',
|
|
664
|
-
},
|
|
665
|
-
],
|
|
666
|
-
});
|
|
667
|
-
|
|
668
|
-
let status = batch.status;
|
|
669
|
-
while (status === 'pending') {
|
|
670
|
-
await setTimeout(60_000);
|
|
671
|
-
({ status } = await getBatchStatus({ provider: xai, batch }));
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
for await (const item of getBatchResults({ provider: xai, batch })) {
|
|
675
|
-
if (item.status === 'succeeded') {
|
|
676
|
-
console.log(item.id, item.text);
|
|
677
|
-
} else {
|
|
678
|
-
console.error(item.id, item.error);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
`startBatch` returns a serializable batch reference. Persist this reference
|
|
684
|
-
to check the batch status or retrieve its results from another process. Results
|
|
685
|
-
can arrive in a different order from the input requests, so match each result by
|
|
686
|
-
its `id`.
|
|
634
|
+
The xAI provider supports asynchronous text generation through the [Batch
|
|
635
|
+
API](https://docs.x.ai/developers/advanced-api-usage/batch-api). Pass the xAI
|
|
636
|
+
provider to the AI SDK's [Batch](/docs/ai-sdk-core/batch) API
|
|
637
|
+
for the complete workflow, including polling, persistence, and result handling.
|
|
687
638
|
|
|
688
639
|
Each request specifies its `type` and `model`. xAI supports using different
|
|
689
640
|
text models within the same batch.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.56",
|
|
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": "4.0.
|
|
33
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
32
|
+
"@ai-sdk/provider": "4.0.12",
|
|
33
|
+
"@ai-sdk/provider-utils": "5.0.38"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@ai-sdk/test-server": "2.0.1",
|