@ai-sdk/openai 2.0.0-canary.11 → 2.0.0-canary.13

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.
@@ -248,7 +248,13 @@ var openaiProviderOptions = z.object({
248
248
  /**
249
249
  * Parameters for prediction mode.
250
250
  */
251
- prediction: z.record(z.any()).optional()
251
+ prediction: z.record(z.any()).optional(),
252
+ /**
253
+ * Whether to use structured outputs.
254
+ *
255
+ * @default true
256
+ */
257
+ structuredOutputs: z.boolean().optional()
252
258
  });
253
259
 
254
260
  // src/openai-error.ts
@@ -331,10 +337,9 @@ function prepareTools({
331
337
 
332
338
  // src/openai-chat-language-model.ts
333
339
  var OpenAIChatLanguageModel = class {
334
- constructor(modelId, settings, config) {
340
+ constructor(modelId, config) {
335
341
  this.specificationVersion = "v2";
336
342
  this.modelId = modelId;
337
- this.settings = settings;
338
343
  this.config = config;
339
344
  }
340
345
  get provider() {
@@ -345,7 +350,7 @@ var OpenAIChatLanguageModel = class {
345
350
  "image/*": [/^https?:\/\/.*$/]
346
351
  };
347
352
  }
348
- getArgs({
353
+ async getArgs({
349
354
  prompt,
350
355
  maxOutputTokens,
351
356
  temperature,
@@ -362,18 +367,19 @@ var OpenAIChatLanguageModel = class {
362
367
  }) {
363
368
  var _a, _b, _c;
364
369
  const warnings = [];
365
- const openaiOptions = (_a = parseProviderOptions({
370
+ const openaiOptions = (_a = await parseProviderOptions({
366
371
  provider: "openai",
367
372
  providerOptions,
368
373
  schema: openaiProviderOptions
369
374
  })) != null ? _a : {};
375
+ const structuredOutputs = (_b = openaiOptions.structuredOutputs) != null ? _b : true;
370
376
  if (topK != null) {
371
377
  warnings.push({
372
378
  type: "unsupported-setting",
373
379
  setting: "topK"
374
380
  });
375
381
  }
376
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.settings.structuredOutputs) {
382
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
377
383
  warnings.push({
378
384
  type: "unsupported-setting",
379
385
  setting: "responseFormat",
@@ -402,12 +408,12 @@ var OpenAIChatLanguageModel = class {
402
408
  presence_penalty: presencePenalty,
403
409
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? (
404
410
  // TODO convert into provider option
405
- this.settings.structuredOutputs && responseFormat.schema != null ? {
411
+ structuredOutputs && responseFormat.schema != null ? {
406
412
  type: "json_schema",
407
413
  json_schema: {
408
414
  schema: responseFormat.schema,
409
415
  strict: true,
410
- name: (_b = responseFormat.name) != null ? _b : "response",
416
+ name: (_c = responseFormat.name) != null ? _c : "response",
411
417
  description: responseFormat.description
412
418
  }
413
419
  } : { type: "json_object" }
@@ -487,7 +493,7 @@ var OpenAIChatLanguageModel = class {
487
493
  } = prepareTools({
488
494
  tools,
489
495
  toolChoice,
490
- structuredOutputs: (_c = this.settings.structuredOutputs) != null ? _c : false
496
+ structuredOutputs
491
497
  });
492
498
  return {
493
499
  args: {
@@ -500,7 +506,7 @@ var OpenAIChatLanguageModel = class {
500
506
  }
501
507
  async doGenerate(options) {
502
508
  var _a, _b, _c, _d, _e, _f, _g, _h;
503
- const { args: body, warnings } = this.getArgs(options);
509
+ const { args: body, warnings } = await this.getArgs(options);
504
510
  const {
505
511
  responseHeaders,
506
512
  value: response,
@@ -567,7 +573,7 @@ var OpenAIChatLanguageModel = class {
567
573
  };
568
574
  }
569
575
  async doStream(options) {
570
- const { args, warnings } = this.getArgs(options);
576
+ const { args, warnings } = await this.getArgs(options);
571
577
  const body = {
572
578
  ...args,
573
579
  stream: true,
@@ -860,9 +866,10 @@ import {
860
866
  combineHeaders as combineHeaders2,
861
867
  createEventSourceResponseHandler as createEventSourceResponseHandler2,
862
868
  createJsonResponseHandler as createJsonResponseHandler2,
869
+ parseProviderOptions as parseProviderOptions2,
863
870
  postJsonToApi as postJsonToApi2
864
871
  } from "@ai-sdk/provider-utils";
865
- import { z as z4 } from "zod";
872
+ import { z as z5 } from "zod";
866
873
 
867
874
  // src/convert-to-openai-completion-prompt.ts
868
875
  import {
@@ -871,13 +878,9 @@ import {
871
878
  } from "@ai-sdk/provider";
872
879
  function convertToOpenAICompletionPrompt({
873
880
  prompt,
874
- inputFormat,
875
881
  user = "user",
876
882
  assistant = "assistant"
877
883
  }) {
878
- if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
879
- return { prompt: prompt[0].content[0].text };
880
- }
881
884
  let text = "";
882
885
  if (prompt[0].role === "system") {
883
886
  text += `${prompt[0].content}
@@ -946,14 +949,49 @@ ${user}:`]
946
949
  };
947
950
  }
948
951
 
952
+ // src/openai-completion-options.ts
953
+ import { z as z4 } from "zod";
954
+ var openaiCompletionProviderOptions = z4.object({
955
+ /**
956
+ Echo back the prompt in addition to the completion.
957
+ */
958
+ echo: z4.boolean().optional(),
959
+ /**
960
+ Modify the likelihood of specified tokens appearing in the completion.
961
+
962
+ Accepts a JSON object that maps tokens (specified by their token ID in
963
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
964
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
965
+ the bias is added to the logits generated by the model prior to sampling.
966
+ The exact effect will vary per model, but values between -1 and 1 should
967
+ decrease or increase likelihood of selection; values like -100 or 100
968
+ should result in a ban or exclusive selection of the relevant token.
969
+
970
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
971
+ token from being generated.
972
+ */
973
+ logitBias: z4.record(z4.string(), z4.number()).optional(),
974
+ /**
975
+ The suffix that comes after a completion of inserted text.
976
+ */
977
+ suffix: z4.string().optional(),
978
+ /**
979
+ A unique identifier representing your end-user, which can help OpenAI to
980
+ monitor and detect abuse. Learn more.
981
+ */
982
+ user: z4.string().optional()
983
+ });
984
+
949
985
  // src/openai-completion-language-model.ts
950
986
  var OpenAICompletionLanguageModel = class {
951
- constructor(modelId, settings, config) {
987
+ constructor(modelId, config) {
952
988
  this.specificationVersion = "v2";
953
989
  this.modelId = modelId;
954
- this.settings = settings;
955
990
  this.config = config;
956
991
  }
992
+ get providerOptionsName() {
993
+ return this.config.provider.split(".")[0].trim();
994
+ }
957
995
  get provider() {
958
996
  return this.config.provider;
959
997
  }
@@ -962,8 +1000,7 @@ var OpenAICompletionLanguageModel = class {
962
1000
  // no supported urls for completion models
963
1001
  };
964
1002
  }
965
- getArgs({
966
- inputFormat,
1003
+ async getArgs({
967
1004
  prompt,
968
1005
  maxOutputTokens,
969
1006
  temperature,
@@ -975,9 +1012,22 @@ var OpenAICompletionLanguageModel = class {
975
1012
  responseFormat,
976
1013
  tools,
977
1014
  toolChoice,
978
- seed
1015
+ seed,
1016
+ providerOptions
979
1017
  }) {
980
1018
  const warnings = [];
1019
+ const openaiOptions = {
1020
+ ...await parseProviderOptions2({
1021
+ provider: "openai",
1022
+ providerOptions,
1023
+ schema: openaiCompletionProviderOptions
1024
+ }),
1025
+ ...await parseProviderOptions2({
1026
+ provider: this.providerOptionsName,
1027
+ providerOptions,
1028
+ schema: openaiCompletionProviderOptions
1029
+ })
1030
+ };
981
1031
  if (topK != null) {
982
1032
  warnings.push({ type: "unsupported-setting", setting: "topK" });
983
1033
  }
@@ -994,17 +1044,17 @@ var OpenAICompletionLanguageModel = class {
994
1044
  details: "JSON response format is not supported."
995
1045
  });
996
1046
  }
997
- const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
1047
+ const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
998
1048
  const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
999
1049
  return {
1000
1050
  args: {
1001
1051
  // model id:
1002
1052
  model: this.modelId,
1003
1053
  // model specific settings:
1004
- echo: this.settings.echo,
1005
- logit_bias: this.settings.logitBias,
1006
- suffix: this.settings.suffix,
1007
- user: this.settings.user,
1054
+ echo: openaiOptions.echo,
1055
+ logit_bias: openaiOptions.logitBias,
1056
+ suffix: openaiOptions.suffix,
1057
+ user: openaiOptions.user,
1008
1058
  // standardized settings:
1009
1059
  max_tokens: maxOutputTokens,
1010
1060
  temperature,
@@ -1021,7 +1071,7 @@ var OpenAICompletionLanguageModel = class {
1021
1071
  };
1022
1072
  }
1023
1073
  async doGenerate(options) {
1024
- const { args, warnings } = this.getArgs(options);
1074
+ const { args, warnings } = await this.getArgs(options);
1025
1075
  const {
1026
1076
  responseHeaders,
1027
1077
  value: response,
@@ -1058,7 +1108,7 @@ var OpenAICompletionLanguageModel = class {
1058
1108
  };
1059
1109
  }
1060
1110
  async doStream(options) {
1061
- const { args, warnings } = this.getArgs(options);
1111
+ const { args, warnings } = await this.getArgs(options);
1062
1112
  const body = {
1063
1113
  ...args,
1064
1114
  stream: true,
@@ -1139,36 +1189,36 @@ var OpenAICompletionLanguageModel = class {
1139
1189
  };
1140
1190
  }
1141
1191
  };
1142
- var openaiCompletionResponseSchema = z4.object({
1143
- id: z4.string().nullish(),
1144
- created: z4.number().nullish(),
1145
- model: z4.string().nullish(),
1146
- choices: z4.array(
1147
- z4.object({
1148
- text: z4.string(),
1149
- finish_reason: z4.string()
1192
+ var openaiCompletionResponseSchema = z5.object({
1193
+ id: z5.string().nullish(),
1194
+ created: z5.number().nullish(),
1195
+ model: z5.string().nullish(),
1196
+ choices: z5.array(
1197
+ z5.object({
1198
+ text: z5.string(),
1199
+ finish_reason: z5.string()
1150
1200
  })
1151
1201
  ),
1152
- usage: z4.object({
1153
- prompt_tokens: z4.number(),
1154
- completion_tokens: z4.number()
1202
+ usage: z5.object({
1203
+ prompt_tokens: z5.number(),
1204
+ completion_tokens: z5.number()
1155
1205
  })
1156
1206
  });
1157
- var openaiCompletionChunkSchema = z4.union([
1158
- z4.object({
1159
- id: z4.string().nullish(),
1160
- created: z4.number().nullish(),
1161
- model: z4.string().nullish(),
1162
- choices: z4.array(
1163
- z4.object({
1164
- text: z4.string(),
1165
- finish_reason: z4.string().nullish(),
1166
- index: z4.number()
1207
+ var openaiCompletionChunkSchema = z5.union([
1208
+ z5.object({
1209
+ id: z5.string().nullish(),
1210
+ created: z5.number().nullish(),
1211
+ model: z5.string().nullish(),
1212
+ choices: z5.array(
1213
+ z5.object({
1214
+ text: z5.string(),
1215
+ finish_reason: z5.string().nullish(),
1216
+ index: z5.number()
1167
1217
  })
1168
1218
  ),
1169
- usage: z4.object({
1170
- prompt_tokens: z4.number(),
1171
- completion_tokens: z4.number()
1219
+ usage: z5.object({
1220
+ prompt_tokens: z5.number(),
1221
+ completion_tokens: z5.number()
1172
1222
  }).nullish()
1173
1223
  }),
1174
1224
  openaiErrorDataSchema
@@ -1181,45 +1231,38 @@ import {
1181
1231
  import {
1182
1232
  combineHeaders as combineHeaders3,
1183
1233
  createJsonResponseHandler as createJsonResponseHandler3,
1184
- parseProviderOptions as parseProviderOptions2,
1234
+ parseProviderOptions as parseProviderOptions3,
1185
1235
  postJsonToApi as postJsonToApi3
1186
1236
  } from "@ai-sdk/provider-utils";
1187
- import { z as z6 } from "zod";
1237
+ import { z as z7 } from "zod";
1188
1238
 
1189
1239
  // src/openai-embedding-options.ts
1190
- import { z as z5 } from "zod";
1191
- var openaiEmbeddingProviderOptions = z5.object({
1240
+ import { z as z6 } from "zod";
1241
+ var openaiEmbeddingProviderOptions = z6.object({
1192
1242
  /**
1193
1243
  The number of dimensions the resulting output embeddings should have.
1194
1244
  Only supported in text-embedding-3 and later models.
1195
1245
  */
1196
- dimensions: z5.number().optional(),
1246
+ dimensions: z6.number().optional(),
1197
1247
  /**
1198
1248
  A unique identifier representing your end-user, which can help OpenAI to
1199
1249
  monitor and detect abuse. Learn more.
1200
1250
  */
1201
- user: z5.string().optional()
1251
+ user: z6.string().optional()
1202
1252
  });
1203
1253
 
1204
1254
  // src/openai-embedding-model.ts
1205
1255
  var OpenAIEmbeddingModel = class {
1206
- constructor(modelId, settings, config) {
1256
+ constructor(modelId, config) {
1207
1257
  this.specificationVersion = "v2";
1258
+ this.maxEmbeddingsPerCall = 2048;
1259
+ this.supportsParallelCalls = true;
1208
1260
  this.modelId = modelId;
1209
- this.settings = settings;
1210
1261
  this.config = config;
1211
1262
  }
1212
1263
  get provider() {
1213
1264
  return this.config.provider;
1214
1265
  }
1215
- get maxEmbeddingsPerCall() {
1216
- var _a;
1217
- return (_a = this.settings.maxEmbeddingsPerCall) != null ? _a : 2048;
1218
- }
1219
- get supportsParallelCalls() {
1220
- var _a;
1221
- return (_a = this.settings.supportsParallelCalls) != null ? _a : true;
1222
- }
1223
1266
  async doEmbed({
1224
1267
  values,
1225
1268
  headers,
@@ -1235,7 +1278,7 @@ var OpenAIEmbeddingModel = class {
1235
1278
  values
1236
1279
  });
1237
1280
  }
1238
- const openaiOptions = (_a = parseProviderOptions2({
1281
+ const openaiOptions = (_a = await parseProviderOptions3({
1239
1282
  provider: "openai",
1240
1283
  providerOptions,
1241
1284
  schema: openaiEmbeddingProviderOptions
@@ -1271,9 +1314,9 @@ var OpenAIEmbeddingModel = class {
1271
1314
  };
1272
1315
  }
1273
1316
  };
1274
- var openaiTextEmbeddingResponseSchema = z6.object({
1275
- data: z6.array(z6.object({ embedding: z6.array(z6.number()) })),
1276
- usage: z6.object({ prompt_tokens: z6.number() }).nullish()
1317
+ var openaiTextEmbeddingResponseSchema = z7.object({
1318
+ data: z7.array(z7.object({ embedding: z7.array(z7.number()) })),
1319
+ usage: z7.object({ prompt_tokens: z7.number() }).nullish()
1277
1320
  });
1278
1321
 
1279
1322
  // src/openai-image-model.ts
@@ -1282,13 +1325,15 @@ import {
1282
1325
  createJsonResponseHandler as createJsonResponseHandler4,
1283
1326
  postJsonToApi as postJsonToApi4
1284
1327
  } from "@ai-sdk/provider-utils";
1285
- import { z as z7 } from "zod";
1328
+ import { z as z8 } from "zod";
1286
1329
 
1287
1330
  // src/openai-image-settings.ts
1288
1331
  var modelMaxImagesPerCall = {
1289
1332
  "dall-e-3": 1,
1290
- "dall-e-2": 10
1333
+ "dall-e-2": 10,
1334
+ "gpt-image-1": 10
1291
1335
  };
1336
+ var hasDefaultResponseFormat = /* @__PURE__ */ new Set(["gpt-image-1"]);
1292
1337
 
1293
1338
  // src/openai-image-model.ts
1294
1339
  var OpenAIImageModel = class {
@@ -1340,7 +1385,7 @@ var OpenAIImageModel = class {
1340
1385
  n,
1341
1386
  size,
1342
1387
  ...(_d = providerOptions.openai) != null ? _d : {},
1343
- response_format: "b64_json"
1388
+ ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1344
1389
  },
1345
1390
  failedResponseHandler: openaiFailedResponseHandler,
1346
1391
  successfulResponseHandler: createJsonResponseHandler4(
@@ -1360,8 +1405,8 @@ var OpenAIImageModel = class {
1360
1405
  };
1361
1406
  }
1362
1407
  };
1363
- var openaiImageResponseSchema = z7.object({
1364
- data: z7.array(z7.object({ b64_json: z7.string() }))
1408
+ var openaiImageResponseSchema = z8.object({
1409
+ data: z8.array(z8.object({ b64_json: z8.string() }))
1365
1410
  });
1366
1411
 
1367
1412
  // src/openai-transcription-model.ts
@@ -1369,17 +1414,39 @@ import {
1369
1414
  combineHeaders as combineHeaders5,
1370
1415
  convertBase64ToUint8Array,
1371
1416
  createJsonResponseHandler as createJsonResponseHandler5,
1372
- parseProviderOptions as parseProviderOptions3,
1417
+ parseProviderOptions as parseProviderOptions4,
1373
1418
  postFormDataToApi
1374
1419
  } from "@ai-sdk/provider-utils";
1375
- import { z as z8 } from "zod";
1376
- var openAIProviderOptionsSchema = z8.object({
1377
- include: z8.array(z8.string()).nullish(),
1378
- language: z8.string().nullish(),
1379
- prompt: z8.string().nullish(),
1380
- temperature: z8.number().min(0).max(1).nullish().default(0),
1381
- timestampGranularities: z8.array(z8.enum(["word", "segment"])).nullish().default(["segment"])
1420
+ import { z as z10 } from "zod";
1421
+
1422
+ // src/openai-transcription-options.ts
1423
+ import { z as z9 } from "zod";
1424
+ var openAITranscriptionProviderOptions = z9.object({
1425
+ /**
1426
+ * Additional information to include in the transcription response.
1427
+ */
1428
+ include: z9.array(z9.string()).nullish(),
1429
+ /**
1430
+ * The language of the input audio in ISO-639-1 format.
1431
+ */
1432
+ language: z9.string().nullish(),
1433
+ /**
1434
+ * An optional text to guide the model's style or continue a previous audio segment.
1435
+ */
1436
+ prompt: z9.string().nullish(),
1437
+ /**
1438
+ * The sampling temperature, between 0 and 1.
1439
+ * @default 0
1440
+ */
1441
+ temperature: z9.number().min(0).max(1).default(0).nullish(),
1442
+ /**
1443
+ * The timestamp granularities to populate for this transcription.
1444
+ * @default ['segment']
1445
+ */
1446
+ timestampGranularities: z9.array(z9.enum(["word", "segment"])).default(["segment"]).nullish()
1382
1447
  });
1448
+
1449
+ // src/openai-transcription-model.ts
1383
1450
  var languageMap = {
1384
1451
  afrikaans: "af",
1385
1452
  arabic: "ar",
@@ -1448,17 +1515,16 @@ var OpenAITranscriptionModel = class {
1448
1515
  get provider() {
1449
1516
  return this.config.provider;
1450
1517
  }
1451
- getArgs({
1518
+ async getArgs({
1452
1519
  audio,
1453
1520
  mediaType,
1454
1521
  providerOptions
1455
1522
  }) {
1456
- var _a, _b, _c, _d, _e;
1457
1523
  const warnings = [];
1458
- const openAIOptions = parseProviderOptions3({
1524
+ const openAIOptions = await parseProviderOptions4({
1459
1525
  provider: "openai",
1460
1526
  providerOptions,
1461
- schema: openAIProviderOptionsSchema
1527
+ schema: openAITranscriptionProviderOptions
1462
1528
  });
1463
1529
  const formData = new FormData();
1464
1530
  const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
@@ -1466,15 +1532,14 @@ var OpenAITranscriptionModel = class {
1466
1532
  formData.append("file", new File([blob], "audio", { type: mediaType }));
1467
1533
  if (openAIOptions) {
1468
1534
  const transcriptionModelOptions = {
1469
- include: (_a = openAIOptions.include) != null ? _a : void 0,
1470
- language: (_b = openAIOptions.language) != null ? _b : void 0,
1471
- prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
1472
- temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
1473
- timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
1535
+ include: openAIOptions.include,
1536
+ language: openAIOptions.language,
1537
+ prompt: openAIOptions.prompt,
1538
+ temperature: openAIOptions.temperature,
1539
+ timestamp_granularities: openAIOptions.timestampGranularities
1474
1540
  };
1475
- for (const key in transcriptionModelOptions) {
1476
- const value = transcriptionModelOptions[key];
1477
- if (value !== void 0) {
1541
+ for (const [key, value] of Object.entries(transcriptionModelOptions)) {
1542
+ if (value != null) {
1478
1543
  formData.append(key, String(value));
1479
1544
  }
1480
1545
  }
@@ -1487,7 +1552,7 @@ var OpenAITranscriptionModel = class {
1487
1552
  async doGenerate(options) {
1488
1553
  var _a, _b, _c, _d, _e, _f;
1489
1554
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1490
- const { formData, warnings } = this.getArgs(options);
1555
+ const { formData, warnings } = await this.getArgs(options);
1491
1556
  const {
1492
1557
  value: response,
1493
1558
  responseHeaders,
@@ -1526,15 +1591,15 @@ var OpenAITranscriptionModel = class {
1526
1591
  };
1527
1592
  }
1528
1593
  };
1529
- var openaiTranscriptionResponseSchema = z8.object({
1530
- text: z8.string(),
1531
- language: z8.string().nullish(),
1532
- duration: z8.number().nullish(),
1533
- words: z8.array(
1534
- z8.object({
1535
- word: z8.string(),
1536
- start: z8.number(),
1537
- end: z8.number()
1594
+ var openaiTranscriptionResponseSchema = z10.object({
1595
+ text: z10.string(),
1596
+ language: z10.string().nullish(),
1597
+ duration: z10.number().nullish(),
1598
+ words: z10.array(
1599
+ z10.object({
1600
+ word: z10.string(),
1601
+ start: z10.number(),
1602
+ end: z10.number()
1538
1603
  })
1539
1604
  ).nullish()
1540
1605
  });
@@ -1543,13 +1608,13 @@ var openaiTranscriptionResponseSchema = z8.object({
1543
1608
  import {
1544
1609
  combineHeaders as combineHeaders6,
1545
1610
  createBinaryResponseHandler,
1546
- parseProviderOptions as parseProviderOptions4,
1611
+ parseProviderOptions as parseProviderOptions5,
1547
1612
  postJsonToApi as postJsonToApi5
1548
1613
  } from "@ai-sdk/provider-utils";
1549
- import { z as z9 } from "zod";
1550
- var OpenAIProviderOptionsSchema = z9.object({
1551
- instructions: z9.string().nullish(),
1552
- speed: z9.number().min(0.25).max(4).default(1).nullish()
1614
+ import { z as z11 } from "zod";
1615
+ var OpenAIProviderOptionsSchema = z11.object({
1616
+ instructions: z11.string().nullish(),
1617
+ speed: z11.number().min(0.25).max(4).default(1).nullish()
1553
1618
  });
1554
1619
  var OpenAISpeechModel = class {
1555
1620
  constructor(modelId, config) {
@@ -1560,7 +1625,7 @@ var OpenAISpeechModel = class {
1560
1625
  get provider() {
1561
1626
  return this.config.provider;
1562
1627
  }
1563
- getArgs({
1628
+ async getArgs({
1564
1629
  text,
1565
1630
  voice = "alloy",
1566
1631
  outputFormat = "mp3",
@@ -1569,7 +1634,7 @@ var OpenAISpeechModel = class {
1569
1634
  providerOptions
1570
1635
  }) {
1571
1636
  const warnings = [];
1572
- const openAIOptions = parseProviderOptions4({
1637
+ const openAIOptions = await parseProviderOptions5({
1573
1638
  provider: "openai",
1574
1639
  providerOptions,
1575
1640
  schema: OpenAIProviderOptionsSchema
@@ -1610,7 +1675,7 @@ var OpenAISpeechModel = class {
1610
1675
  async doGenerate(options) {
1611
1676
  var _a, _b, _c;
1612
1677
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1613
- const { requestBody, warnings } = this.getArgs(options);
1678
+ const { requestBody, warnings } = await this.getArgs(options);
1614
1679
  const {
1615
1680
  value: audio,
1616
1681
  responseHeaders,
@@ -1649,10 +1714,10 @@ import {
1649
1714
  createEventSourceResponseHandler as createEventSourceResponseHandler3,
1650
1715
  createJsonResponseHandler as createJsonResponseHandler6,
1651
1716
  generateId as generateId2,
1652
- parseProviderOptions as parseProviderOptions5,
1717
+ parseProviderOptions as parseProviderOptions6,
1653
1718
  postJsonToApi as postJsonToApi6
1654
1719
  } from "@ai-sdk/provider-utils";
1655
- import { z as z10 } from "zod";
1720
+ import { z as z12 } from "zod";
1656
1721
 
1657
1722
  // src/responses/convert-to-openai-responses-messages.ts
1658
1723
  import {
@@ -1876,7 +1941,7 @@ var OpenAIResponsesLanguageModel = class {
1876
1941
  get provider() {
1877
1942
  return this.config.provider;
1878
1943
  }
1879
- getArgs({
1944
+ async getArgs({
1880
1945
  maxOutputTokens,
1881
1946
  temperature,
1882
1947
  stopSequences,
@@ -1920,7 +1985,7 @@ var OpenAIResponsesLanguageModel = class {
1920
1985
  systemMessageMode: modelConfig.systemMessageMode
1921
1986
  });
1922
1987
  warnings.push(...messageWarnings);
1923
- const openaiOptions = parseProviderOptions5({
1988
+ const openaiOptions = await parseProviderOptions6({
1924
1989
  provider: "openai",
1925
1990
  providerOptions,
1926
1991
  schema: openaiResponsesProviderOptionsSchema
@@ -2003,7 +2068,7 @@ var OpenAIResponsesLanguageModel = class {
2003
2068
  }
2004
2069
  async doGenerate(options) {
2005
2070
  var _a, _b, _c, _d, _e, _f, _g, _h;
2006
- const { args: body, warnings } = this.getArgs(options);
2071
+ const { args: body, warnings } = await this.getArgs(options);
2007
2072
  const {
2008
2073
  responseHeaders,
2009
2074
  value: response,
@@ -2017,55 +2082,55 @@ var OpenAIResponsesLanguageModel = class {
2017
2082
  body,
2018
2083
  failedResponseHandler: openaiFailedResponseHandler,
2019
2084
  successfulResponseHandler: createJsonResponseHandler6(
2020
- z10.object({
2021
- id: z10.string(),
2022
- created_at: z10.number(),
2023
- model: z10.string(),
2024
- output: z10.array(
2025
- z10.discriminatedUnion("type", [
2026
- z10.object({
2027
- type: z10.literal("message"),
2028
- role: z10.literal("assistant"),
2029
- content: z10.array(
2030
- z10.object({
2031
- type: z10.literal("output_text"),
2032
- text: z10.string(),
2033
- annotations: z10.array(
2034
- z10.object({
2035
- type: z10.literal("url_citation"),
2036
- start_index: z10.number(),
2037
- end_index: z10.number(),
2038
- url: z10.string(),
2039
- title: z10.string()
2085
+ z12.object({
2086
+ id: z12.string(),
2087
+ created_at: z12.number(),
2088
+ model: z12.string(),
2089
+ output: z12.array(
2090
+ z12.discriminatedUnion("type", [
2091
+ z12.object({
2092
+ type: z12.literal("message"),
2093
+ role: z12.literal("assistant"),
2094
+ content: z12.array(
2095
+ z12.object({
2096
+ type: z12.literal("output_text"),
2097
+ text: z12.string(),
2098
+ annotations: z12.array(
2099
+ z12.object({
2100
+ type: z12.literal("url_citation"),
2101
+ start_index: z12.number(),
2102
+ end_index: z12.number(),
2103
+ url: z12.string(),
2104
+ title: z12.string()
2040
2105
  })
2041
2106
  )
2042
2107
  })
2043
2108
  )
2044
2109
  }),
2045
- z10.object({
2046
- type: z10.literal("function_call"),
2047
- call_id: z10.string(),
2048
- name: z10.string(),
2049
- arguments: z10.string()
2110
+ z12.object({
2111
+ type: z12.literal("function_call"),
2112
+ call_id: z12.string(),
2113
+ name: z12.string(),
2114
+ arguments: z12.string()
2050
2115
  }),
2051
- z10.object({
2052
- type: z10.literal("web_search_call")
2116
+ z12.object({
2117
+ type: z12.literal("web_search_call")
2053
2118
  }),
2054
- z10.object({
2055
- type: z10.literal("computer_call")
2119
+ z12.object({
2120
+ type: z12.literal("computer_call")
2056
2121
  }),
2057
- z10.object({
2058
- type: z10.literal("reasoning"),
2059
- summary: z10.array(
2060
- z10.object({
2061
- type: z10.literal("summary_text"),
2062
- text: z10.string()
2122
+ z12.object({
2123
+ type: z12.literal("reasoning"),
2124
+ summary: z12.array(
2125
+ z12.object({
2126
+ type: z12.literal("summary_text"),
2127
+ text: z12.string()
2063
2128
  })
2064
2129
  )
2065
2130
  })
2066
2131
  ])
2067
2132
  ),
2068
- incomplete_details: z10.object({ reason: z10.string() }).nullable(),
2133
+ incomplete_details: z12.object({ reason: z12.string() }).nullable(),
2069
2134
  usage: usageSchema
2070
2135
  })
2071
2136
  ),
@@ -2078,7 +2143,6 @@ var OpenAIResponsesLanguageModel = class {
2078
2143
  case "reasoning": {
2079
2144
  content.push({
2080
2145
  type: "reasoning",
2081
- reasoningType: "text",
2082
2146
  text: part.summary.map((summary) => summary.text).join()
2083
2147
  });
2084
2148
  break;
@@ -2142,7 +2206,7 @@ var OpenAIResponsesLanguageModel = class {
2142
2206
  };
2143
2207
  }
2144
2208
  async doStream(options) {
2145
- const { args: body, warnings } = this.getArgs(options);
2209
+ const { args: body, warnings } = await this.getArgs(options);
2146
2210
  const { responseHeaders, value: response } = await postJsonToApi6({
2147
2211
  url: this.config.url({
2148
2212
  path: "/responses",
@@ -2226,7 +2290,6 @@ var OpenAIResponsesLanguageModel = class {
2226
2290
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2227
2291
  controller.enqueue({
2228
2292
  type: "reasoning",
2229
- reasoningType: "text",
2230
2293
  text: value.delta
2231
2294
  });
2232
2295
  } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
@@ -2281,86 +2344,86 @@ var OpenAIResponsesLanguageModel = class {
2281
2344
  };
2282
2345
  }
2283
2346
  };
2284
- var usageSchema = z10.object({
2285
- input_tokens: z10.number(),
2286
- input_tokens_details: z10.object({ cached_tokens: z10.number().nullish() }).nullish(),
2287
- output_tokens: z10.number(),
2288
- output_tokens_details: z10.object({ reasoning_tokens: z10.number().nullish() }).nullish()
2347
+ var usageSchema = z12.object({
2348
+ input_tokens: z12.number(),
2349
+ input_tokens_details: z12.object({ cached_tokens: z12.number().nullish() }).nullish(),
2350
+ output_tokens: z12.number(),
2351
+ output_tokens_details: z12.object({ reasoning_tokens: z12.number().nullish() }).nullish()
2289
2352
  });
2290
- var textDeltaChunkSchema = z10.object({
2291
- type: z10.literal("response.output_text.delta"),
2292
- delta: z10.string()
2353
+ var textDeltaChunkSchema = z12.object({
2354
+ type: z12.literal("response.output_text.delta"),
2355
+ delta: z12.string()
2293
2356
  });
2294
- var responseFinishedChunkSchema = z10.object({
2295
- type: z10.enum(["response.completed", "response.incomplete"]),
2296
- response: z10.object({
2297
- incomplete_details: z10.object({ reason: z10.string() }).nullish(),
2357
+ var responseFinishedChunkSchema = z12.object({
2358
+ type: z12.enum(["response.completed", "response.incomplete"]),
2359
+ response: z12.object({
2360
+ incomplete_details: z12.object({ reason: z12.string() }).nullish(),
2298
2361
  usage: usageSchema
2299
2362
  })
2300
2363
  });
2301
- var responseCreatedChunkSchema = z10.object({
2302
- type: z10.literal("response.created"),
2303
- response: z10.object({
2304
- id: z10.string(),
2305
- created_at: z10.number(),
2306
- model: z10.string()
2364
+ var responseCreatedChunkSchema = z12.object({
2365
+ type: z12.literal("response.created"),
2366
+ response: z12.object({
2367
+ id: z12.string(),
2368
+ created_at: z12.number(),
2369
+ model: z12.string()
2307
2370
  })
2308
2371
  });
2309
- var responseOutputItemDoneSchema = z10.object({
2310
- type: z10.literal("response.output_item.done"),
2311
- output_index: z10.number(),
2312
- item: z10.discriminatedUnion("type", [
2313
- z10.object({
2314
- type: z10.literal("message")
2372
+ var responseOutputItemDoneSchema = z12.object({
2373
+ type: z12.literal("response.output_item.done"),
2374
+ output_index: z12.number(),
2375
+ item: z12.discriminatedUnion("type", [
2376
+ z12.object({
2377
+ type: z12.literal("message")
2315
2378
  }),
2316
- z10.object({
2317
- type: z10.literal("function_call"),
2318
- id: z10.string(),
2319
- call_id: z10.string(),
2320
- name: z10.string(),
2321
- arguments: z10.string(),
2322
- status: z10.literal("completed")
2379
+ z12.object({
2380
+ type: z12.literal("function_call"),
2381
+ id: z12.string(),
2382
+ call_id: z12.string(),
2383
+ name: z12.string(),
2384
+ arguments: z12.string(),
2385
+ status: z12.literal("completed")
2323
2386
  })
2324
2387
  ])
2325
2388
  });
2326
- var responseFunctionCallArgumentsDeltaSchema = z10.object({
2327
- type: z10.literal("response.function_call_arguments.delta"),
2328
- item_id: z10.string(),
2329
- output_index: z10.number(),
2330
- delta: z10.string()
2389
+ var responseFunctionCallArgumentsDeltaSchema = z12.object({
2390
+ type: z12.literal("response.function_call_arguments.delta"),
2391
+ item_id: z12.string(),
2392
+ output_index: z12.number(),
2393
+ delta: z12.string()
2331
2394
  });
2332
- var responseOutputItemAddedSchema = z10.object({
2333
- type: z10.literal("response.output_item.added"),
2334
- output_index: z10.number(),
2335
- item: z10.discriminatedUnion("type", [
2336
- z10.object({
2337
- type: z10.literal("message")
2395
+ var responseOutputItemAddedSchema = z12.object({
2396
+ type: z12.literal("response.output_item.added"),
2397
+ output_index: z12.number(),
2398
+ item: z12.discriminatedUnion("type", [
2399
+ z12.object({
2400
+ type: z12.literal("message")
2338
2401
  }),
2339
- z10.object({
2340
- type: z10.literal("function_call"),
2341
- id: z10.string(),
2342
- call_id: z10.string(),
2343
- name: z10.string(),
2344
- arguments: z10.string()
2402
+ z12.object({
2403
+ type: z12.literal("function_call"),
2404
+ id: z12.string(),
2405
+ call_id: z12.string(),
2406
+ name: z12.string(),
2407
+ arguments: z12.string()
2345
2408
  })
2346
2409
  ])
2347
2410
  });
2348
- var responseAnnotationAddedSchema = z10.object({
2349
- type: z10.literal("response.output_text.annotation.added"),
2350
- annotation: z10.object({
2351
- type: z10.literal("url_citation"),
2352
- url: z10.string(),
2353
- title: z10.string()
2411
+ var responseAnnotationAddedSchema = z12.object({
2412
+ type: z12.literal("response.output_text.annotation.added"),
2413
+ annotation: z12.object({
2414
+ type: z12.literal("url_citation"),
2415
+ url: z12.string(),
2416
+ title: z12.string()
2354
2417
  })
2355
2418
  });
2356
- var responseReasoningSummaryTextDeltaSchema = z10.object({
2357
- type: z10.literal("response.reasoning_summary_text.delta"),
2358
- item_id: z10.string(),
2359
- output_index: z10.number(),
2360
- summary_index: z10.number(),
2361
- delta: z10.string()
2419
+ var responseReasoningSummaryTextDeltaSchema = z12.object({
2420
+ type: z12.literal("response.reasoning_summary_text.delta"),
2421
+ item_id: z12.string(),
2422
+ output_index: z12.number(),
2423
+ summary_index: z12.number(),
2424
+ delta: z12.string()
2362
2425
  });
2363
- var openaiResponsesChunkSchema = z10.union([
2426
+ var openaiResponsesChunkSchema = z12.union([
2364
2427
  textDeltaChunkSchema,
2365
2428
  responseFinishedChunkSchema,
2366
2429
  responseCreatedChunkSchema,
@@ -2369,7 +2432,7 @@ var openaiResponsesChunkSchema = z10.union([
2369
2432
  responseOutputItemAddedSchema,
2370
2433
  responseAnnotationAddedSchema,
2371
2434
  responseReasoningSummaryTextDeltaSchema,
2372
- z10.object({ type: z10.string() }).passthrough()
2435
+ z12.object({ type: z12.string() }).passthrough()
2373
2436
  // fallback for unknown chunks
2374
2437
  ]);
2375
2438
  function isTextDeltaChunk(chunk) {
@@ -2417,16 +2480,16 @@ function getResponsesModelConfig(modelId) {
2417
2480
  requiredAutoTruncation: false
2418
2481
  };
2419
2482
  }
2420
- var openaiResponsesProviderOptionsSchema = z10.object({
2421
- metadata: z10.any().nullish(),
2422
- parallelToolCalls: z10.boolean().nullish(),
2423
- previousResponseId: z10.string().nullish(),
2424
- store: z10.boolean().nullish(),
2425
- user: z10.string().nullish(),
2426
- reasoningEffort: z10.string().nullish(),
2427
- strictSchemas: z10.boolean().nullish(),
2428
- instructions: z10.string().nullish(),
2429
- reasoningSummary: z10.string().nullish()
2483
+ var openaiResponsesProviderOptionsSchema = z12.object({
2484
+ metadata: z12.any().nullish(),
2485
+ parallelToolCalls: z12.boolean().nullish(),
2486
+ previousResponseId: z12.string().nullish(),
2487
+ store: z12.boolean().nullish(),
2488
+ user: z12.string().nullish(),
2489
+ reasoningEffort: z12.string().nullish(),
2490
+ strictSchemas: z12.boolean().nullish(),
2491
+ instructions: z12.string().nullish(),
2492
+ reasoningSummary: z12.string().nullish()
2430
2493
  });
2431
2494
  export {
2432
2495
  OpenAIChatLanguageModel,
@@ -2436,7 +2499,10 @@ export {
2436
2499
  OpenAIResponsesLanguageModel,
2437
2500
  OpenAISpeechModel,
2438
2501
  OpenAITranscriptionModel,
2502
+ hasDefaultResponseFormat,
2439
2503
  modelMaxImagesPerCall,
2504
+ openAITranscriptionProviderOptions,
2505
+ openaiCompletionProviderOptions,
2440
2506
  openaiEmbeddingProviderOptions,
2441
2507
  openaiProviderOptions
2442
2508
  };