@ai-sdk/xai 4.0.0-beta.9 → 4.0.0-canary.51

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.51
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [cd9c311]
8
+ - @ai-sdk/openai-compatible@3.0.0-canary.38
9
+
10
+ ## 4.0.0-canary.50
11
+
12
+ ### Patch Changes
13
+
14
+ - 0c4c275: trigger initial canary release
15
+ - Updated dependencies [0c4c275]
16
+ - @ai-sdk/openai-compatible@3.0.0-canary.37
17
+ - @ai-sdk/provider-utils@5.0.0-canary.31
18
+ - @ai-sdk/provider@4.0.0-canary.15
19
+
20
+ ## 4.0.0-beta.49
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [e59c955]
25
+ - @ai-sdk/openai-compatible@3.0.0-beta.36
26
+
27
+ ## 4.0.0-beta.48
28
+
29
+ ### Major Changes
30
+
31
+ - 04e9009: chore: make provider implementations code patterns more consistent, including renaming certain exported symbols
32
+
33
+ For all externally exported symbols that were renamed, the old names continue to work via deprecated aliases.
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [08d2129]
38
+ - Updated dependencies [04e9009]
39
+ - @ai-sdk/provider-utils@5.0.0-beta.30
40
+ - @ai-sdk/openai-compatible@3.0.0-beta.35
41
+
42
+ ## 4.0.0-beta.47
43
+
44
+ ### Patch Changes
45
+
46
+ - 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
47
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
48
+ - Updated dependencies [9bd6512]
49
+ - Updated dependencies [258c093]
50
+ - Updated dependencies [b6783da]
51
+ - @ai-sdk/openai-compatible@3.0.0-beta.34
52
+ - @ai-sdk/provider-utils@5.0.0-beta.29
53
+ - @ai-sdk/provider@4.0.0-beta.14
54
+
55
+ ## 4.0.0-beta.46
56
+
57
+ ### Patch Changes
58
+
59
+ - 78b6433: feat(provider/xai): support non-image file parts (PDF, text, CSV) in the Responses API via `input_file` + `file_url`
60
+
61
+ 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/`.
62
+
63
+ 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.
64
+
65
+ 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.
66
+
67
+ ## 4.0.0-beta.45
68
+
69
+ ### Patch Changes
70
+
71
+ - 9f0e36c: trigger release for all packages after provenance setup
72
+ - Updated dependencies [9f0e36c]
73
+ - @ai-sdk/openai-compatible@3.0.0-beta.33
74
+ - @ai-sdk/provider@4.0.0-beta.13
75
+ - @ai-sdk/provider-utils@5.0.0-beta.28
76
+
77
+ ## 4.0.0-beta.44
78
+
79
+ ### Patch Changes
80
+
81
+ - 58a2ad7: fix: more precise default message for tool execution denial
82
+ - Updated dependencies [ab81968]
83
+ - Updated dependencies [785fe16]
84
+ - Updated dependencies [67df0a0]
85
+ - Updated dependencies [befb78c]
86
+ - Updated dependencies [0458559]
87
+ - Updated dependencies [58a2ad7]
88
+ - Updated dependencies [5852c0a]
89
+ - Updated dependencies [fc92055]
90
+ - @ai-sdk/openai-compatible@3.0.0-beta.32
91
+ - @ai-sdk/provider-utils@5.0.0-beta.27
92
+
93
+ ## 4.0.0-beta.43
94
+
95
+ ### Patch Changes
96
+
97
+ - a0b0a0c: expose costInUsdTicks in responses provider metadata
98
+ - Updated dependencies [2e98477]
99
+ - Updated dependencies [bfb756d]
100
+ - @ai-sdk/provider-utils@5.0.0-beta.26
101
+ - @ai-sdk/openai-compatible@3.0.0-beta.31
102
+
103
+ ## 4.0.0-beta.42
104
+
105
+ ### Patch Changes
106
+
107
+ - Updated dependencies [eea8d98]
108
+ - @ai-sdk/provider-utils@5.0.0-beta.25
109
+ - @ai-sdk/openai-compatible@3.0.0-beta.30
110
+
111
+ ## 4.0.0-beta.41
112
+
113
+ ### Patch Changes
114
+
115
+ - Updated dependencies [f807e45]
116
+ - @ai-sdk/provider-utils@5.0.0-beta.24
117
+ - @ai-sdk/openai-compatible@3.0.0-beta.29
118
+
119
+ ## 4.0.0-beta.40
120
+
121
+ ### Patch Changes
122
+
123
+ - Updated dependencies [350ea38]
124
+ - @ai-sdk/provider-utils@5.0.0-beta.23
125
+ - @ai-sdk/openai-compatible@3.0.0-beta.28
126
+
127
+ ## 4.0.0-beta.39
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [083947b]
132
+ - @ai-sdk/provider-utils@5.0.0-beta.22
133
+ - @ai-sdk/openai-compatible@3.0.0-beta.27
134
+
135
+ ## 4.0.0-beta.38
136
+
137
+ ### Patch Changes
138
+
139
+ - Updated dependencies [add1126]
140
+ - @ai-sdk/provider-utils@5.0.0-beta.21
141
+ - @ai-sdk/openai-compatible@3.0.0-beta.26
142
+
143
+ ## 4.0.0-beta.37
144
+
145
+ ### Patch Changes
146
+
147
+ - 8d87577: fix(xai): support encrypted reasoning round-trip for ZDR
148
+
149
+ ## 4.0.0-beta.36
150
+
151
+ ### Patch Changes
152
+
153
+ - b3976a2: Add workflow serialization support to all provider models.
154
+
155
+ **`@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.
156
+
157
+ **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.
158
+
159
+ All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
160
+
161
+ - Updated dependencies [b3976a2]
162
+ - Updated dependencies [ff5eba1]
163
+ - @ai-sdk/provider-utils@5.0.0-beta.20
164
+ - @ai-sdk/openai-compatible@3.0.0-beta.25
165
+ - @ai-sdk/provider@4.0.0-beta.12
166
+
167
+ ## 4.0.0-beta.35
168
+
169
+ ### Major Changes
170
+
171
+ - ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
172
+
173
+ ### Patch Changes
174
+
175
+ - Updated dependencies [ef992f8]
176
+ - @ai-sdk/openai-compatible@3.0.0-beta.24
177
+ - @ai-sdk/provider@4.0.0-beta.11
178
+ - @ai-sdk/provider-utils@5.0.0-beta.19
179
+
180
+ ## 4.0.0-beta.34
181
+
182
+ ### Patch Changes
183
+
184
+ - 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
185
+ - Updated dependencies [90e2d8a]
186
+ - @ai-sdk/openai-compatible@3.0.0-beta.23
187
+ - @ai-sdk/provider-utils@5.0.0-beta.18
188
+
189
+ ## 4.0.0-beta.33
190
+
191
+ ### Patch Changes
192
+
193
+ - Updated dependencies [3ae1786]
194
+ - @ai-sdk/provider-utils@5.0.0-beta.17
195
+ - @ai-sdk/openai-compatible@3.0.0-beta.22
196
+
197
+ ## 4.0.0-beta.32
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies [176466a]
202
+ - @ai-sdk/provider@4.0.0-beta.10
203
+ - @ai-sdk/openai-compatible@3.0.0-beta.21
204
+ - @ai-sdk/provider-utils@5.0.0-beta.16
205
+
206
+ ## 4.0.0-beta.31
207
+
208
+ ### Patch Changes
209
+
210
+ - Updated dependencies [e311194]
211
+ - @ai-sdk/provider@4.0.0-beta.9
212
+ - @ai-sdk/openai-compatible@3.0.0-beta.20
213
+ - @ai-sdk/provider-utils@5.0.0-beta.15
214
+
215
+ ## 4.0.0-beta.30
216
+
217
+ ### Patch Changes
218
+
219
+ - e5bdc8d: fix (provider/xai): handle mid-stream error chunks
220
+
221
+ ## 4.0.0-beta.29
222
+
223
+ ### Patch Changes
224
+
225
+ - 813851f: fix (provider/xai): add response.incomplete and response.failed streaming event handling
226
+
227
+ ## 4.0.0-beta.28
228
+
229
+ ### Patch Changes
230
+
231
+ - Updated dependencies [34bd95d]
232
+ - Updated dependencies [008271d]
233
+ - @ai-sdk/provider@4.0.0-beta.8
234
+ - @ai-sdk/openai-compatible@3.0.0-beta.19
235
+ - @ai-sdk/provider-utils@5.0.0-beta.14
236
+
237
+ ## 4.0.0-beta.27
238
+
239
+ ### Patch Changes
240
+
241
+ - Updated dependencies [b0c2869]
242
+ - Updated dependencies [7e26e81]
243
+ - @ai-sdk/provider-utils@5.0.0-beta.13
244
+ - @ai-sdk/openai-compatible@3.0.0-beta.18
245
+
246
+ ## 4.0.0-beta.26
247
+
248
+ ### Patch Changes
249
+
250
+ - Updated dependencies [816ff67]
251
+ - @ai-sdk/openai-compatible@3.0.0-beta.17
252
+
253
+ ## 4.0.0-beta.25
254
+
255
+ ### Patch Changes
256
+
257
+ - Updated dependencies [46d1149]
258
+ - @ai-sdk/provider-utils@5.0.0-beta.12
259
+ - @ai-sdk/openai-compatible@3.0.0-beta.16
260
+
261
+ ## 4.0.0-beta.24
262
+
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies [6fd51c0]
266
+ - @ai-sdk/provider-utils@5.0.0-beta.11
267
+ - @ai-sdk/provider@4.0.0-beta.7
268
+ - @ai-sdk/openai-compatible@3.0.0-beta.15
269
+
270
+ ## 4.0.0-beta.23
271
+
272
+ ### Patch Changes
273
+
274
+ - c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
275
+ - Updated dependencies [c29a26f]
276
+ - @ai-sdk/openai-compatible@3.0.0-beta.14
277
+ - @ai-sdk/provider-utils@5.0.0-beta.10
278
+ - @ai-sdk/provider@4.0.0-beta.6
279
+
280
+ ## 4.0.0-beta.22
281
+
282
+ ### Patch Changes
283
+
284
+ - f51c95e: feat(provider/xai): add video extension and reference-to-video (R2V) support
285
+
286
+ ## 4.0.0-beta.21
287
+
288
+ ### Patch Changes
289
+
290
+ - 38fc777: Add AI Gateway hint to provider READMEs
291
+ - Updated dependencies [38fc777]
292
+ - @ai-sdk/openai-compatible@3.0.0-beta.13
293
+
294
+ ## 4.0.0-beta.20
295
+
296
+ ### Patch Changes
297
+
298
+ - Updated dependencies [2e17091]
299
+ - @ai-sdk/provider-utils@5.0.0-beta.9
300
+ - @ai-sdk/openai-compatible@3.0.0-beta.12
301
+
302
+ ## 4.0.0-beta.19
303
+
304
+ ### Patch Changes
305
+
306
+ - Updated dependencies [986c6fd]
307
+ - Updated dependencies [493295c]
308
+ - @ai-sdk/provider-utils@5.0.0-beta.8
309
+ - @ai-sdk/openai-compatible@3.0.0-beta.11
310
+
311
+ ## 4.0.0-beta.18
312
+
313
+ ### Patch Changes
314
+
315
+ - 9f20868: fix(provider/xai): correct finish reason for tool calls
316
+
317
+ ## 4.0.0-beta.17
318
+
319
+ ### Patch Changes
320
+
321
+ - Updated dependencies [1f509d4]
322
+ - @ai-sdk/provider-utils@5.0.0-beta.7
323
+ - @ai-sdk/provider@4.0.0-beta.5
324
+ - @ai-sdk/openai-compatible@3.0.0-beta.10
325
+
326
+ ## 4.0.0-beta.16
327
+
328
+ ### Patch Changes
329
+
330
+ - 4f91b5d: chore(provider/xai): update Grok 4.20 model IDs to their non-beta versions
331
+
332
+ ## 4.0.0-beta.15
333
+
334
+ ### Patch Changes
335
+
336
+ - 74d520f: feat: migrate providers to support new top-level `reasoning` parameter
337
+ - Updated dependencies [74d520f]
338
+ - @ai-sdk/openai-compatible@3.0.0-beta.9
339
+
340
+ ## 4.0.0-beta.14
341
+
342
+ ### Patch Changes
343
+
344
+ - Updated dependencies [3887c70]
345
+ - @ai-sdk/provider-utils@5.0.0-beta.6
346
+ - @ai-sdk/provider@4.0.0-beta.4
347
+ - @ai-sdk/openai-compatible@3.0.0-beta.8
348
+
349
+ ## 4.0.0-beta.13
350
+
351
+ ### Major Changes
352
+
353
+ - 776b617: feat(provider): adding new 'custom' content type
354
+
355
+ ### Patch Changes
356
+
357
+ - Updated dependencies [776b617]
358
+ - @ai-sdk/provider-utils@5.0.0-beta.5
359
+ - @ai-sdk/provider@4.0.0-beta.3
360
+ - @ai-sdk/openai-compatible@3.0.0-beta.7
361
+
362
+ ## 4.0.0-beta.12
363
+
364
+ ### Patch Changes
365
+
366
+ - d20829e: feat(provider/xai): add moderation error, and costInUsdTicks to video model
367
+ - Updated dependencies [61753c3]
368
+ - @ai-sdk/provider-utils@5.0.0-beta.4
369
+ - @ai-sdk/openai-compatible@3.0.0-beta.6
370
+
371
+ ## 4.0.0-beta.11
372
+
373
+ ### Patch Changes
374
+
375
+ - f7d4f01: feat(provider): add support for `reasoning-file` type for files that are part of reasoning
376
+ - Updated dependencies [f7d4f01]
377
+ - @ai-sdk/provider-utils@5.0.0-beta.3
378
+ - @ai-sdk/provider@4.0.0-beta.2
379
+ - @ai-sdk/openai-compatible@3.0.0-beta.5
380
+
381
+ ## 4.0.0-beta.10
382
+
383
+ ### Patch Changes
384
+
385
+ - Updated dependencies [5c2a5a2]
386
+ - @ai-sdk/provider@4.0.0-beta.1
387
+ - @ai-sdk/openai-compatible@3.0.0-beta.4
388
+ - @ai-sdk/provider-utils@5.0.0-beta.2
389
+
3
390
  ## 4.0.0-beta.9
