@ai-sdk/xai 4.0.0-beta.8 → 4.0.0-canary.50

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +395 -8
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +129 -55
  4. package/dist/index.js +1230 -763
  5. package/dist/index.js.map +1 -1
  6. package/docs/01-xai.mdx +167 -48
  7. package/package.json +12 -12
  8. package/src/convert-to-xai-chat-messages.ts +45 -24
  9. package/src/convert-xai-chat-usage.ts +2 -2
  10. package/src/files/xai-files-api.ts +16 -0
  11. package/src/files/xai-files-options.ts +19 -0
  12. package/src/files/xai-files.ts +94 -0
  13. package/src/index.ts +5 -4
  14. package/src/map-xai-finish-reason.ts +1 -1
  15. package/src/responses/convert-to-xai-responses-input.ts +97 -20
  16. package/src/responses/convert-xai-responses-usage.ts +2 -2
  17. package/src/responses/map-xai-responses-finish-reason.ts +2 -1
  18. package/src/responses/xai-responses-api.ts +30 -1
  19. package/src/responses/{xai-responses-options.ts → xai-responses-language-model-options.ts} +5 -0
  20. package/src/responses/xai-responses-language-model.ts +125 -30
  21. package/src/responses/xai-responses-prepare-tools.ts +3 -3
  22. package/src/tool/code-execution.ts +2 -2
  23. package/src/tool/file-search.ts +2 -2
  24. package/src/tool/mcp-server.ts +2 -2
  25. package/src/tool/view-image.ts +2 -2
  26. package/src/tool/view-x-video.ts +2 -2
  27. package/src/tool/web-search.ts +2 -2
  28. package/src/tool/x-search.ts +2 -2
  29. package/src/{xai-chat-options.ts → xai-chat-language-model-options.ts} +3 -0
  30. package/src/xai-chat-language-model.ts +53 -17
  31. package/src/xai-chat-prompt.ts +2 -1
  32. package/src/xai-image-model.ts +23 -6
  33. package/src/xai-prepare-tools.ts +3 -3
  34. package/src/xai-provider.ts +25 -9
  35. package/src/xai-video-model-options.ts +145 -0
  36. package/src/xai-video-model.ts +122 -15
  37. package/dist/index.d.mts +0 -377
  38. package/dist/index.mjs +0 -3070
  39. package/dist/index.mjs.map +0 -1
  40. package/src/xai-video-options.ts +0 -23
  41. /package/src/{xai-image-options.ts → xai-image-model-options.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,392 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.0-canary.50
4
+
5
+ ### Patch Changes
6
+
7
+ - 0c4c275: trigger initial canary release
8
+ - Updated dependencies [0c4c275]
9
+ - @ai-sdk/openai-compatible@3.0.0-canary.37
10
+ - @ai-sdk/provider-utils@5.0.0-canary.31
11
+ - @ai-sdk/provider@4.0.0-canary.15
12
+
13
+ ## 4.0.0-beta.49
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [e59c955]
18
+ - @ai-sdk/openai-compatible@3.0.0-beta.36
19
+
20
+ ## 4.0.0-beta.48
21
+
22
+ ### Major Changes
23
+
24
+ - 04e9009: chore: make provider implementations code patterns more consistent, including renaming certain exported symbols
25
+
26
+ For all externally exported symbols that were renamed, the old names continue to work via deprecated aliases.
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [08d2129]
31
+ - Updated dependencies [04e9009]
32
+ - @ai-sdk/provider-utils@5.0.0-beta.30
33
+ - @ai-sdk/openai-compatible@3.0.0-beta.35
34
+
35
+ ## 4.0.0-beta.47
36
+
37
+ ### Patch Changes
38
+
39
+ - 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
40
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
41
+ - Updated dependencies [9bd6512]
42
+ - Updated dependencies [258c093]
43
+ - Updated dependencies [b6783da]
44
+ - @ai-sdk/openai-compatible@3.0.0-beta.34
45
+ - @ai-sdk/provider-utils@5.0.0-beta.29
46
+ - @ai-sdk/provider@4.0.0-beta.14
47
+
48
+ ## 4.0.0-beta.46
49
+
50
+ ### Patch Changes
51
+
52
+ - 78b6433: feat(provider/xai): support non-image file parts (PDF, text, CSV) in the Responses API via `input_file` + `file_url`
53
+
54
+ The xAI Responses API accepts `{ type: 'input_file', file_url }` for non-image documents (see https://docs.x.ai/docs/guides/chat-with-files), but the AI SDK xAI Responses provider previously threw `UnsupportedFunctionalityError` for any file part whose `mediaType` did not start with `image/`.
55
+
56
+ When a file part is passed with `data: URL` and a non-image media type, the provider now emits `{ type: 'input_file', file_url }`. `application/pdf` and `text/*` are also added to `supportedUrls` so the SDK does not download them to bytes before reaching the converter.
57
+
58
+ Inline-byte (base64) inputs for non-image media types continue to throw, since xAI's Responses API requires either a public URL or a pre-uploaded `file_id` for non-image documents.
59
+
60
+ ## 4.0.0-beta.45
61
+
62
+ ### Patch Changes
63
+
64
+ - 9f0e36c: trigger release for all packages after provenance setup
65
+ - Updated dependencies [9f0e36c]
66
+ - @ai-sdk/openai-compatible@3.0.0-beta.33
67
+ - @ai-sdk/provider@4.0.0-beta.13
68
+ - @ai-sdk/provider-utils@5.0.0-beta.28
69
+
70
+ ## 4.0.0-beta.44
71
+
72
+ ### Patch Changes
73
+
74
+ - 58a2ad7: fix: more precise default message for tool execution denial
75
+ - Updated dependencies [ab81968]
76
+ - Updated dependencies [785fe16]
77
+ - Updated dependencies [67df0a0]
78
+ - Updated dependencies [befb78c]
79
+ - Updated dependencies [0458559]
80
+ - Updated dependencies [58a2ad7]
81
+ - Updated dependencies [5852c0a]
82
+ - Updated dependencies [fc92055]
83
+ - @ai-sdk/openai-compatible@3.0.0-beta.32
84
+ - @ai-sdk/provider-utils@5.0.0-beta.27
85
+
86
+ ## 4.0.0-beta.43
87
+
88
+ ### Patch Changes
89
+
90
+ - a0b0a0c: expose costInUsdTicks in responses provider metadata
91
+ - Updated dependencies [2e98477]
92
+ - Updated dependencies [bfb756d]
93
+ - @ai-sdk/provider-utils@5.0.0-beta.26
94
+ - @ai-sdk/openai-compatible@3.0.0-beta.31
95
+
96
+ ## 4.0.0-beta.42
97
+
98
+ ### Patch Changes
99
+
100
+ - Updated dependencies [eea8d98]
101
+ - @ai-sdk/provider-utils@5.0.0-beta.25
102
+ - @ai-sdk/openai-compatible@3.0.0-beta.30
103
+
104
+ ## 4.0.0-beta.41
105
+
106
+ ### Patch Changes
107
+
108
+ - Updated dependencies [f807e45]
109
+ - @ai-sdk/provider-utils@5.0.0-beta.24
110
+ - @ai-sdk/openai-compatible@3.0.0-beta.29
111
+
112
+ ## 4.0.0-beta.40
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies [350ea38]
117
+ - @ai-sdk/provider-utils@5.0.0-beta.23
118
+ - @ai-sdk/openai-compatible@3.0.0-beta.28
119
+
120
+ ## 4.0.0-beta.39
121
+
122
+ ### Patch Changes
123
+
124
+ - Updated dependencies [083947b]
125
+ - @ai-sdk/provider-utils@5.0.0-beta.22
126
+ - @ai-sdk/openai-compatible@3.0.0-beta.27
127
+
128
+ ## 4.0.0-beta.38
129
+
130
+ ### Patch Changes
131
+
132
+ - Updated dependencies [add1126]
133
+ - @ai-sdk/provider-utils@5.0.0-beta.21
134
+ - @ai-sdk/openai-compatible@3.0.0-beta.26
135
+
136
+ ## 4.0.0-beta.37
137
+
138
+ ### Patch Changes
139
+
140
+ - 8d87577: fix(xai): support encrypted reasoning round-trip for ZDR
141
+
142
+ ## 4.0.0-beta.36
143
+
144
+ ### Patch Changes
145
+
146
+ - b3976a2: Add workflow serialization support to all provider models.
147
+
148
+ **`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
149
+
150
+ **All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
151
+
152
+ All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
153
+
154
+ - Updated dependencies [b3976a2]
155
+ - Updated dependencies [ff5eba1]
156
+ - @ai-sdk/provider-utils@5.0.0-beta.20
157
+ - @ai-sdk/openai-compatible@3.0.0-beta.25
158
+ - @ai-sdk/provider@4.0.0-beta.12
159
+
160
+ ## 4.0.0-beta.35
161
+
162
+ ### Major Changes
163
+
164
+ - ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
165
+
166
+ ### Patch Changes
167
+
168
+ - Updated dependencies [ef992f8]
169
+ - @ai-sdk/openai-compatible@3.0.0-beta.24
170
+ - @ai-sdk/provider@4.0.0-beta.11
171
+ - @ai-sdk/provider-utils@5.0.0-beta.19
172
+
173
+ ## 4.0.0-beta.34
174
+
175
+ ### Patch Changes
176
+
177
+ - 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
178
+ - Updated dependencies [90e2d8a]
179
+ - @ai-sdk/openai-compatible@3.0.0-beta.23
180
+ - @ai-sdk/provider-utils@5.0.0-beta.18
181
+
182
+ ## 4.0.0-beta.33
183
+
184
+ ### Patch Changes
185
+
186
+ - Updated dependencies [3ae1786]
187
+ - @ai-sdk/provider-utils@5.0.0-beta.17
188
+ - @ai-sdk/openai-compatible@3.0.0-beta.22
189
+
190
+ ## 4.0.0-beta.32
191
+
192
+ ### Patch Changes
193
+
194
+ - Updated dependencies [176466a]
195
+ - @ai-sdk/provider@4.0.0-beta.10
196
+ - @ai-sdk/openai-compatible@3.0.0-beta.21
197
+ - @ai-sdk/provider-utils@5.0.0-beta.16
198
+
199
+ ## 4.0.0-beta.31
200
+
201
+ ### Patch Changes
202
+
203
+ - Updated dependencies [e311194]
204
+ - @ai-sdk/provider@4.0.0-beta.9
205
+ - @ai-sdk/openai-compatible@3.0.0-beta.20
206
+ - @ai-sdk/provider-utils@5.0.0-beta.15
207
+
208
+ ## 4.0.0-beta.30
209
+
210
+ ### Patch Changes
211
+
212
+ - e5bdc8d: fix (provider/xai): handle mid-stream error chunks
213
+
214
+ ## 4.0.0-beta.29
215
+
216
+ ### Patch Changes
217
+
218
+ - 813851f: fix (provider/xai): add response.incomplete and response.failed streaming event handling
219
+
220
+ ## 4.0.0-beta.28
221
+
222
+ ### Patch Changes
223
+
224
+ - Updated dependencies [34bd95d]
225
+ - Updated dependencies [008271d]
226
+ - @ai-sdk/provider@4.0.0-beta.8
227
+ - @ai-sdk/openai-compatible@3.0.0-beta.19
228
+ - @ai-sdk/provider-utils@5.0.0-beta.14
229
+
230
+ ## 4.0.0-beta.27
231
+
232
+ ### Patch Changes
233
+
234
+ - Updated dependencies [b0c2869]
235
+ - Updated dependencies [7e26e81]
236
+ - @ai-sdk/provider-utils@5.0.0-beta.13
237
+ - @ai-sdk/openai-compatible@3.0.0-beta.18
238
+
239
+ ## 4.0.0-beta.26
240
+
241
+ ### Patch Changes
242
+
243
+ - Updated dependencies [816ff67]
244
+ - @ai-sdk/openai-compatible@3.0.0-beta.17
245
+
246
+ ## 4.0.0-beta.25
247
+
248
+ ### Patch Changes
249
+
250
+ - Updated dependencies [46d1149]
251
+ - @ai-sdk/provider-utils@5.0.0-beta.12
252
+ - @ai-sdk/openai-compatible@3.0.0-beta.16
253
+
254
+ ## 4.0.0-beta.24
255
+
256
+ ### Patch Changes
257
+
258
+ - Updated dependencies [6fd51c0]
259
+ - @ai-sdk/provider-utils@5.0.0-beta.11
260
+ - @ai-sdk/provider@4.0.0-beta.7
261
+ - @ai-sdk/openai-compatible@3.0.0-beta.15
262
+
263
+ ## 4.0.0-beta.23
264
+
265
+ ### Patch Changes
266
+
267
+ - c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
268
+ - Updated dependencies [c29a26f]
269
+ - @ai-sdk/openai-compatible@3.0.0-beta.14
270
+ - @ai-sdk/provider-utils@5.0.0-beta.10
271
+ - @ai-sdk/provider@4.0.0-beta.6
272
+
273
+ ## 4.0.0-beta.22
274
+
275
+ ### Patch Changes
276
+
277
+ - f51c95e: feat(provider/xai): add video extension and reference-to-video (R2V) support
278
+
279
+ ## 4.0.0-beta.21
280
+
281
+ ### Patch Changes
282
+
283
+ - 38fc777: Add AI Gateway hint to provider READMEs
284
+ - Updated dependencies [38fc777]
285
+ - @ai-sdk/openai-compatible@3.0.0-beta.13
286
+
287
+ ## 4.0.0-beta.20
288
+
289
+ ### Patch Changes
290
+
291
+ - Updated dependencies [2e17091]
292
+ - @ai-sdk/provider-utils@5.0.0-beta.9
293
+ - @ai-sdk/openai-compatible@3.0.0-beta.12
294
+
295
+ ## 4.0.0-beta.19
296
+
297
+ ### Patch Changes
298
+
299
+ - Updated dependencies [986c6fd]
300
+ - Updated dependencies [493295c]
301
+ - @ai-sdk/provider-utils@5.0.0-beta.8
302
+ - @ai-sdk/openai-compatible@3.0.0-beta.11
303
+
304
+ ## 4.0.0-beta.18
305
+
306
+ ### Patch Changes
307
+
308
+ - 9f20868: fix(provider/xai): correct finish reason for tool calls
309
+
310
+ ## 4.0.0-beta.17
311
+
312
+ ### Patch Changes
313
+
314
+ - Updated dependencies [1f509d4]
315
+ - @ai-sdk/provider-utils@5.0.0-beta.7
316
+ - @ai-sdk/provider@4.0.0-beta.5
317
+ - @ai-sdk/openai-compatible@3.0.0-beta.10
318
+
319
+ ## 4.0.0-beta.16
320
+
321
+ ### Patch Changes
322
+
323
+ - 4f91b5d: chore(provider/xai): update Grok 4.20 model IDs to their non-beta versions
324
+
325
+ ## 4.0.0-beta.15
326
+
327
+ ### Patch Changes
328
+
329
+ - 74d520f: feat: migrate providers to support new top-level `reasoning` parameter
330
+ - Updated dependencies [74d520f]
331
+ - @ai-sdk/openai-compatible@3.0.0-beta.9
332
+
333
+ ## 4.0.0-beta.14
334
+
335
+ ### Patch Changes
336
+
337
+ - Updated dependencies [3887c70]
338
+ - @ai-sdk/provider-utils@5.0.0-beta.6
339
+ - @ai-sdk/provider@4.0.0-beta.4
340
+ - @ai-sdk/openai-compatible@3.0.0-beta.8
341
+
342
+ ## 4.0.0-beta.13
343
+
344
+ ### Major Changes
345
+
346
+ - 776b617: feat(provider): adding new 'custom' content type
347
+
348
+ ### Patch Changes
349
+
350
+ - Updated dependencies [776b617]
351
+ - @ai-sdk/provider-utils@5.0.0-beta.5
352
+ - @ai-sdk/provider@4.0.0-beta.3
353
+ - @ai-sdk/openai-compatible@3.0.0-beta.7
354
+
355
+ ## 4.0.0-beta.12
356
+
357
+ ### Patch Changes
358
+
359
+ - d20829e: feat(provider/xai): add moderation error, and costInUsdTicks to video model
360
+ - Updated dependencies [61753c3]
361
+ - @ai-sdk/provider-utils@5.0.0-beta.4
362
+ - @ai-sdk/openai-compatible@3.0.0-beta.6
363
+
364
+ ## 4.0.0-beta.11
365
+
366
+ ### Patch Changes
367
+
368
+ - f7d4f01: feat(provider): add support for `reasoning-file` type for files that are part of reasoning
369
+ - Updated dependencies [f7d4f01]
370
+ - @ai-sdk/provider-utils@5.0.0-beta.3
371
+ - @ai-sdk/provider@4.0.0-beta.2
372
+ - @ai-sdk/openai-compatible@3.0.0-beta.5
373
+
374
+ ## 4.0.0-beta.10
375
+
376
+ ### Patch Changes
377
+
378
+ - Updated dependencies [5c2a5a2]
379
+ - @ai-sdk/provider@4.0.0-beta.1
380
+ - @ai-sdk/openai-compatible@3.0.0-beta.4
381
+ - @ai-sdk/provider-utils@5.0.0-beta.2
382
+
383
+ ## 4.0.0-beta.9
384
+
385
+ ### Patch Changes
386
+
387
+ - Updated dependencies [8f3e1da]
388
+ - @ai-sdk/openai-compatible@3.0.0-beta.3
389
+
3
390
  ## 4.0.0-beta.8
4
391
 
5
392
  ### Patch Changes
@@ -561,13 +948,13 @@
561
948
  Before
562
949
 
563
950
  ```ts
564
- model.textEmbeddingModel('my-model-id');
951
+ model.textEmbeddingModel("my-model-id");
565
952
  ```
566
953
 
567
954
  After
568
955
 
569
956
  ```ts
570
- model.embeddingModel('my-model-id');
957
+ model.embeddingModel("my-model-id");
571
958
  ```
572
959
 
573
960
  - 2625a04: feat(openai); update spec for mcp approval
@@ -825,13 +1212,13 @@
825
1212
  Before
826
1213
 
827
1214
  ```ts
828
- model.textEmbeddingModel('my-model-id');
1215
+ model.textEmbeddingModel("my-model-id");
829
1216
  ```
830
1217
 
831
1218
  After
832
1219
 
833
1220
  ```ts
834
- model.embeddingModel('my-model-id');
1221
+ model.embeddingModel("my-model-id");
835
1222
  ```
836
1223
 
837
1224
  - 8514146: add grok-4-1 model IDs
@@ -1374,7 +1761,7 @@
1374
1761
 
1375
1762
  ```js
1376
1763
  await generateImage({
1377
- model: luma.image('photon-flash-1', {
1764
+ model: luma.image("photon-flash-1", {
1378
1765
  maxImagesPerCall: 5,
1379
1766
  pollIntervalMillis: 500,
1380
1767
  }),
@@ -1387,7 +1774,7 @@
1387
1774
 
1388
1775
  ```js
1389
1776
  await generateImage({
1390
- model: luma.image('photon-flash-1'),
1777
+ model: luma.image("photon-flash-1"),
1391
1778
  prompt,
1392
1779
  n: 10,
1393
1780
  maxImagesPerCall: 5,
@@ -1703,7 +2090,7 @@
1703
2090
 
1704
2091
  ```js
1705
2092
  await generateImage({
1706
- model: luma.image('photon-flash-1', {
2093
+ model: luma.image("photon-flash-1", {
1707
2094
  maxImagesPerCall: 5,
1708
2095
  pollIntervalMillis: 500,
1709
2096
  }),
@@ -1716,7 +2103,7 @@
1716
2103
 
1717
2104
  ```js
1718
2105
  await generateImage({
1719
- model: luma.image('photon-flash-1'),
2106
+ model: luma.image("photon-flash-1"),
1720
2107
  prompt,
1721
2108
  n: 10,
1722
2109
  maxImagesPerCall: 5,
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  The **[xAI Grok provider](https://ai-sdk.dev/providers/ai-sdk-providers/xai)** for the [AI SDK](https://ai-sdk.dev/docs)
4
4
  contains language model support for the xAI chat and completion APIs.
5
5
 
6
+ > **Deploying to Vercel?** With Vercel's AI Gateway you can access xAI (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
7
+
6
8
  ## Setup
7
9
 
8
10
  The xAI Grok provider is available in the `@ai-sdk/xai` module. You can install it with