@ai-sdk/openai 2.0.9 → 2.0.11

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/dist/index.js CHANGED
@@ -26,16 +26,35 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/openai-provider.ts
29
- var import_provider_utils14 = require("@ai-sdk/provider-utils");
29
+ var import_provider_utils15 = require("@ai-sdk/provider-utils");
30
30
 
31
- // src/openai-chat-language-model.ts
31
+ // src/chat/openai-chat-language-model.ts
32
32
  var import_provider3 = require("@ai-sdk/provider");
33
33
  var import_provider_utils5 = require("@ai-sdk/provider-utils");
34
34
  var import_v45 = require("zod/v4");
35
35
 
36
- // src/convert-to-openai-chat-messages.ts
37
- var import_provider = require("@ai-sdk/provider");
36
+ // src/openai-error.ts
37
+ var import_v4 = require("zod/v4");
38
38
  var import_provider_utils = require("@ai-sdk/provider-utils");
39
+ var openaiErrorDataSchema = import_v4.z.object({
40
+ error: import_v4.z.object({
41
+ message: import_v4.z.string(),
42
+ // The additional information below is handled loosely to support
43
+ // OpenAI-compatible providers that have slightly different error
44
+ // responses:
45
+ type: import_v4.z.string().nullish(),
46
+ param: import_v4.z.any().nullish(),
47
+ code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).nullish()
48
+ })
49
+ });
50
+ var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
51
+ errorSchema: openaiErrorDataSchema,
52
+ errorToMessage: (data) => data.error.message
53
+ });
54
+
55
+ // src/chat/convert-to-openai-chat-messages.ts
56
+ var import_provider = require("@ai-sdk/provider");
57
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
39
58
  function convertToOpenAIChatMessages({
40
59
  prompt,
41
60
  systemMessageMode = "system"
@@ -89,7 +108,7 @@ function convertToOpenAIChatMessages({
89
108
  return {
90
109
  type: "image_url",
91
110
  image_url: {
92
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`,
111
+ url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`,
93
112
  // OpenAI specific extension: image detail
94
113
  detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
95
114
  }
@@ -105,7 +124,7 @@ function convertToOpenAIChatMessages({
105
124
  return {
106
125
  type: "input_audio",
107
126
  input_audio: {
108
- data: (0, import_provider_utils.convertToBase64)(part.data),
127
+ data: (0, import_provider_utils2.convertToBase64)(part.data),
109
128
  format: "wav"
110
129
  }
111
130
  };
@@ -115,7 +134,7 @@ function convertToOpenAIChatMessages({
115
134
  return {
116
135
  type: "input_audio",
117
136
  input_audio: {
118
- data: (0, import_provider_utils.convertToBase64)(part.data),
137
+ data: (0, import_provider_utils2.convertToBase64)(part.data),
119
138
  format: "mp3"
120
139
  }
121
140
  };
@@ -136,7 +155,7 @@ function convertToOpenAIChatMessages({
136
155
  type: "file",
137
156
  file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
138
157
  filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
139
- file_data: `data:application/pdf;base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
158
+ file_data: `data:application/pdf;base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`
140
159
  }
141
160
  };
142
161
  } else {
@@ -211,7 +230,7 @@ function convertToOpenAIChatMessages({
211
230
  return { messages, warnings };
212
231
  }
213
232
 
214
- // src/get-response-metadata.ts
233
+ // src/chat/get-response-metadata.ts
215
234
  function getResponseMetadata({
216
235
  id,
217
236
  model,
@@ -224,7 +243,7 @@ function getResponseMetadata({
224
243
  };
225
244
  }
226
245
 
227
- // src/map-openai-finish-reason.ts
246
+ // src/chat/map-openai-finish-reason.ts
228
247
  function mapOpenAIFinishReason(finishReason) {
229
248
  switch (finishReason) {
230
249
  case "stop":
@@ -241,16 +260,16 @@ function mapOpenAIFinishReason(finishReason) {
241
260
  }
242
261
  }
243
262
 
244
- // src/openai-chat-options.ts
245
- var import_v4 = require("zod/v4");
246
- var openaiProviderOptions = import_v4.z.object({
263
+ // src/chat/openai-chat-options.ts
264
+ var import_v42 = require("zod/v4");
265
+ var openaiProviderOptions = import_v42.z.object({
247
266
  /**
248
267
  * Modify the likelihood of specified tokens appearing in the completion.
249
268
  *
250
269
  * Accepts a JSON object that maps tokens (specified by their token ID in
251
270
  * the GPT tokenizer) to an associated bias value from -100 to 100.
252
271
  */
253
- logitBias: import_v4.z.record(import_v4.z.coerce.number(), import_v4.z.number()).optional(),
272
+ logitBias: import_v42.z.record(import_v42.z.coerce.number(), import_v42.z.number()).optional(),
254
273
  /**
255
274
  * Return the log probabilities of the tokens.
256
275
  *
@@ -260,42 +279,42 @@ var openaiProviderOptions = import_v4.z.object({
260
279
  * Setting to a number will return the log probabilities of the top n
261
280
  * tokens that were generated.
262
281
  */
263
- logprobs: import_v4.z.union([import_v4.z.boolean(), import_v4.z.number()]).optional(),
282
+ logprobs: import_v42.z.union([import_v42.z.boolean(), import_v42.z.number()]).optional(),
264
283
  /**
265
284
  * Whether to enable parallel function calling during tool use. Default to true.
266
285
  */
267
- parallelToolCalls: import_v4.z.boolean().optional(),
286
+ parallelToolCalls: import_v42.z.boolean().optional(),
268
287
  /**
269
288
  * A unique identifier representing your end-user, which can help OpenAI to
270
289
  * monitor and detect abuse.
271
290
  */
272
- user: import_v4.z.string().optional(),
291
+ user: import_v42.z.string().optional(),
273
292
  /**
274
293
  * Reasoning effort for reasoning models. Defaults to `medium`.
275
294
  */
276
- reasoningEffort: import_v4.z.enum(["minimal", "low", "medium", "high"]).optional(),
295
+ reasoningEffort: import_v42.z.enum(["minimal", "low", "medium", "high"]).optional(),
277
296
  /**
278
297
  * Maximum number of completion tokens to generate. Useful for reasoning models.
279
298
  */
280
- maxCompletionTokens: import_v4.z.number().optional(),
299
+ maxCompletionTokens: import_v42.z.number().optional(),
281
300
  /**
282
301
  * Whether to enable persistence in responses API.
283
302
  */
284
- store: import_v4.z.boolean().optional(),
303
+ store: import_v42.z.boolean().optional(),
285
304
  /**
286
305
  * Metadata to associate with the request.
287
306
  */
288
- metadata: import_v4.z.record(import_v4.z.string().max(64), import_v4.z.string().max(512)).optional(),
307
+ metadata: import_v42.z.record(import_v42.z.string().max(64), import_v42.z.string().max(512)).optional(),
289
308
  /**
290
309
  * Parameters for prediction mode.
291
310
  */
292
- prediction: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
311
+ prediction: import_v42.z.record(import_v42.z.string(), import_v42.z.any()).optional(),
293
312
  /**
294
313
  * Whether to use structured outputs.
295
314
  *
296
315
  * @default true
297
316
  */
298
- structuredOutputs: import_v4.z.boolean().optional(),
317
+ structuredOutputs: import_v42.z.boolean().optional(),
299
318
  /**
300
319
  * Service tier for the request.
301
320
  * - 'auto': Default service tier
@@ -304,40 +323,34 @@ var openaiProviderOptions = import_v4.z.object({
304
323
  *
305
324
  * @default 'auto'
306
325
  */
307
- serviceTier: import_v4.z.enum(["auto", "flex", "priority"]).optional(),
326
+ serviceTier: import_v42.z.enum(["auto", "flex", "priority"]).optional(),
308
327
  /**
309
328
  * Whether to use strict JSON schema validation.
310
329
  *
311
330
  * @default false
312
331
  */
313
- strictJsonSchema: import_v4.z.boolean().optional(),
332
+ strictJsonSchema: import_v42.z.boolean().optional(),
314
333
  /**
315
334
  * Controls the verbosity of the model's responses.
316
335
  * Lower values will result in more concise responses, while higher values will result in more verbose responses.
317
336
  */
318
- textVerbosity: import_v4.z.enum(["low", "medium", "high"]).optional()
319
- });
320
-
321
- // src/openai-error.ts
322
- var import_v42 = require("zod/v4");
323
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
324
- var openaiErrorDataSchema = import_v42.z.object({
325
- error: import_v42.z.object({
326
- message: import_v42.z.string(),
327
- // The additional information below is handled loosely to support
328
- // OpenAI-compatible providers that have slightly different error
329
- // responses:
330
- type: import_v42.z.string().nullish(),
331
- param: import_v42.z.any().nullish(),
332
- code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
333
- })
334
- });
335
- var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
336
- errorSchema: openaiErrorDataSchema,
337
- errorToMessage: (data) => data.error.message
337
+ textVerbosity: import_v42.z.enum(["low", "medium", "high"]).optional(),
338
+ /**
339
+ * A cache key for prompt caching. Allows manual control over prompt caching behavior.
340
+ * Useful for improving cache hit rates and working around automatic caching issues.
341
+ */
342
+ promptCacheKey: import_v42.z.string().optional(),
343
+ /**
344
+ * A stable identifier used to help detect users of your application
345
+ * that may be violating OpenAI's usage policies. The IDs should be a
346
+ * string that uniquely identifies each user. We recommend hashing their
347
+ * username or email address, in order to avoid sending us any identifying
348
+ * information.
349
+ */
350
+ safetyIdentifier: import_v42.z.string().optional()
338
351
  });
339
352
 
340
- // src/openai-prepare-tools.ts
353
+ // src/chat/openai-chat-prepare-tools.ts
341
354
  var import_provider2 = require("@ai-sdk/provider");
342
355
 
343
356
  // src/tool/file-search.ts
@@ -426,8 +439,8 @@ var webSearchPreview = (0, import_provider_utils4.createProviderDefinedToolFacto
426
439
  inputSchema: import_v44.z.object({})
427
440
  });
428
441
 
429
- // src/openai-prepare-tools.ts
430
- function prepareTools({
442
+ // src/chat/openai-chat-prepare-tools.ts
443
+ function prepareChatTools({
431
444
  tools,
432
445
  toolChoice,
433
446
  structuredOutputs,
@@ -513,7 +526,7 @@ function prepareTools({
513
526
  }
514
527
  }
515
528
 
516
- // src/openai-chat-language-model.ts
529
+ // src/chat/openai-chat-language-model.ts
517
530
  var OpenAIChatLanguageModel = class {
518
531
  constructor(modelId, config) {
519
532
  this.specificationVersion = "v2";
@@ -598,13 +611,15 @@ var OpenAIChatLanguageModel = class {
598
611
  seed,
599
612
  verbosity: openaiOptions.textVerbosity,
600
613
  // openai specific settings:
601
- // TODO remove in next major version; we auto-map maxOutputTokens now
614
+ // TODO AI SDK 6: remove, we auto-map maxOutputTokens now
602
615
  max_completion_tokens: openaiOptions.maxCompletionTokens,
603
616
  store: openaiOptions.store,
604
617
  metadata: openaiOptions.metadata,
605
618
  prediction: openaiOptions.prediction,
606
619
  reasoning_effort: openaiOptions.reasoningEffort,
607
620
  service_tier: openaiOptions.serviceTier,
621
+ prompt_cache_key: openaiOptions.promptCacheKey,
622
+ safety_identifier: openaiOptions.safetyIdentifier,
608
623
  // messages:
609
624
  messages
610
625
  };
@@ -698,7 +713,7 @@ var OpenAIChatLanguageModel = class {
698
713
  tools: openaiTools2,
699
714
  toolChoice: openaiToolChoice,
700
715
  toolWarnings
701
- } = prepareTools({
716
+ } = prepareChatTools({
702
717
  tools,
703
718
  toolChoice,
704
719
  structuredOutputs,
@@ -1168,11 +1183,11 @@ var reasoningModels = {
1168
1183
  }
1169
1184
  };
1170
1185
 
1171
- // src/openai-completion-language-model.ts
1186
+ // src/completion/openai-completion-language-model.ts
1172
1187
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1173
1188
  var import_v47 = require("zod/v4");
1174
1189
 
1175
- // src/convert-to-openai-completion-prompt.ts
1190
+ // src/completion/convert-to-openai-completion-prompt.ts
1176
1191
  var import_provider4 = require("@ai-sdk/provider");
1177
1192
  function convertToOpenAICompletionPrompt({
1178
1193
  prompt,
@@ -1247,7 +1262,37 @@ ${user}:`]
1247
1262
  };
1248
1263
  }
1249
1264
 
1250
- // src/openai-completion-options.ts
1265
+ // src/completion/get-response-metadata.ts
1266
+ function getResponseMetadata2({
1267
+ id,
1268
+ model,
1269
+ created
1270
+ }) {
1271
+ return {
1272
+ id: id != null ? id : void 0,
1273
+ modelId: model != null ? model : void 0,
1274
+ timestamp: created != null ? new Date(created * 1e3) : void 0
1275
+ };
1276
+ }
1277
+
1278
+ // src/completion/map-openai-finish-reason.ts
1279
+ function mapOpenAIFinishReason2(finishReason) {
1280
+ switch (finishReason) {
1281
+ case "stop":
1282
+ return "stop";
1283
+ case "length":
1284
+ return "length";
1285
+ case "content_filter":
1286
+ return "content-filter";
1287
+ case "function_call":
1288
+ case "tool_calls":
1289
+ return "tool-calls";
1290
+ default:
1291
+ return "unknown";
1292
+ }
1293
+ }
1294
+
1295
+ // src/completion/openai-completion-options.ts
1251
1296
  var import_v46 = require("zod/v4");
1252
1297
  var openaiCompletionProviderOptions = import_v46.z.object({
1253
1298
  /**
@@ -1290,7 +1335,7 @@ var openaiCompletionProviderOptions = import_v46.z.object({
1290
1335
  logprobs: import_v46.z.union([import_v46.z.boolean(), import_v46.z.number()]).optional()
1291
1336
  });
1292
1337
 
1293
- // src/openai-completion-language-model.ts
1338
+ // src/completion/openai-completion-language-model.ts
1294
1339
  var OpenAICompletionLanguageModel = class {
1295
1340
  constructor(modelId, config) {
1296
1341
  this.specificationVersion = "v2";
@@ -1410,10 +1455,10 @@ var OpenAICompletionLanguageModel = class {
1410
1455
  outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
1411
1456
  totalTokens: (_c = response.usage) == null ? void 0 : _c.total_tokens
1412
1457
  },
1413
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
1458
+ finishReason: mapOpenAIFinishReason2(choice.finish_reason),
1414
1459
  request: { body: args },
1415
1460
  response: {
1416
- ...getResponseMetadata(response),
1461
+ ...getResponseMetadata2(response),
1417
1462
  headers: responseHeaders,
1418
1463
  body: rawResponse
1419
1464
  },
@@ -1477,7 +1522,7 @@ var OpenAICompletionLanguageModel = class {
1477
1522
  isFirstChunk = false;
1478
1523
  controller.enqueue({
1479
1524
  type: "response-metadata",
1480
- ...getResponseMetadata(value)
1525
+ ...getResponseMetadata2(value)
1481
1526
  });
1482
1527
  controller.enqueue({ type: "text-start", id: "0" });
1483
1528
  }
@@ -1488,7 +1533,7 @@ var OpenAICompletionLanguageModel = class {
1488
1533
  }
1489
1534
  const choice = value.choices[0];
1490
1535
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1491
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
1536
+ finishReason = mapOpenAIFinishReason2(choice.finish_reason);
1492
1537
  }
1493
1538
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1494
1539
  providerMetadata.openai.logprobs = choice.logprobs;
@@ -1563,12 +1608,12 @@ var openaiCompletionChunkSchema = import_v47.z.union([
1563
1608
  openaiErrorDataSchema
1564
1609
  ]);
1565
1610
 
1566
- // src/openai-embedding-model.ts
1611
+ // src/embedding/openai-embedding-model.ts
1567
1612
  var import_provider5 = require("@ai-sdk/provider");
1568
1613
  var import_provider_utils7 = require("@ai-sdk/provider-utils");
1569
1614
  var import_v49 = require("zod/v4");
1570
1615
 
1571
- // src/openai-embedding-options.ts
1616
+ // src/embedding/openai-embedding-options.ts
1572
1617
  var import_v48 = require("zod/v4");
1573
1618
  var openaiEmbeddingProviderOptions = import_v48.z.object({
1574
1619
  /**
@@ -1583,7 +1628,7 @@ var openaiEmbeddingProviderOptions = import_v48.z.object({
1583
1628
  user: import_v48.z.string().optional()
1584
1629
  });
1585
1630
 
1586
- // src/openai-embedding-model.ts
1631
+ // src/embedding/openai-embedding-model.ts
1587
1632
  var OpenAIEmbeddingModel = class {
1588
1633
  constructor(modelId, config) {
1589
1634
  this.specificationVersion = "v2";
@@ -1651,11 +1696,11 @@ var openaiTextEmbeddingResponseSchema = import_v49.z.object({
1651
1696
  usage: import_v49.z.object({ prompt_tokens: import_v49.z.number() }).nullish()
1652
1697
  });
1653
1698
 
1654
- // src/openai-image-model.ts
1699
+ // src/image/openai-image-model.ts
1655
1700
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
1656
1701
  var import_v410 = require("zod/v4");
1657
1702
 
1658
- // src/openai-image-settings.ts
1703
+ // src/image/openai-image-options.ts
1659
1704
  var modelMaxImagesPerCall = {
1660
1705
  "dall-e-3": 1,
1661
1706
  "dall-e-2": 10,
@@ -1663,7 +1708,7 @@ var modelMaxImagesPerCall = {
1663
1708
  };
1664
1709
  var hasDefaultResponseFormat = /* @__PURE__ */ new Set(["gpt-image-1"]);
1665
1710
 
1666
- // src/openai-image-model.ts
1711
+ // src/image/openai-image-model.ts
1667
1712
  var OpenAIImageModel = class {
1668
1713
  constructor(modelId, config) {
1669
1714
  this.modelId = modelId;
@@ -1747,214 +1792,48 @@ var openaiImageResponseSchema = import_v410.z.object({
1747
1792
  )
1748
1793
  });
1749
1794
 
1750
- // src/openai-tools.ts
1751
- var openaiTools = {
1752
- fileSearch,
1753
- webSearchPreview
1754
- };
1755
-
1756
- // src/openai-transcription-model.ts
1795
+ // src/tool/code-interpreter.ts
1757
1796
  var import_provider_utils9 = require("@ai-sdk/provider-utils");
1758
- var import_v412 = require("zod/v4");
1759
-
1760
- // src/openai-transcription-options.ts
1761
1797
  var import_v411 = require("zod/v4");
1762
- var openAITranscriptionProviderOptions = import_v411.z.object({
1763
- /**
1764
- * Additional information to include in the transcription response.
1765
- */
1766
- include: import_v411.z.array(import_v411.z.string()).optional(),
1767
- /**
1768
- * The language of the input audio in ISO-639-1 format.
1769
- */
1770
- language: import_v411.z.string().optional(),
1771
- /**
1772
- * An optional text to guide the model's style or continue a previous audio segment.
1773
- */
1774
- prompt: import_v411.z.string().optional(),
1775
- /**
1776
- * The sampling temperature, between 0 and 1.
1777
- * @default 0
1778
- */
1779
- temperature: import_v411.z.number().min(0).max(1).default(0).optional(),
1780
- /**
1781
- * The timestamp granularities to populate for this transcription.
1782
- * @default ['segment']
1783
- */
1784
- timestampGranularities: import_v411.z.array(import_v411.z.enum(["word", "segment"])).default(["segment"]).optional()
1798
+ var codeInterpreterArgsSchema = import_v411.z.object({
1799
+ container: import_v411.z.union([
1800
+ import_v411.z.string(),
1801
+ import_v411.z.object({
1802
+ fileIds: import_v411.z.array(import_v411.z.string()).optional()
1803
+ })
1804
+ ]).optional()
1805
+ });
1806
+ var codeInterpreter = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1807
+ id: "openai.code_interpreter",
1808
+ name: "code_interpreter",
1809
+ inputSchema: import_v411.z.object({})
1785
1810
  });
1786
1811
 
1787
- // src/openai-transcription-model.ts
1788
- var languageMap = {
1789
- afrikaans: "af",
1790
- arabic: "ar",
1791
- armenian: "hy",
1792
- azerbaijani: "az",
1793
- belarusian: "be",
1794
- bosnian: "bs",
1795
- bulgarian: "bg",
1796
- catalan: "ca",
1797
- chinese: "zh",
1798
- croatian: "hr",
1799
- czech: "cs",
1800
- danish: "da",
1801
- dutch: "nl",
1802
- english: "en",
1803
- estonian: "et",
1804
- finnish: "fi",
1805
- french: "fr",
1806
- galician: "gl",
1807
- german: "de",
1808
- greek: "el",
1809
- hebrew: "he",
1810
- hindi: "hi",
1811
- hungarian: "hu",
1812
- icelandic: "is",
1813
- indonesian: "id",
1814
- italian: "it",
1815
- japanese: "ja",
1816
- kannada: "kn",
1817
- kazakh: "kk",
1818
- korean: "ko",
1819
- latvian: "lv",
1820
- lithuanian: "lt",
1821
- macedonian: "mk",
1822
- malay: "ms",
1823
- marathi: "mr",
1824
- maori: "mi",
1825
- nepali: "ne",
1826
- norwegian: "no",
1827
- persian: "fa",
1828
- polish: "pl",
1829
- portuguese: "pt",
1830
- romanian: "ro",
1831
- russian: "ru",
1832
- serbian: "sr",
1833
- slovak: "sk",
1834
- slovenian: "sl",
1835
- spanish: "es",
1836
- swahili: "sw",
1837
- swedish: "sv",
1838
- tagalog: "tl",
1839
- tamil: "ta",
1840
- thai: "th",
1841
- turkish: "tr",
1842
- ukrainian: "uk",
1843
- urdu: "ur",
1844
- vietnamese: "vi",
1845
- welsh: "cy"
1846
- };
1847
- var OpenAITranscriptionModel = class {
1848
- constructor(modelId, config) {
1849
- this.modelId = modelId;
1850
- this.config = config;
1851
- this.specificationVersion = "v2";
1852
- }
1853
- get provider() {
1854
- return this.config.provider;
1855
- }
1856
- async getArgs({
1857
- audio,
1858
- mediaType,
1859
- providerOptions
1860
- }) {
1861
- const warnings = [];
1862
- const openAIOptions = await (0, import_provider_utils9.parseProviderOptions)({
1863
- provider: "openai",
1864
- providerOptions,
1865
- schema: openAITranscriptionProviderOptions
1866
- });
1867
- const formData = new FormData();
1868
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils9.convertBase64ToUint8Array)(audio)]);
1869
- formData.append("model", this.modelId);
1870
- formData.append("file", new File([blob], "audio", { type: mediaType }));
1871
- if (openAIOptions) {
1872
- const transcriptionModelOptions = {
1873
- include: openAIOptions.include,
1874
- language: openAIOptions.language,
1875
- prompt: openAIOptions.prompt,
1876
- temperature: openAIOptions.temperature,
1877
- timestamp_granularities: openAIOptions.timestampGranularities
1878
- };
1879
- for (const [key, value] of Object.entries(transcriptionModelOptions)) {
1880
- if (value != null) {
1881
- formData.append(key, String(value));
1882
- }
1883
- }
1884
- }
1885
- return {
1886
- formData,
1887
- warnings
1888
- };
1889
- }
1890
- async doGenerate(options) {
1891
- var _a, _b, _c, _d, _e, _f;
1892
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1893
- const { formData, warnings } = await this.getArgs(options);
1894
- const {
1895
- value: response,
1896
- responseHeaders,
1897
- rawValue: rawResponse
1898
- } = await (0, import_provider_utils9.postFormDataToApi)({
1899
- url: this.config.url({
1900
- path: "/audio/transcriptions",
1901
- modelId: this.modelId
1902
- }),
1903
- headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
1904
- formData,
1905
- failedResponseHandler: openaiFailedResponseHandler,
1906
- successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
1907
- openaiTranscriptionResponseSchema
1908
- ),
1909
- abortSignal: options.abortSignal,
1910
- fetch: this.config.fetch
1911
- });
1912
- const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1913
- return {
1914
- text: response.text,
1915
- segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1916
- text: word.word,
1917
- startSecond: word.start,
1918
- endSecond: word.end
1919
- }))) != null ? _e : [],
1920
- language,
1921
- durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1922
- warnings,
1923
- response: {
1924
- timestamp: currentDate,
1925
- modelId: this.modelId,
1926
- headers: responseHeaders,
1927
- body: rawResponse
1928
- }
1929
- };
1930
- }
1812
+ // src/openai-tools.ts
1813
+ var openaiTools = {
1814
+ codeInterpreter,
1815
+ fileSearch,
1816
+ webSearchPreview
1931
1817
  };
1932
- var openaiTranscriptionResponseSchema = import_v412.z.object({
1933
- text: import_v412.z.string(),
1934
- language: import_v412.z.string().nullish(),
1935
- duration: import_v412.z.number().nullish(),
1936
- words: import_v412.z.array(
1937
- import_v412.z.object({
1938
- word: import_v412.z.string(),
1939
- start: import_v412.z.number(),
1940
- end: import_v412.z.number()
1941
- })
1942
- ).nullish()
1943
- });
1944
1818
 
1945
1819
  // src/responses/openai-responses-language-model.ts
1946
1820
  var import_provider8 = require("@ai-sdk/provider");
1947
1821
  var import_provider_utils12 = require("@ai-sdk/provider-utils");
1948
- var import_v414 = require("zod/v4");
1822
+ var import_v413 = require("zod/v4");
1949
1823
 
1950
1824
  // src/responses/convert-to-openai-responses-messages.ts
1951
1825
  var import_provider6 = require("@ai-sdk/provider");
1952
1826
  var import_provider_utils10 = require("@ai-sdk/provider-utils");
1953
- var import_v413 = require("zod/v4");
1827
+ var import_v412 = require("zod/v4");
1954
1828
  var import_provider_utils11 = require("@ai-sdk/provider-utils");
1829
+ function isFileId(data, prefixes) {
1830
+ if (!prefixes) return false;
1831
+ return prefixes.some((prefix) => data.startsWith(prefix));
1832
+ }
1955
1833
  async function convertToOpenAIResponsesMessages({
1956
1834
  prompt,
1957
- systemMessageMode
1835
+ systemMessageMode,
1836
+ fileIdPrefixes
1958
1837
  }) {
1959
1838
  var _a, _b, _c, _d, _e, _f;
1960
1839
  const messages = [];
@@ -2001,7 +1880,7 @@ async function convertToOpenAIResponsesMessages({
2001
1880
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
2002
1881
  return {
2003
1882
  type: "input_image",
2004
- ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
1883
+ ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2005
1884
  image_url: `data:${mediaType};base64,${(0, import_provider_utils11.convertToBase64)(part.data)}`
2006
1885
  },
2007
1886
  detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
@@ -2014,7 +1893,7 @@ async function convertToOpenAIResponsesMessages({
2014
1893
  }
2015
1894
  return {
2016
1895
  type: "input_file",
2017
- ...typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
1896
+ ...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2018
1897
  filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
2019
1898
  file_data: `data:application/pdf;base64,${(0, import_provider_utils11.convertToBase64)(part.data)}`
2020
1899
  }
@@ -2134,9 +2013,9 @@ async function convertToOpenAIResponsesMessages({
2134
2013
  }
2135
2014
  return { messages, warnings };
2136
2015
  }
2137
- var openaiResponsesReasoningProviderOptionsSchema = import_v413.z.object({
2138
- itemId: import_v413.z.string().nullish(),
2139
- reasoningEncryptedContent: import_v413.z.string().nullish()
2016
+ var openaiResponsesReasoningProviderOptionsSchema = import_v412.z.object({
2017
+ itemId: import_v412.z.string().nullish(),
2018
+ reasoningEncryptedContent: import_v412.z.string().nullish()
2140
2019
  });
2141
2020
 
2142
2021
  // src/responses/map-openai-responses-finish-reason.ts
@@ -2181,7 +2060,7 @@ function prepareResponsesTools({
2181
2060
  strict: strictJsonSchema
2182
2061
  });
2183
2062
  break;
2184
- case "provider-defined":
2063
+ case "provider-defined": {
2185
2064
  switch (tool.id) {
2186
2065
  case "openai.file_search": {
2187
2066
  const args = fileSearchArgsSchema.parse(tool.args);
@@ -2194,18 +2073,30 @@ function prepareResponsesTools({
2194
2073
  });
2195
2074
  break;
2196
2075
  }
2197
- case "openai.web_search_preview":
2076
+ case "openai.web_search_preview": {
2077
+ const args = webSearchPreviewArgsSchema.parse(tool.args);
2198
2078
  openaiTools2.push({
2199
2079
  type: "web_search_preview",
2200
- search_context_size: tool.args.searchContextSize,
2201
- user_location: tool.args.userLocation
2080
+ search_context_size: args.searchContextSize,
2081
+ user_location: args.userLocation
2202
2082
  });
2203
2083
  break;
2204
- default:
2084
+ }
2085
+ case "openai.code_interpreter": {
2086
+ const args = codeInterpreterArgsSchema.parse(tool.args);
2087
+ openaiTools2.push({
2088
+ type: "code_interpreter",
2089
+ container: args.container == null ? { type: "auto", file_ids: void 0 } : typeof args.container === "string" ? args.container : { type: "auto", file_ids: args.container.fileIds }
2090
+ });
2091
+ break;
2092
+ }
2093
+ default: {
2205
2094
  toolWarnings.push({ type: "unsupported-tool", tool });
2206
2095
  break;
2096
+ }
2207
2097
  }
2208
2098
  break;
2099
+ }
2209
2100
  default:
2210
2101
  toolWarnings.push({ type: "unsupported-tool", tool });
2211
2102
  break;
@@ -2223,7 +2114,7 @@ function prepareResponsesTools({
2223
2114
  case "tool":
2224
2115
  return {
2225
2116
  tools: openaiTools2,
2226
- toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
2117
+ toolChoice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "web_search_preview" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
2227
2118
  toolWarnings
2228
2119
  };
2229
2120
  default: {
@@ -2289,7 +2180,8 @@ var OpenAIResponsesLanguageModel = class {
2289
2180
  }
2290
2181
  const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
2291
2182
  prompt,
2292
- systemMessageMode: modelConfig.systemMessageMode
2183
+ systemMessageMode: modelConfig.systemMessageMode,
2184
+ fileIdPrefixes: this.config.fileIdPrefixes
2293
2185
  });
2294
2186
  warnings.push(...messageWarnings);
2295
2187
  const openaiOptions = await (0, import_provider_utils12.parseProviderOptions)({
@@ -2329,6 +2221,8 @@ var OpenAIResponsesLanguageModel = class {
2329
2221
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2330
2222
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2331
2223
  include: openaiOptions == null ? void 0 : openaiOptions.include,
2224
+ prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
2225
+ safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
2332
2226
  // model-specific settings:
2333
2227
  ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2334
2228
  reasoning: {
@@ -2428,72 +2322,83 @@ var OpenAIResponsesLanguageModel = class {
2428
2322
  body,
2429
2323
  failedResponseHandler: openaiFailedResponseHandler,
2430
2324
  successfulResponseHandler: (0, import_provider_utils12.createJsonResponseHandler)(
2431
- import_v414.z.object({
2432
- id: import_v414.z.string(),
2433
- created_at: import_v414.z.number(),
2434
- error: import_v414.z.object({
2435
- code: import_v414.z.string(),
2436
- message: import_v414.z.string()
2325
+ import_v413.z.object({
2326
+ id: import_v413.z.string(),
2327
+ created_at: import_v413.z.number(),
2328
+ error: import_v413.z.object({
2329
+ code: import_v413.z.string(),
2330
+ message: import_v413.z.string()
2437
2331
  }).nullish(),
2438
- model: import_v414.z.string(),
2439
- output: import_v414.z.array(
2440
- import_v414.z.discriminatedUnion("type", [
2441
- import_v414.z.object({
2442
- type: import_v414.z.literal("message"),
2443
- role: import_v414.z.literal("assistant"),
2444
- id: import_v414.z.string(),
2445
- content: import_v414.z.array(
2446
- import_v414.z.object({
2447
- type: import_v414.z.literal("output_text"),
2448
- text: import_v414.z.string(),
2449
- annotations: import_v414.z.array(
2450
- import_v414.z.object({
2451
- type: import_v414.z.literal("url_citation"),
2452
- start_index: import_v414.z.number(),
2453
- end_index: import_v414.z.number(),
2454
- url: import_v414.z.string(),
2455
- title: import_v414.z.string()
2332
+ model: import_v413.z.string(),
2333
+ output: import_v413.z.array(
2334
+ import_v413.z.discriminatedUnion("type", [
2335
+ import_v413.z.object({
2336
+ type: import_v413.z.literal("message"),
2337
+ role: import_v413.z.literal("assistant"),
2338
+ id: import_v413.z.string(),
2339
+ content: import_v413.z.array(
2340
+ import_v413.z.object({
2341
+ type: import_v413.z.literal("output_text"),
2342
+ text: import_v413.z.string(),
2343
+ annotations: import_v413.z.array(
2344
+ import_v413.z.object({
2345
+ type: import_v413.z.literal("url_citation"),
2346
+ start_index: import_v413.z.number(),
2347
+ end_index: import_v413.z.number(),
2348
+ url: import_v413.z.string(),
2349
+ title: import_v413.z.string()
2456
2350
  })
2457
2351
  )
2458
2352
  })
2459
2353
  )
2460
2354
  }),
2461
- import_v414.z.object({
2462
- type: import_v414.z.literal("function_call"),
2463
- call_id: import_v414.z.string(),
2464
- name: import_v414.z.string(),
2465
- arguments: import_v414.z.string(),
2466
- id: import_v414.z.string()
2355
+ import_v413.z.object({
2356
+ type: import_v413.z.literal("function_call"),
2357
+ call_id: import_v413.z.string(),
2358
+ name: import_v413.z.string(),
2359
+ arguments: import_v413.z.string(),
2360
+ id: import_v413.z.string()
2467
2361
  }),
2468
- import_v414.z.object({
2469
- type: import_v414.z.literal("web_search_call"),
2470
- id: import_v414.z.string(),
2471
- status: import_v414.z.string().optional()
2362
+ import_v413.z.object({
2363
+ type: import_v413.z.literal("web_search_call"),
2364
+ id: import_v413.z.string(),
2365
+ status: import_v413.z.string().optional()
2472
2366
  }),
2473
- import_v414.z.object({
2474
- type: import_v414.z.literal("computer_call"),
2475
- id: import_v414.z.string(),
2476
- status: import_v414.z.string().optional()
2367
+ import_v413.z.object({
2368
+ type: import_v413.z.literal("computer_call"),
2369
+ id: import_v413.z.string(),
2370
+ status: import_v413.z.string().optional()
2477
2371
  }),
2478
- import_v414.z.object({
2479
- type: import_v414.z.literal("file_search_call"),
2480
- id: import_v414.z.string(),
2481
- status: import_v414.z.string().optional()
2372
+ import_v413.z.object({
2373
+ type: import_v413.z.literal("file_search_call"),
2374
+ id: import_v413.z.string(),
2375
+ status: import_v413.z.string().optional(),
2376
+ queries: import_v413.z.array(import_v413.z.string()).nullish(),
2377
+ results: import_v413.z.array(
2378
+ import_v413.z.object({
2379
+ attributes: import_v413.z.object({
2380
+ file_id: import_v413.z.string(),
2381
+ filename: import_v413.z.string(),
2382
+ score: import_v413.z.number(),
2383
+ text: import_v413.z.string()
2384
+ })
2385
+ })
2386
+ ).nullish()
2482
2387
  }),
2483
- import_v414.z.object({
2484
- type: import_v414.z.literal("reasoning"),
2485
- id: import_v414.z.string(),
2486
- encrypted_content: import_v414.z.string().nullish(),
2487
- summary: import_v414.z.array(
2488
- import_v414.z.object({
2489
- type: import_v414.z.literal("summary_text"),
2490
- text: import_v414.z.string()
2388
+ import_v413.z.object({
2389
+ type: import_v413.z.literal("reasoning"),
2390
+ id: import_v413.z.string(),
2391
+ encrypted_content: import_v413.z.string().nullish(),
2392
+ summary: import_v413.z.array(
2393
+ import_v413.z.object({
2394
+ type: import_v413.z.literal("summary_text"),
2395
+ text: import_v413.z.string()
2491
2396
  })
2492
2397
  )
2493
2398
  })
2494
2399
  ])
2495
2400
  ),
2496
- incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullable(),
2401
+ incomplete_details: import_v413.z.object({ reason: import_v413.z.string() }).nullable(),
2497
2402
  usage: usageSchema2
2498
2403
  })
2499
2404
  ),
@@ -2620,7 +2525,9 @@ var OpenAIResponsesLanguageModel = class {
2620
2525
  toolName: "file_search",
2621
2526
  result: {
2622
2527
  type: "file_search_tool_result",
2623
- status: part.status || "completed"
2528
+ status: part.status || "completed",
2529
+ ...part.queries && { queries: part.queries },
2530
+ ...part.results && { results: part.results }
2624
2531
  },
2625
2532
  providerExecuted: true
2626
2533
  });
@@ -2735,6 +2642,16 @@ var OpenAIResponsesLanguageModel = class {
2735
2642
  id: value.item.id,
2736
2643
  toolName: "computer_use"
2737
2644
  });
2645
+ } else if (value.item.type === "file_search_call") {
2646
+ ongoingToolCalls[value.output_index] = {
2647
+ toolName: "file_search",
2648
+ toolCallId: value.item.id
2649
+ };
2650
+ controller.enqueue({
2651
+ type: "tool-input-start",
2652
+ id: value.item.id,
2653
+ toolName: "file_search"
2654
+ });
2738
2655
  } else if (value.item.type === "message") {
2739
2656
  controller.enqueue({
2740
2657
  type: "text-start",
@@ -2828,6 +2745,32 @@ var OpenAIResponsesLanguageModel = class {
2828
2745
  },
2829
2746
  providerExecuted: true
2830
2747
  });
2748
+ } else if (value.item.type === "file_search_call") {
2749
+ ongoingToolCalls[value.output_index] = void 0;
2750
+ hasToolCalls = true;
2751
+ controller.enqueue({
2752
+ type: "tool-input-end",
2753
+ id: value.item.id
2754
+ });
2755
+ controller.enqueue({
2756
+ type: "tool-call",
2757
+ toolCallId: value.item.id,
2758
+ toolName: "file_search",
2759
+ input: "",
2760
+ providerExecuted: true
2761
+ });
2762
+ controller.enqueue({
2763
+ type: "tool-result",
2764
+ toolCallId: value.item.id,
2765
+ toolName: "file_search",
2766
+ result: {
2767
+ type: "file_search_tool_result",
2768
+ status: value.item.status || "completed",
2769
+ ...value.item.queries && { queries: value.item.queries },
2770
+ ...value.item.results && { results: value.item.results }
2771
+ },
2772
+ providerExecuted: true
2773
+ });
2831
2774
  } else if (value.item.type === "message") {
2832
2775
  controller.enqueue({
2833
2776
  type: "text-end",
@@ -2940,140 +2883,162 @@ var OpenAIResponsesLanguageModel = class {
2940
2883
  };
2941
2884
  }
2942
2885
  };
2943
- var usageSchema2 = import_v414.z.object({
2944
- input_tokens: import_v414.z.number(),
2945
- input_tokens_details: import_v414.z.object({ cached_tokens: import_v414.z.number().nullish() }).nullish(),
2946
- output_tokens: import_v414.z.number(),
2947
- output_tokens_details: import_v414.z.object({ reasoning_tokens: import_v414.z.number().nullish() }).nullish()
2886
+ var usageSchema2 = import_v413.z.object({
2887
+ input_tokens: import_v413.z.number(),
2888
+ input_tokens_details: import_v413.z.object({ cached_tokens: import_v413.z.number().nullish() }).nullish(),
2889
+ output_tokens: import_v413.z.number(),
2890
+ output_tokens_details: import_v413.z.object({ reasoning_tokens: import_v413.z.number().nullish() }).nullish()
2948
2891
  });
2949
- var textDeltaChunkSchema = import_v414.z.object({
2950
- type: import_v414.z.literal("response.output_text.delta"),
2951
- item_id: import_v414.z.string(),
2952
- delta: import_v414.z.string()
2892
+ var textDeltaChunkSchema = import_v413.z.object({
2893
+ type: import_v413.z.literal("response.output_text.delta"),
2894
+ item_id: import_v413.z.string(),
2895
+ delta: import_v413.z.string()
2953
2896
  });
2954
- var errorChunkSchema = import_v414.z.object({
2955
- type: import_v414.z.literal("error"),
2956
- code: import_v414.z.string(),
2957
- message: import_v414.z.string(),
2958
- param: import_v414.z.string().nullish(),
2959
- sequence_number: import_v414.z.number()
2897
+ var errorChunkSchema = import_v413.z.object({
2898
+ type: import_v413.z.literal("error"),
2899
+ code: import_v413.z.string(),
2900
+ message: import_v413.z.string(),
2901
+ param: import_v413.z.string().nullish(),
2902
+ sequence_number: import_v413.z.number()
2960
2903
  });
2961
- var responseFinishedChunkSchema = import_v414.z.object({
2962
- type: import_v414.z.enum(["response.completed", "response.incomplete"]),
2963
- response: import_v414.z.object({
2964
- incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullish(),
2904
+ var responseFinishedChunkSchema = import_v413.z.object({
2905
+ type: import_v413.z.enum(["response.completed", "response.incomplete"]),
2906
+ response: import_v413.z.object({
2907
+ incomplete_details: import_v413.z.object({ reason: import_v413.z.string() }).nullish(),
2965
2908
  usage: usageSchema2
2966
2909
  })
2967
2910
  });
2968
- var responseCreatedChunkSchema = import_v414.z.object({
2969
- type: import_v414.z.literal("response.created"),
2970
- response: import_v414.z.object({
2971
- id: import_v414.z.string(),
2972
- created_at: import_v414.z.number(),
2973
- model: import_v414.z.string()
2911
+ var responseCreatedChunkSchema = import_v413.z.object({
2912
+ type: import_v413.z.literal("response.created"),
2913
+ response: import_v413.z.object({
2914
+ id: import_v413.z.string(),
2915
+ created_at: import_v413.z.number(),
2916
+ model: import_v413.z.string()
2974
2917
  })
2975
2918
  });
2976
- var responseOutputItemAddedSchema = import_v414.z.object({
2977
- type: import_v414.z.literal("response.output_item.added"),
2978
- output_index: import_v414.z.number(),
2979
- item: import_v414.z.discriminatedUnion("type", [
2980
- import_v414.z.object({
2981
- type: import_v414.z.literal("message"),
2982
- id: import_v414.z.string()
2919
+ var responseOutputItemAddedSchema = import_v413.z.object({
2920
+ type: import_v413.z.literal("response.output_item.added"),
2921
+ output_index: import_v413.z.number(),
2922
+ item: import_v413.z.discriminatedUnion("type", [
2923
+ import_v413.z.object({
2924
+ type: import_v413.z.literal("message"),
2925
+ id: import_v413.z.string()
2983
2926
  }),
2984
- import_v414.z.object({
2985
- type: import_v414.z.literal("reasoning"),
2986
- id: import_v414.z.string(),
2987
- encrypted_content: import_v414.z.string().nullish()
2927
+ import_v413.z.object({
2928
+ type: import_v413.z.literal("reasoning"),
2929
+ id: import_v413.z.string(),
2930
+ encrypted_content: import_v413.z.string().nullish()
2988
2931
  }),
2989
- import_v414.z.object({
2990
- type: import_v414.z.literal("function_call"),
2991
- id: import_v414.z.string(),
2992
- call_id: import_v414.z.string(),
2993
- name: import_v414.z.string(),
2994
- arguments: import_v414.z.string()
2932
+ import_v413.z.object({
2933
+ type: import_v413.z.literal("function_call"),
2934
+ id: import_v413.z.string(),
2935
+ call_id: import_v413.z.string(),
2936
+ name: import_v413.z.string(),
2937
+ arguments: import_v413.z.string()
2995
2938
  }),
2996
- import_v414.z.object({
2997
- type: import_v414.z.literal("web_search_call"),
2998
- id: import_v414.z.string(),
2999
- status: import_v414.z.string()
2939
+ import_v413.z.object({
2940
+ type: import_v413.z.literal("web_search_call"),
2941
+ id: import_v413.z.string(),
2942
+ status: import_v413.z.string()
3000
2943
  }),
3001
- import_v414.z.object({
3002
- type: import_v414.z.literal("computer_call"),
3003
- id: import_v414.z.string(),
3004
- status: import_v414.z.string()
2944
+ import_v413.z.object({
2945
+ type: import_v413.z.literal("computer_call"),
2946
+ id: import_v413.z.string(),
2947
+ status: import_v413.z.string()
3005
2948
  }),
3006
- import_v414.z.object({
3007
- type: import_v414.z.literal("file_search_call"),
3008
- id: import_v414.z.string(),
3009
- status: import_v414.z.string()
2949
+ import_v413.z.object({
2950
+ type: import_v413.z.literal("file_search_call"),
2951
+ id: import_v413.z.string(),
2952
+ status: import_v413.z.string(),
2953
+ queries: import_v413.z.array(import_v413.z.string()).nullish(),
2954
+ results: import_v413.z.array(
2955
+ import_v413.z.object({
2956
+ attributes: import_v413.z.object({
2957
+ file_id: import_v413.z.string(),
2958
+ filename: import_v413.z.string(),
2959
+ score: import_v413.z.number(),
2960
+ text: import_v413.z.string()
2961
+ })
2962
+ })
2963
+ ).optional()
3010
2964
  })
3011
2965
  ])
3012
2966
  });
3013
- var responseOutputItemDoneSchema = import_v414.z.object({
3014
- type: import_v414.z.literal("response.output_item.done"),
3015
- output_index: import_v414.z.number(),
3016
- item: import_v414.z.discriminatedUnion("type", [
3017
- import_v414.z.object({
3018
- type: import_v414.z.literal("message"),
3019
- id: import_v414.z.string()
2967
+ var responseOutputItemDoneSchema = import_v413.z.object({
2968
+ type: import_v413.z.literal("response.output_item.done"),
2969
+ output_index: import_v413.z.number(),
2970
+ item: import_v413.z.discriminatedUnion("type", [
2971
+ import_v413.z.object({
2972
+ type: import_v413.z.literal("message"),
2973
+ id: import_v413.z.string()
3020
2974
  }),
3021
- import_v414.z.object({
3022
- type: import_v414.z.literal("reasoning"),
3023
- id: import_v414.z.string(),
3024
- encrypted_content: import_v414.z.string().nullish()
2975
+ import_v413.z.object({
2976
+ type: import_v413.z.literal("reasoning"),
2977
+ id: import_v413.z.string(),
2978
+ encrypted_content: import_v413.z.string().nullish()
3025
2979
  }),
3026
- import_v414.z.object({
3027
- type: import_v414.z.literal("function_call"),
3028
- id: import_v414.z.string(),
3029
- call_id: import_v414.z.string(),
3030
- name: import_v414.z.string(),
3031
- arguments: import_v414.z.string(),
3032
- status: import_v414.z.literal("completed")
2980
+ import_v413.z.object({
2981
+ type: import_v413.z.literal("function_call"),
2982
+ id: import_v413.z.string(),
2983
+ call_id: import_v413.z.string(),
2984
+ name: import_v413.z.string(),
2985
+ arguments: import_v413.z.string(),
2986
+ status: import_v413.z.literal("completed")
3033
2987
  }),
3034
- import_v414.z.object({
3035
- type: import_v414.z.literal("web_search_call"),
3036
- id: import_v414.z.string(),
3037
- status: import_v414.z.literal("completed")
2988
+ import_v413.z.object({
2989
+ type: import_v413.z.literal("web_search_call"),
2990
+ id: import_v413.z.string(),
2991
+ status: import_v413.z.literal("completed")
3038
2992
  }),
3039
- import_v414.z.object({
3040
- type: import_v414.z.literal("computer_call"),
3041
- id: import_v414.z.string(),
3042
- status: import_v414.z.literal("completed")
2993
+ import_v413.z.object({
2994
+ type: import_v413.z.literal("computer_call"),
2995
+ id: import_v413.z.string(),
2996
+ status: import_v413.z.literal("completed")
3043
2997
  }),
3044
- import_v414.z.object({
3045
- type: import_v414.z.literal("file_search_call"),
3046
- id: import_v414.z.string(),
3047
- status: import_v414.z.literal("completed")
2998
+ import_v413.z.object({
2999
+ type: import_v413.z.literal("file_search_call"),
3000
+ id: import_v413.z.string(),
3001
+ status: import_v413.z.literal("completed"),
3002
+ queries: import_v413.z.array(import_v413.z.string()).nullish(),
3003
+ results: import_v413.z.array(
3004
+ import_v413.z.object({
3005
+ attributes: import_v413.z.object({
3006
+ file_id: import_v413.z.string(),
3007
+ filename: import_v413.z.string(),
3008
+ score: import_v413.z.number(),
3009
+ text: import_v413.z.string()
3010
+ })
3011
+ })
3012
+ ).nullish()
3048
3013
  })
3049
3014
  ])
3050
3015
  });
3051
- var responseFunctionCallArgumentsDeltaSchema = import_v414.z.object({
3052
- type: import_v414.z.literal("response.function_call_arguments.delta"),
3053
- item_id: import_v414.z.string(),
3054
- output_index: import_v414.z.number(),
3055
- delta: import_v414.z.string()
3016
+ var responseFunctionCallArgumentsDeltaSchema = import_v413.z.object({
3017
+ type: import_v413.z.literal("response.function_call_arguments.delta"),
3018
+ item_id: import_v413.z.string(),
3019
+ output_index: import_v413.z.number(),
3020
+ delta: import_v413.z.string()
3056
3021
  });
3057
- var responseAnnotationAddedSchema = import_v414.z.object({
3058
- type: import_v414.z.literal("response.output_text.annotation.added"),
3059
- annotation: import_v414.z.object({
3060
- type: import_v414.z.literal("url_citation"),
3061
- url: import_v414.z.string(),
3062
- title: import_v414.z.string()
3022
+ var responseAnnotationAddedSchema = import_v413.z.object({
3023
+ type: import_v413.z.literal("response.output_text.annotation.added"),
3024
+ annotation: import_v413.z.object({
3025
+ type: import_v413.z.literal("url_citation"),
3026
+ url: import_v413.z.string(),
3027
+ title: import_v413.z.string()
3063
3028
  })
3064
3029
  });
3065
- var responseReasoningSummaryPartAddedSchema = import_v414.z.object({
3066
- type: import_v414.z.literal("response.reasoning_summary_part.added"),
3067
- item_id: import_v414.z.string(),
3068
- summary_index: import_v414.z.number()
3030
+ var responseReasoningSummaryPartAddedSchema = import_v413.z.object({
3031
+ type: import_v413.z.literal("response.reasoning_summary_part.added"),
3032
+ item_id: import_v413.z.string(),
3033
+ summary_index: import_v413.z.number()
3069
3034
  });
3070
- var responseReasoningSummaryTextDeltaSchema = import_v414.z.object({
3071
- type: import_v414.z.literal("response.reasoning_summary_text.delta"),
3072
- item_id: import_v414.z.string(),
3073
- summary_index: import_v414.z.number(),
3074
- delta: import_v414.z.string()
3035
+ var responseReasoningSummaryTextDeltaSchema = import_v413.z.object({
3036
+ type: import_v413.z.literal("response.reasoning_summary_text.delta"),
3037
+ item_id: import_v413.z.string(),
3038
+ summary_index: import_v413.z.number(),
3039
+ delta: import_v413.z.string()
3075
3040
  });
3076
- var openaiResponsesChunkSchema = import_v414.z.union([
3041
+ var openaiResponsesChunkSchema = import_v413.z.union([
3077
3042
  textDeltaChunkSchema,
3078
3043
  responseFinishedChunkSchema,
3079
3044
  responseCreatedChunkSchema,
@@ -3084,7 +3049,7 @@ var openaiResponsesChunkSchema = import_v414.z.union([
3084
3049
  responseReasoningSummaryPartAddedSchema,
3085
3050
  responseReasoningSummaryTextDeltaSchema,
3086
3051
  errorChunkSchema,
3087
- import_v414.z.object({ type: import_v414.z.string() }).loose()
3052
+ import_v413.z.object({ type: import_v413.z.string() }).loose()
3088
3053
  // fallback for unknown chunks
3089
3054
  ]);
3090
3055
  function isTextDeltaChunk(chunk) {
@@ -3150,27 +3115,29 @@ function supportsFlexProcessing2(modelId) {
3150
3115
  function supportsPriorityProcessing2(modelId) {
3151
3116
  return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3152
3117
  }
3153
- var openaiResponsesProviderOptionsSchema = import_v414.z.object({
3154
- metadata: import_v414.z.any().nullish(),
3155
- parallelToolCalls: import_v414.z.boolean().nullish(),
3156
- previousResponseId: import_v414.z.string().nullish(),
3157
- store: import_v414.z.boolean().nullish(),
3158
- user: import_v414.z.string().nullish(),
3159
- reasoningEffort: import_v414.z.string().nullish(),
3160
- strictJsonSchema: import_v414.z.boolean().nullish(),
3161
- instructions: import_v414.z.string().nullish(),
3162
- reasoningSummary: import_v414.z.string().nullish(),
3163
- serviceTier: import_v414.z.enum(["auto", "flex", "priority"]).nullish(),
3164
- include: import_v414.z.array(import_v414.z.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish(),
3165
- textVerbosity: import_v414.z.enum(["low", "medium", "high"]).nullish()
3118
+ var openaiResponsesProviderOptionsSchema = import_v413.z.object({
3119
+ metadata: import_v413.z.any().nullish(),
3120
+ parallelToolCalls: import_v413.z.boolean().nullish(),
3121
+ previousResponseId: import_v413.z.string().nullish(),
3122
+ store: import_v413.z.boolean().nullish(),
3123
+ user: import_v413.z.string().nullish(),
3124
+ reasoningEffort: import_v413.z.string().nullish(),
3125
+ strictJsonSchema: import_v413.z.boolean().nullish(),
3126
+ instructions: import_v413.z.string().nullish(),
3127
+ reasoningSummary: import_v413.z.string().nullish(),
3128
+ serviceTier: import_v413.z.enum(["auto", "flex", "priority"]).nullish(),
3129
+ include: import_v413.z.array(import_v413.z.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish(),
3130
+ textVerbosity: import_v413.z.enum(["low", "medium", "high"]).nullish(),
3131
+ promptCacheKey: import_v413.z.string().nullish(),
3132
+ safetyIdentifier: import_v413.z.string().nullish()
3166
3133
  });
3167
3134
 
3168
- // src/openai-speech-model.ts
3135
+ // src/speech/openai-speech-model.ts
3169
3136
  var import_provider_utils13 = require("@ai-sdk/provider-utils");
3170
- var import_v415 = require("zod/v4");
3171
- var OpenAIProviderOptionsSchema = import_v415.z.object({
3172
- instructions: import_v415.z.string().nullish(),
3173
- speed: import_v415.z.number().min(0.25).max(4).default(1).nullish()
3137
+ var import_v414 = require("zod/v4");
3138
+ var OpenAIProviderOptionsSchema = import_v414.z.object({
3139
+ instructions: import_v414.z.string().nullish(),
3140
+ speed: import_v414.z.number().min(0.25).max(4).default(1).nullish()
3174
3141
  });
3175
3142
  var OpenAISpeechModel = class {
3176
3143
  constructor(modelId, config) {
@@ -3272,13 +3239,202 @@ var OpenAISpeechModel = class {
3272
3239
  }
3273
3240
  };
3274
3241
 
3242
+ // src/transcription/openai-transcription-model.ts
3243
+ var import_provider_utils14 = require("@ai-sdk/provider-utils");
3244
+ var import_v416 = require("zod/v4");
3245
+
3246
+ // src/transcription/openai-transcription-options.ts
3247
+ var import_v415 = require("zod/v4");
3248
+ var openAITranscriptionProviderOptions = import_v415.z.object({
3249
+ /**
3250
+ * Additional information to include in the transcription response.
3251
+ */
3252
+ include: import_v415.z.array(import_v415.z.string()).optional(),
3253
+ /**
3254
+ * The language of the input audio in ISO-639-1 format.
3255
+ */
3256
+ language: import_v415.z.string().optional(),
3257
+ /**
3258
+ * An optional text to guide the model's style or continue a previous audio segment.
3259
+ */
3260
+ prompt: import_v415.z.string().optional(),
3261
+ /**
3262
+ * The sampling temperature, between 0 and 1.
3263
+ * @default 0
3264
+ */
3265
+ temperature: import_v415.z.number().min(0).max(1).default(0).optional(),
3266
+ /**
3267
+ * The timestamp granularities to populate for this transcription.
3268
+ * @default ['segment']
3269
+ */
3270
+ timestampGranularities: import_v415.z.array(import_v415.z.enum(["word", "segment"])).default(["segment"]).optional()
3271
+ });
3272
+
3273
+ // src/transcription/openai-transcription-model.ts
3274
+ var languageMap = {
3275
+ afrikaans: "af",
3276
+ arabic: "ar",
3277
+ armenian: "hy",
3278
+ azerbaijani: "az",
3279
+ belarusian: "be",
3280
+ bosnian: "bs",
3281
+ bulgarian: "bg",
3282
+ catalan: "ca",
3283
+ chinese: "zh",
3284
+ croatian: "hr",
3285
+ czech: "cs",
3286
+ danish: "da",
3287
+ dutch: "nl",
3288
+ english: "en",
3289
+ estonian: "et",
3290
+ finnish: "fi",
3291
+ french: "fr",
3292
+ galician: "gl",
3293
+ german: "de",
3294
+ greek: "el",
3295
+ hebrew: "he",
3296
+ hindi: "hi",
3297
+ hungarian: "hu",
3298
+ icelandic: "is",
3299
+ indonesian: "id",
3300
+ italian: "it",
3301
+ japanese: "ja",
3302
+ kannada: "kn",
3303
+ kazakh: "kk",
3304
+ korean: "ko",
3305
+ latvian: "lv",
3306
+ lithuanian: "lt",
3307
+ macedonian: "mk",
3308
+ malay: "ms",
3309
+ marathi: "mr",
3310
+ maori: "mi",
3311
+ nepali: "ne",
3312
+ norwegian: "no",
3313
+ persian: "fa",
3314
+ polish: "pl",
3315
+ portuguese: "pt",
3316
+ romanian: "ro",
3317
+ russian: "ru",
3318
+ serbian: "sr",
3319
+ slovak: "sk",
3320
+ slovenian: "sl",
3321
+ spanish: "es",
3322
+ swahili: "sw",
3323
+ swedish: "sv",
3324
+ tagalog: "tl",
3325
+ tamil: "ta",
3326
+ thai: "th",
3327
+ turkish: "tr",
3328
+ ukrainian: "uk",
3329
+ urdu: "ur",
3330
+ vietnamese: "vi",
3331
+ welsh: "cy"
3332
+ };
3333
+ var OpenAITranscriptionModel = class {
3334
+ constructor(modelId, config) {
3335
+ this.modelId = modelId;
3336
+ this.config = config;
3337
+ this.specificationVersion = "v2";
3338
+ }
3339
+ get provider() {
3340
+ return this.config.provider;
3341
+ }
3342
+ async getArgs({
3343
+ audio,
3344
+ mediaType,
3345
+ providerOptions
3346
+ }) {
3347
+ const warnings = [];
3348
+ const openAIOptions = await (0, import_provider_utils14.parseProviderOptions)({
3349
+ provider: "openai",
3350
+ providerOptions,
3351
+ schema: openAITranscriptionProviderOptions
3352
+ });
3353
+ const formData = new FormData();
3354
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils14.convertBase64ToUint8Array)(audio)]);
3355
+ formData.append("model", this.modelId);
3356
+ formData.append("file", new File([blob], "audio", { type: mediaType }));
3357
+ if (openAIOptions) {
3358
+ const transcriptionModelOptions = {
3359
+ include: openAIOptions.include,
3360
+ language: openAIOptions.language,
3361
+ prompt: openAIOptions.prompt,
3362
+ temperature: openAIOptions.temperature,
3363
+ timestamp_granularities: openAIOptions.timestampGranularities
3364
+ };
3365
+ for (const [key, value] of Object.entries(transcriptionModelOptions)) {
3366
+ if (value != null) {
3367
+ formData.append(key, String(value));
3368
+ }
3369
+ }
3370
+ }
3371
+ return {
3372
+ formData,
3373
+ warnings
3374
+ };
3375
+ }
3376
+ async doGenerate(options) {
3377
+ var _a, _b, _c, _d, _e, _f;
3378
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
3379
+ const { formData, warnings } = await this.getArgs(options);
3380
+ const {
3381
+ value: response,
3382
+ responseHeaders,
3383
+ rawValue: rawResponse
3384
+ } = await (0, import_provider_utils14.postFormDataToApi)({
3385
+ url: this.config.url({
3386
+ path: "/audio/transcriptions",
3387
+ modelId: this.modelId
3388
+ }),
3389
+ headers: (0, import_provider_utils14.combineHeaders)(this.config.headers(), options.headers),
3390
+ formData,
3391
+ failedResponseHandler: openaiFailedResponseHandler,
3392
+ successfulResponseHandler: (0, import_provider_utils14.createJsonResponseHandler)(
3393
+ openaiTranscriptionResponseSchema
3394
+ ),
3395
+ abortSignal: options.abortSignal,
3396
+ fetch: this.config.fetch
3397
+ });
3398
+ const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
3399
+ return {
3400
+ text: response.text,
3401
+ segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
3402
+ text: word.word,
3403
+ startSecond: word.start,
3404
+ endSecond: word.end
3405
+ }))) != null ? _e : [],
3406
+ language,
3407
+ durationInSeconds: (_f = response.duration) != null ? _f : void 0,
3408
+ warnings,
3409
+ response: {
3410
+ timestamp: currentDate,
3411
+ modelId: this.modelId,
3412
+ headers: responseHeaders,
3413
+ body: rawResponse
3414
+ }
3415
+ };
3416
+ }
3417
+ };
3418
+ var openaiTranscriptionResponseSchema = import_v416.z.object({
3419
+ text: import_v416.z.string(),
3420
+ language: import_v416.z.string().nullish(),
3421
+ duration: import_v416.z.number().nullish(),
3422
+ words: import_v416.z.array(
3423
+ import_v416.z.object({
3424
+ word: import_v416.z.string(),
3425
+ start: import_v416.z.number(),
3426
+ end: import_v416.z.number()
3427
+ })
3428
+ ).nullish()
3429
+ });
3430
+
3275
3431
  // src/openai-provider.ts
3276
3432
  function createOpenAI(options = {}) {
3277
3433
  var _a, _b;
3278
- const baseURL = (_a = (0, import_provider_utils14.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
3434
+ const baseURL = (_a = (0, import_provider_utils15.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
3279
3435
  const providerName = (_b = options.name) != null ? _b : "openai";
3280
3436
  const getHeaders = () => ({
3281
- Authorization: `Bearer ${(0, import_provider_utils14.loadApiKey)({
3437
+ Authorization: `Bearer ${(0, import_provider_utils15.loadApiKey)({
3282
3438
  apiKey: options.apiKey,
3283
3439
  environmentVariableName: "OPENAI_API_KEY",
3284
3440
  description: "OpenAI"
@@ -3336,7 +3492,8 @@ function createOpenAI(options = {}) {
3336
3492
  provider: `${providerName}.responses`,
3337
3493
  url: ({ path }) => `${baseURL}${path}`,
3338
3494
  headers: getHeaders,
3339
- fetch: options.fetch
3495
+ fetch: options.fetch,
3496
+ fileIdPrefixes: ["file-"]
3340
3497
  });
3341
3498
  };
3342
3499
  const provider = function(modelId) {