4
391
 
5
392
  ### Patch Changes
@@ -568,13 +955,13 @@
568
955
  Before
569
956
 
570
957
  ```ts
571
- model.textEmbeddingModel('my-model-id');
958
+ model.textEmbeddingModel("my-model-id");
572
959
  ```
573
960
 
574
961
  After
575
962
 
576
963
  ```ts
577
- model.embeddingModel('my-model-id');
964
+ model.embeddingModel("my-model-id");
578
965
  ```
579
966
 
580
967
  - 2625a04: feat(openai); update spec for mcp approval
@@ -832,13 +1219,13 @@
832
1219
  Before
833
1220
 
834
1221
  ```ts
835
- model.textEmbeddingModel('my-model-id');
1222
+ model.textEmbeddingModel("my-model-id");
836
1223
  ```
837
1224
 
838
1225
  After
839
1226
 
840
1227
  ```ts
841
- model.embeddingModel('my-model-id');
1228
+ model.embeddingModel("my-model-id");
842
1229
  ```
843
1230
 
844
1231
  - 8514146: add grok-4-1 model IDs
@@ -1381,7 +1768,7 @@
1381
1768
 
1382
1769
  ```js
1383
1770
  await generateImage({
1384
- model: luma.image('photon-flash-1', {
1771
+ model: luma.image("photon-flash-1", {
1385
1772
  maxImagesPerCall: 5,
1386
1773
  pollIntervalMillis: 500,
1387
1774
  }),
@@ -1394,7 +1781,7 @@
1394
1781
 
1395
1782
  ```js
1396
1783
  await generateImage({
1397
- model: luma.image('photon-flash-1'),
1784
+ model: luma.image("photon-flash-1"),
1398
1785
  prompt,
1399
1786
  n: 10,
1400
1787
  maxImagesPerCall: 5,
@@ -1710,7 +2097,7 @@
1710
2097
 
1711
2098
  ```js
1712
2099
  await generateImage({
1713
- model: luma.image('photon-flash-1', {
2100
+ model: luma.image("photon-flash-1", {
1714
2101
  maxImagesPerCall: 5,
1715
2102
  pollIntervalMillis: 500,
1716
2103
  }),
@@ -1723,7 +2110,7 @@
1723
2110
 
1724
2111
  ```js
1725
2112
  await generateImage({
1726
- model: luma.image('photon-flash-1'),
2113
+ model: luma.image("photon-flash-1"),
1727
2114
  prompt,
1728
2115
  n: 10,
1729
2116
  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