@ai-sdk/openai 4.0.60 → 4.0.62

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
@@ -58,6 +58,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
58
58
  supportsFlexProcessing,
59
59
  supportsPriorityProcessing,
60
60
  supportsConfigurationUpdate: isGpt6OrLaterModel,
61
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
61
62
  supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
62
63
  isReasoningModel,
63
64
  systemMessageMode,
@@ -2416,9 +2417,10 @@ var baseImageModelOptionsObject = z11.object({
2416
2417
  /**
2417
2418
  * Quality of the generated image(s).
2418
2419
  *
2419
- * Valid values: `standard`, `hd`, `low`, `medium`, `high`, `auto`.
2420
+ * Valid values: `standard`, `hd`, `low`, `medium`, `high`, `xhigh`, `max`, `auto`.
2421
+ * `xhigh` and `max` are supported by GPT Image 2.5 models.
2420
2422
  */
2421
- quality: z11.enum(["standard", "hd", "low", "medium", "high", "auto"]).optional(),
2423
+ quality: z11.enum(["standard", "hd", "low", "medium", "high", "xhigh", "max", "auto"]).optional(),
2422
2424
  /**
2423
2425
  * Background behavior for the generated image(s).
2424
2426
  *
@@ -2896,6 +2898,7 @@ var customArgsSchema = lazySchema14(
2896
2898
  () => zodSchema14(
2897
2899
  z15.object({
2898
2900
  description: z15.string().optional(),
2901
+ async: z15.boolean().optional(),
2899
2902
  format: z15.union([
2900
2903
  z15.object({
2901
2904
  type: z15.literal("grammar"),
@@ -2991,7 +2994,7 @@ var imageGenerationArgsSchema = lazySchema16(
2991
2994
  outputCompression: z17.number().int().min(0).max(100).optional(),
2992
2995
  outputFormat: z17.enum(["png", "jpeg", "webp"]).optional(),
2993
2996
  partialImages: z17.number().int().min(0).max(3).optional(),
2994
- quality: z17.enum(["auto", "low", "medium", "high"]).optional(),
2997
+ quality: z17.enum(["auto", "low", "medium", "high", "xhigh", "max"]).optional(),
2995
2998
  size: z17.union([
2996
2999
  z17.enum(["1024x1024", "1024x1536", "1536x1024", "auto"]),
2997
3000
  z17.string().regex(/^\d+x\d+$/)
@@ -3427,6 +3430,7 @@ var openaiTools = {
3427
3430
  * `input` field is a string matching the specified grammar.
3428
3431
  *
3429
3432
  * @param description - An optional description of the tool.
3433
+ * @param async - Whether the model can continue without waiting for the tool result.
3430
3434
  * @param format - The output format constraint (grammar type, syntax, and definition).
3431
3435
  */
3432
3436
  customTool,
@@ -3471,7 +3475,7 @@ var openaiTools = {
3471
3475
  * @param outputCompression - Compression level for the output image (0-100).
3472
3476
  * @param outputFormat - The output format of the generated image. One of 'png', 'jpeg', or 'webp'.
3473
3477
  * @param partialImages - Number of partial images to generate in streaming mode (0-3).
3474
- * @param quality - The quality of the generated image. One of 'auto', 'low', 'medium', or 'high'.
3478
+ * @param quality - The quality of the generated image. One of 'auto', 'low', 'medium', 'high', 'xhigh', or 'max'. 'xhigh' and 'max' require a GPT Image 2.5 model.
3475
3479
  * @param size - The size of the generated image. One of 'auto', '1024x1024', '1024x1536', or '1536x1024'.
3476
3480
  */
3477
3481
  imageGeneration,
@@ -3542,7 +3546,7 @@ var openaiTools = {
3542
3546
  toolSearch
3543
3547
  };
3544
3548
 
3545
- // src/openai-responses-batch.ts
3549
+ // src/openai-batch.ts
3546
3550
  import {
3547
3551
  InvalidArgumentError as InvalidArgumentError2,
3548
3552
  InvalidResponseDataError
@@ -3559,34 +3563,10 @@ import {
3559
3563
  postJsonToApi as postJsonToApi6,
3560
3564
  postToApi,
3561
3565
  safeValidateTypes,
3562
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
3563
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6,
3564
3566
  zodSchema as zodSchema26
3565
3567
  } from "@ai-sdk/provider-utils";
3566
3568
  import { z as z28 } from "zod/v4";
3567
3569
 
3568
- // src/openai-config.ts
3569
- function prepareOpenAIConfigForWorkflowDeserialize(config) {
3570
- if (config.provider == null) {
3571
- throw new Error(
3572
- "OpenAI model is missing provider after workflow deserialization."
3573
- );
3574
- }
3575
- return {
3576
- ...config,
3577
- provider: config.provider,
3578
- url: typeof config.url === "function" ? config.url : ({ path }) => {
3579
- if (config.baseURL == null) {
3580
- throw new Error(
3581
- "OpenAI model is missing baseURL after workflow deserialization."
3582
- );
3583
- }
3584
- return `${config.baseURL}${path}`;
3585
- },
3586
- headers: typeof config.headers === "function" ? config.headers : config.headers == null ? void 0 : () => config.headers
3587
- };
3588
- }
3589
-
3590
3570
  // src/responses/convert-openai-responses-usage.ts
3591
3571
  import { createNullLanguageModelUsage as createNullLanguageModelUsage3 } from "@ai-sdk/provider-utils";
3592
3572
  function convertOpenAIResponsesUsage(usage) {
@@ -3932,6 +3912,7 @@ var openaiResponsesChunkSchema = lazySchema24(
3932
3912
  call_id: z25.string(),
3933
3913
  name: z25.string(),
3934
3914
  arguments: z25.string(),
3915
+ async: z25.boolean().nullish(),
3935
3916
  namespace: z25.string().nullish(),
3936
3917
  caller: openaiResponsesToolCallerSchema.nullish()
3937
3918
  }),
@@ -4006,7 +3987,8 @@ var openaiResponsesChunkSchema = lazySchema24(
4006
3987
  id: z25.string(),
4007
3988
  call_id: z25.string(),
4008
3989
  name: z25.string(),
4009
- input: z25.string()
3990
+ input: z25.string(),
3991
+ async: z25.boolean().nullish()
4010
3992
  }),
4011
3993
  z25.object({
4012
3994
  type: z25.literal("shell_call"),
@@ -4079,6 +4061,7 @@ var openaiResponsesChunkSchema = lazySchema24(
4079
4061
  call_id: z25.string(),
4080
4062
  name: z25.string(),
4081
4063
  arguments: z25.string(),
4064
+ async: z25.boolean().nullish(),
4082
4065
  status: z25.enum(["in_progress", "completed", "incomplete"]),
4083
4066
  namespace: z25.string().nullish(),
4084
4067
  caller: openaiResponsesToolCallerSchema.nullish()
@@ -4091,6 +4074,7 @@ var openaiResponsesChunkSchema = lazySchema24(
4091
4074
  call_id: z25.string(),
4092
4075
  name: z25.string(),
4093
4076
  input: z25.string(),
4077
+ async: z25.boolean().nullish(),
4094
4078
  status: z25.literal("completed")
4095
4079
  }),
4096
4080
  z25.object({
@@ -4528,6 +4512,7 @@ var openaiResponsesResponseSchema = lazySchema24(
4528
4512
  name: z25.string(),
4529
4513
  arguments: z25.string(),
4530
4514
  id: z25.string(),
4515
+ async: z25.boolean().nullish(),
4531
4516
  namespace: z25.string().nullish(),
4532
4517
  caller: openaiResponsesToolCallerSchema.nullish()
4533
4518
  }),
@@ -4538,7 +4523,8 @@ var openaiResponsesResponseSchema = lazySchema24(
4538
4523
  call_id: z25.string(),
4539
4524
  name: z25.string(),
4540
4525
  input: z25.string(),
4541
- id: z25.string()
4526
+ id: z25.string(),
4527
+ async: z25.boolean().nullish()
4542
4528
  }),
4543
4529
  openaiResponsesComputerCallSchema,
4544
4530
  z25.object({
@@ -4700,6 +4686,28 @@ import {
4700
4686
  WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
4701
4687
  } from "@ai-sdk/provider-utils";
4702
4688
 
4689
+ // src/openai-config.ts
4690
+ function prepareOpenAIConfigForWorkflowDeserialize(config) {
4691
+ if (config.provider == null) {
4692
+ throw new Error(
4693
+ "OpenAI model is missing provider after workflow deserialization."
4694
+ );
4695
+ }
4696
+ return {
4697
+ ...config,
4698
+ provider: config.provider,
4699
+ url: typeof config.url === "function" ? config.url : ({ path }) => {
4700
+ if (config.baseURL == null) {
4701
+ throw new Error(
4702
+ "OpenAI model is missing baseURL after workflow deserialization."
4703
+ );
4704
+ }
4705
+ return `${config.baseURL}${path}`;
4706
+ },
4707
+ headers: typeof config.headers === "function" ? config.headers : config.headers == null ? void 0 : () => config.headers
4708
+ };
4709
+ }
4710
+
4703
4711
  // src/responses/convert-to-openai-responses-input.ts
4704
4712
  import {
4705
4713
  UnsupportedFunctionalityError as UnsupportedFunctionalityError4
@@ -5004,7 +5012,7 @@ async function convertToOpenAIResponsesInput({
5004
5012
  customProviderToolNames,
5005
5013
  outputSchemaToolNames
5006
5014
  }) {
5007
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K;
5015
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
5008
5016
  let input = [];
5009
5017
  const warnings = [];
5010
5018
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -5224,7 +5232,8 @@ async function convertToOpenAIResponsesInput({
5224
5232
  }
5225
5233
  const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
5226
5234
  const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
5227
- const caller = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.caller;
5235
+ const isAsync = (_p = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.async) != null ? _p : (_o = (_n = part.providerMetadata) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.async;
5236
+ const caller = (_r = (_q = part.providerOptions) == null ? void 0 : _q[providerOptionsName]) == null ? void 0 : _r.caller;
5228
5237
  if (hasConversation && id != null) {
5229
5238
  break;
5230
5239
  }
@@ -5248,7 +5257,7 @@ async function convertToOpenAIResponsesInput({
5248
5257
  type: "tool_search_call",
5249
5258
  id: id != null ? id : part.toolCallId,
5250
5259
  execution,
5251
- call_id: (_n = parsedInput.call_id) != null ? _n : null,
5260
+ call_id: (_s = parsedInput.call_id) != null ? _s : null,
5252
5261
  status: "completed",
5253
5262
  arguments: parsedInput.arguments
5254
5263
  });
@@ -5280,7 +5289,7 @@ async function convertToOpenAIResponsesInput({
5280
5289
  break;
5281
5290
  }
5282
5291
  }
5283
- const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || ((_o = customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) != null ? _o : false);
5292
+ const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || ((_t = customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) != null ? _t : false);
5284
5293
  if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
5285
5294
  break;
5286
5295
  }
@@ -5393,6 +5402,7 @@ async function convertToOpenAIResponsesInput({
5393
5402
  call_id: part.toolCallId,
5394
5403
  name: resolvedToolName,
5395
5404
  input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
5405
+ ...isAsync != null && { async: isAsync },
5396
5406
  id
5397
5407
  });
5398
5408
  break;
@@ -5402,6 +5412,7 @@ async function convertToOpenAIResponsesInput({
5402
5412
  call_id: part.toolCallId,
5403
5413
  name: resolvedToolName,
5404
5414
  arguments: serializeToolCallArguments2(part.input),
5415
+ ...isAsync != null && { async: isAsync },
5405
5416
  ...namespace != null && { namespace },
5406
5417
  ...caller != null && {
5407
5418
  caller: mapToolCaller(caller)
@@ -5421,7 +5432,7 @@ async function convertToOpenAIResponsesInput({
5421
5432
  part.toolName
5422
5433
  );
5423
5434
  if (part.toolName === toolSearchToolName) {
5424
- const itemId = (_u = (_t = (_q = (_p = part.providerOptions) == null ? void 0 : _p[providerOptionsName]) == null ? void 0 : _q.itemId) != null ? _t : (_s = (_r = part.providerMetadata) == null ? void 0 : _r[providerOptionsName]) == null ? void 0 : _s.itemId) != null ? _u : part.toolCallId;
5435
+ const itemId = (_z = (_y = (_v = (_u = part.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.itemId) != null ? _y : (_x = (_w = part.providerMetadata) == null ? void 0 : _w[providerOptionsName]) == null ? void 0 : _x.itemId) != null ? _z : part.toolCallId;
5425
5436
  if (store) {
5426
5437
  input.push({ type: "item_reference", id: itemId });
5427
5438
  } else if (part.output.type === "json") {
@@ -5441,7 +5452,7 @@ async function convertToOpenAIResponsesInput({
5441
5452
  break;
5442
5453
  }
5443
5454
  if (resolvedResultToolName === "programmatic_tool_calling") {
5444
- const itemId = (_A = (_z = (_w = (_v = part.providerOptions) == null ? void 0 : _v[providerOptionsName]) == null ? void 0 : _w.itemId) != null ? _z : (_y = (_x = part.providerMetadata) == null ? void 0 : _x[providerOptionsName]) == null ? void 0 : _y.itemId) != null ? _A : part.toolCallId;
5455
+ const itemId = (_F = (_E = (_B = (_A = part.providerOptions) == null ? void 0 : _A[providerOptionsName]) == null ? void 0 : _B.itemId) != null ? _E : (_D = (_C = part.providerMetadata) == null ? void 0 : _C[providerOptionsName]) == null ? void 0 : _D.itemId) != null ? _F : part.toolCallId;
5445
5456
  if (store) {
5446
5457
  input.push({ type: "item_reference", id: itemId });
5447
5458
  } else if (part.output.type === "json") {
@@ -5481,7 +5492,7 @@ async function convertToOpenAIResponsesInput({
5481
5492
  break;
5482
5493
  }
5483
5494
  if (store) {
5484
- const itemId = (_D = (_C = (_B = part.providerOptions) == null ? void 0 : _B[providerOptionsName]) == null ? void 0 : _C.itemId) != null ? _D : part.toolCallId;
5495
+ const itemId = (_I = (_H = (_G = part.providerOptions) == null ? void 0 : _G[providerOptionsName]) == null ? void 0 : _H.itemId) != null ? _I : part.toolCallId;
5485
5496
  input.push({ type: "item_reference", id: itemId });
5486
5497
  } else {
5487
5498
  warnings.push({
@@ -5566,7 +5577,7 @@ async function convertToOpenAIResponsesInput({
5566
5577
  }
5567
5578
  case "custom": {
5568
5579
  if (part.kind === "openai.compaction") {
5569
- const providerOptions2 = (_E = part.providerOptions) == null ? void 0 : _E[providerOptionsName];
5580
+ const providerOptions2 = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName];
5570
5581
  const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
5571
5582
  if (hasConversation && id != null) {
5572
5583
  break;
@@ -5672,7 +5683,7 @@ ${text}`,
5672
5683
  }
5673
5684
  const output = part.output;
5674
5685
  if (output.type === "execution-denied") {
5675
- const approvalId = (_G = (_F = output.providerOptions) == null ? void 0 : _F.openai) == null ? void 0 : _G.approvalId;
5686
+ const approvalId = (_L = (_K = output.providerOptions) == null ? void 0 : _K.openai) == null ? void 0 : _L.approvalId;
5676
5687
  if (approvalId) {
5677
5688
  continue;
5678
5689
  }
@@ -5752,7 +5763,7 @@ ${text}`,
5752
5763
  file_id: parsedOutput.output.fileId,
5753
5764
  detail: parsedOutput.output.detail
5754
5765
  },
5755
- acknowledged_safety_checks: (_H = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _H.map((safetyCheck) => ({
5766
+ acknowledged_safety_checks: (_M = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _M.map((safetyCheck) => ({
5756
5767
  id: safetyCheck.id,
5757
5768
  code: safetyCheck.code,
5758
5769
  message: safetyCheck.message
@@ -5781,7 +5792,7 @@ ${text}`,
5781
5792
  break;
5782
5793
  case "execution-denied":
5783
5794
  outputValue = convertScalarOutput(
5784
- (_I = output.reason) != null ? _I : "Tool call execution denied."
5795
+ (_N = output.reason) != null ? _N : "Tool call execution denied."
5785
5796
  );
5786
5797
  break;
5787
5798
  case "json":
@@ -5887,7 +5898,7 @@ ${text}`,
5887
5898
  warnings
5888
5899
  });
5889
5900
  const caller = mapToolCaller(
5890
- (_K = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName]) == null ? void 0 : _K.caller
5901
+ (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller
5891
5902
  );
5892
5903
  input.push({
5893
5904
  type: "function_call_output",
@@ -6234,7 +6245,8 @@ async function prepareResponsesTools({
6234
6245
  allowedTools,
6235
6246
  toolNameMapping,
6236
6247
  customProviderToolNames,
6237
- outputSchemaToolNames
6248
+ outputSchemaToolNames,
6249
+ supportsAsyncToolCalling = true
6238
6250
  }) {
6239
6251
  var _a2, _b, _c, _d;
6240
6252
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
@@ -6268,7 +6280,13 @@ async function prepareResponsesTools({
6268
6280
  }
6269
6281
  const openaiFunctionTool = prepareFunctionTool({
6270
6282
  tool,
6271
- options: openaiOptions
6283
+ options: openaiOptions,
6284
+ async: resolveAsyncToolOption({
6285
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
6286
+ supportsAsyncToolCalling,
6287
+ toolName: tool.name,
6288
+ toolWarnings
6289
+ })
6272
6290
  });
6273
6291
  const namespace = openaiOptions == null ? void 0 : openaiOptions.namespace;
6274
6292
  if (namespace == null) {
@@ -6457,6 +6475,12 @@ async function prepareResponsesTools({
6457
6475
  type: "custom",
6458
6476
  name: tool.name,
6459
6477
  description: args.description,
6478
+ ...resolveAsyncToolOption({
6479
+ value: args.async,
6480
+ supportsAsyncToolCalling,
6481
+ toolName: tool.name,
6482
+ toolWarnings
6483
+ }) != null ? { async: args.async } : {},
6460
6484
  format: args.format
6461
6485
  });
6462
6486
  resolvedCustomProviderToolNames.add(tool.name);
@@ -6636,7 +6660,8 @@ function toAllowedToolResolution(tool) {
6636
6660
  }
6637
6661
  function prepareFunctionTool({
6638
6662
  tool,
6639
- options
6663
+ options,
6664
+ async
6640
6665
  }) {
6641
6666
  const deferLoading = options == null ? void 0 : options.deferLoading;
6642
6667
  return {
@@ -6644,12 +6669,29 @@ function prepareFunctionTool({
6644
6669
  name: tool.name,
6645
6670
  description: tool.description,
6646
6671
  parameters: tool.inputSchema,
6672
+ ...async != null ? { async } : {},
6647
6673
  ...tool.strict != null ? { strict: tool.strict } : {},
6648
6674
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
6649
6675
  ...(options == null ? void 0 : options.allowedCallers) != null ? { allowed_callers: options.allowedCallers } : {},
6650
6676
  ...(options == null ? void 0 : options.outputSchema) != null ? { output_schema: options.outputSchema } : {}
6651
6677
  };
6652
6678
  }
6679
+ function resolveAsyncToolOption({
6680
+ value,
6681
+ supportsAsyncToolCalling,
6682
+ toolName,
6683
+ toolWarnings
6684
+ }) {
6685
+ if (value !== true || supportsAsyncToolCalling) {
6686
+ return value;
6687
+ }
6688
+ toolWarnings.push({
6689
+ type: "unsupported",
6690
+ feature: `async tool calling for "${toolName}"`,
6691
+ details: "Async tool calling is only supported by GPT-6 and later models."
6692
+ });
6693
+ return void 0;
6694
+ }
6653
6695
  function mapShellEnvironment(environment) {
6654
6696
  if (environment.type === "containerReference") {
6655
6697
  const env2 = environment;
@@ -6787,13 +6829,14 @@ function mapComputerCallInput({
6787
6829
  status
6788
6830
  };
6789
6831
  }
6832
+ var openaiResponsesSupportedUrls = {
6833
+ "image/*": [/^https?:\/\/.*$/],
6834
+ "application/pdf": [/^https?:\/\/.*$/]
6835
+ };
6790
6836
  var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6791
6837
  constructor(modelId, config) {
6792
6838
  this.specificationVersion = "v4";
6793
- this.supportedUrls = {
6794
- "image/*": [/^https?:\/\/.*$/],
6795
- "application/pdf": [/^https?:\/\/.*$/]
6796
- };
6839
+ this.supportedUrls = openaiResponsesSupportedUrls;
6797
6840
  this.modelId = modelId;
6798
6841
  this.config = config;
6799
6842
  }
@@ -6812,25 +6855,29 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6812
6855
  get provider() {
6813
6856
  return this.config.provider;
6814
6857
  }
6815
- async getArgs({
6816
- maxOutputTokens,
6817
- temperature,
6818
- stopSequences,
6819
- topP,
6820
- topK,
6821
- presencePenalty,
6822
- frequencyPenalty,
6823
- seed,
6824
- prompt,
6825
- reasoning,
6826
- providerOptions,
6827
- tools,
6828
- toolChoice,
6829
- responseFormat
6858
+ static async prepareRequest({
6859
+ modelId,
6860
+ config,
6861
+ options: {
6862
+ maxOutputTokens,
6863
+ temperature,
6864
+ stopSequences,
6865
+ topP,
6866
+ topK,
6867
+ presencePenalty,
6868
+ frequencyPenalty,
6869
+ seed,
6870
+ prompt,
6871
+ reasoning,
6872
+ providerOptions,
6873
+ tools,
6874
+ toolChoice,
6875
+ responseFormat
6876
+ }
6830
6877
  }) {
6831
6878
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
6832
6879
  const warnings = [];
6833
- const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
6880
+ const modelCapabilities = getOpenAILanguageModelCapabilities(modelId);
6834
6881
  if (topK != null) {
6835
6882
  warnings.push({ type: "unsupported", feature: "topK" });
6836
6883
  }
@@ -6846,7 +6893,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6846
6893
  if (stopSequences != null) {
6847
6894
  warnings.push({ type: "unsupported", feature: "stopSequences" });
6848
6895
  }
6849
- const providerOptionsName = this.config.provider.includes("azure") ? "azure" : "openai";
6896
+ const providerOptionsName = config.provider.includes("azure") ? "azure" : "openai";
6850
6897
  let openaiOptions = await parseProviderOptions7({
6851
6898
  provider: providerOptionsName,
6852
6899
  providerOptions,
@@ -6866,7 +6913,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6866
6913
  warnings.push({
6867
6914
  type: "unsupported",
6868
6915
  feature: "reasoningEffort",
6869
- details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
6916
+ details: `${modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
6870
6917
  });
6871
6918
  resolvedReasoningEffort = void 0;
6872
6919
  }
@@ -6908,14 +6955,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6908
6955
  allowedTools: (_c = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _c : void 0,
6909
6956
  toolNameMapping,
6910
6957
  customProviderToolNames,
6911
- outputSchemaToolNames
6958
+ outputSchemaToolNames,
6959
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
6912
6960
  });
6913
6961
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
6914
6962
  prompt,
6915
6963
  toolNameMapping,
6916
6964
  systemMessageMode: (_d = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
6917
6965
  providerOptionsName,
6918
- fileIdPrefixes: this.config.fileIdPrefixes,
6966
+ fileIdPrefixes: config.fileIdPrefixes,
6919
6967
  passThroughUnsupportedFiles: (_e = openaiOptions == null ? void 0 : openaiOptions.passThroughUnsupportedFiles) != null ? _e : false,
6920
6968
  store: (_f = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _f : true,
6921
6969
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
@@ -6980,7 +7028,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6980
7028
  addInclude("reasoning.encrypted_content");
6981
7029
  }
6982
7030
  const baseArgs = {
6983
- model: this.modelId,
7031
+ model: modelId,
6984
7032
  input,
6985
7033
  temperature,
6986
7034
  top_p: topP,
@@ -7146,6 +7194,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7146
7194
  isShellProviderExecuted
7147
7195
  };
7148
7196
  }
7197
+ getArgs(options) {
7198
+ return _OpenAIResponsesLanguageModel.prepareRequest({
7199
+ modelId: this.modelId,
7200
+ config: this.config,
7201
+ options
7202
+ });
7203
+ }
7149
7204
  async doGenerate(options) {
7150
7205
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H;
7151
7206
  const {
@@ -7442,6 +7497,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7442
7497
  providerMetadata: {
7443
7498
  [providerOptionsName]: {
7444
7499
  itemId: part.id,
7500
+ ...part.async != null && { async: part.async },
7445
7501
  ...part.namespace != null && { namespace: part.namespace },
7446
7502
  ...part.caller != null && {
7447
7503
  caller: part.caller.type === "program" ? {
@@ -7503,7 +7559,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7503
7559
  input: JSON.stringify(part.input),
7504
7560
  providerMetadata: {
7505
7561
  [providerOptionsName]: {
7506
- itemId: part.id
7562
+ itemId: part.id,
7563
+ ...part.async != null && { async: part.async }
7507
7564
  }
7508
7565
  }
7509
7566
  });
@@ -7830,7 +7887,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7830
7887
  toolName: value.item.name,
7831
7888
  toolCallId: value.item.call_id,
7832
7889
  suppressInputStreaming,
7833
- bufferedInputDeltas: suppressInputStreaming ? [] : void 0
7890
+ bufferedInputDeltas: suppressInputStreaming ? [] : void 0,
7891
+ async: value.item.async
7834
7892
  };
7835
7893
  if (!suppressInputStreaming) {
7836
7894
  controller.enqueue({
@@ -7845,7 +7903,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7845
7903
  );
7846
7904
  ongoingToolCalls[value.output_index] = {
7847
7905
  toolName,
7848
- toolCallId: value.item.call_id
7906
+ toolCallId: value.item.call_id,
7907
+ async: value.item.async
7849
7908
  };
7850
7909
  controller.enqueue({
7851
7910
  type: "tool-input-start",
@@ -8096,6 +8155,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8096
8155
  providerMetadata: {
8097
8156
  [providerOptionsName]: {
8098
8157
  itemId: item.id,
8158
+ ...item.async != null ? { async: item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {},
8099
8159
  ...item.namespace != null && {
8100
8160
  namespace: item.namespace
8101
8161
  },
@@ -8181,6 +8241,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8181
8241
  }
8182
8242
  });
8183
8243
  } else if (value.item.type === "custom_tool_call") {
8244
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
8184
8245
  ongoingToolCalls[value.output_index] = void 0;
8185
8246
  hasFunctionCall = true;
8186
8247
  const toolName = toolNameMapping.toCustomToolName(
@@ -8197,7 +8258,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8197
8258
  input: JSON.stringify(value.item.input),
8198
8259
  providerMetadata: {
8199
8260
  [providerOptionsName]: {
8200
- itemId: value.item.id
8261
+ itemId: value.item.id,
8262
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
8201
8263
  }
8202
8264
  }
8203
8265
  });
@@ -8991,7 +9053,7 @@ function escapeJSONDelta(delta) {
8991
9053
  return JSON.stringify(delta).slice(1, -1);
8992
9054
  }
8993
9055
 
8994
- // src/openai-responses-batch.ts
9056
+ // src/openai-batch.ts
8995
9057
  var openaiBatchEndpoint = "/v1/responses";
8996
9058
  var openaiBatchInputFileDefaultExpiresAfterSeconds = 48 * 60 * 60;
8997
9059
  var openaiBatchProviderOptionsSchema = lazySchema26(
@@ -9047,12 +9109,16 @@ var openaiBatchResultLineSchema = lazySchema26(
9047
9109
  })
9048
9110
  )
9049
9111
  );
9050
- var OpenAIResponsesBatch = class {
9112
+ var OpenAIBatch = class {
9051
9113
  constructor(options) {
9052
9114
  this.options = options;
9115
+ this.specificationVersion = "v4";
9116
+ this.supportedUrls = openaiResponsesSupportedUrls;
9117
+ this.provider = options.provider;
9053
9118
  }
9054
- async startBatch(options) {
9119
+ async doStartBatch(options) {
9055
9120
  var _a2, _b, _c, _d, _e, _f;
9121
+ validateSingleModel(options.requests);
9056
9122
  const fileParts = [];
9057
9123
  const warnings = options.webhookUrl == null ? [] : [
9058
9124
  {
@@ -9068,7 +9134,7 @@ var OpenAIResponsesBatch = class {
9068
9134
  );
9069
9135
  const inputFileExpiresAfterSeconds = (_a2 = batchOptions == null ? void 0 : batchOptions.inputFileExpiresAfter) != null ? _a2 : openaiBatchInputFileDefaultExpiresAfterSeconds;
9070
9136
  for (const request of options.requests) {
9071
- const preparedRequest = await this.options.prepareRequest(request);
9137
+ const preparedRequest = await this.prepareRequest(request);
9072
9138
  fileParts.push(
9073
9139
  JSON.stringify({
9074
9140
  custom_id: request.id,
@@ -9174,11 +9240,11 @@ var OpenAIResponsesBatch = class {
9174
9240
  }
9175
9241
  return batchOptions;
9176
9242
  }
9177
- async getBatchStatus(options) {
9243
+ async doGetBatchStatus(options) {
9178
9244
  const batch = await this.retrieveBatch(options);
9179
9245
  return convertOpenAIBatchStatus(batch);
9180
9246
  }
9181
- async getBatchResults(options) {
9247
+ async doGetBatchResults(options) {
9182
9248
  const batch = await this.retrieveBatch(options);
9183
9249
  const batchStatus = convertOpenAIBatchStatus(batch);
9184
9250
  if (batchStatus.status === "pending") {
@@ -9246,15 +9312,16 @@ var OpenAIResponsesBatch = class {
9246
9312
  code: line.error.code
9247
9313
  };
9248
9314
  if (line.error.code === "batch_cancelled") {
9249
- return { id: line.custom_id, status: "cancelled", error };
9315
+ return { type: "text", id: line.custom_id, status: "cancelled", error };
9250
9316
  }
9251
9317
  if (line.error.code === "batch_expired") {
9252
- return { id: line.custom_id, status: "expired", error };
9318
+ return { type: "text", id: line.custom_id, status: "expired", error };
9253
9319
  }
9254
- return { id: line.custom_id, status: "failed", error };
9320
+ return { type: "text", id: line.custom_id, status: "failed", error };
9255
9321
  }
9256
9322
  if (line.response == null) {
9257
9323
  return {
9324
+ type: "text",
9258
9325
  id: line.custom_id,
9259
9326
  status: "failed",
9260
9327
  error: {
@@ -9265,6 +9332,7 @@ var OpenAIResponsesBatch = class {
9265
9332
  }
9266
9333
  if (line.response.status_code < 200 || line.response.status_code >= 300) {
9267
9334
  return {
9335
+ type: "text",
9268
9336
  id: line.custom_id,
9269
9337
  status: "failed",
9270
9338
  error: await convertOpenAIErrorResponse({
@@ -9273,29 +9341,46 @@ var OpenAIResponsesBatch = class {
9273
9341
  })
9274
9342
  };
9275
9343
  }
9276
- const conversion = await convertOpenAIResponsesBatchResponse(
9277
- line.response.body
9278
- );
9344
+ const conversion = await convertOpenAIBatchResult(line.response.body);
9279
9345
  if (!conversion.success) {
9280
9346
  return {
9347
+ type: "text",
9281
9348
  id: line.custom_id,
9282
9349
  status: "failed",
9283
9350
  error: conversion.error
9284
9351
  };
9285
9352
  }
9286
9353
  return {
9354
+ type: "text",
9287
9355
  id: line.custom_id,
9288
9356
  status: "succeeded",
9289
9357
  result: conversion.result
9290
9358
  };
9291
9359
  }
9292
- getUrl(path) {
9293
- return this.options.config.url({
9294
- modelId: this.options.modelId,
9295
- path
9360
+ async prepareRequest(request) {
9361
+ const { args: body, warnings } = await OpenAIResponsesLanguageModel.prepareRequest({
9362
+ modelId: request.modelId,
9363
+ config: this.options.config,
9364
+ options: request.options
9296
9365
  });
9366
+ return { body, warnings };
9367
+ }
9368
+ getUrl(path) {
9369
+ return this.options.config.url({ path, modelId: "" });
9297
9370
  }
9298
9371
  };
9372
+ function validateSingleModel(requests) {
9373
+ var _a2;
9374
+ const modelId = (_a2 = requests[0]) == null ? void 0 : _a2.modelId;
9375
+ for (const request of requests) {
9376
+ if (request.modelId !== modelId) {
9377
+ throw new InvalidArgumentError2({
9378
+ argument: "requests",
9379
+ message: `The OpenAI Batch API requires all requests in a batch to use the same model. Found "${modelId}" and "${request.modelId}".`
9380
+ });
9381
+ }
9382
+ }
9383
+ }
9299
9384
  var openAIBatchConvertibleProviderToolIds = /* @__PURE__ */ new Set([
9300
9385
  "openai.code_interpreter",
9301
9386
  "openai.custom",
@@ -9303,37 +9388,6 @@ var openAIBatchConvertibleProviderToolIds = /* @__PURE__ */ new Set([
9303
9388
  "openai.web_search",
9304
9389
  "openai.web_search_preview"
9305
9390
  ]);
9306
- var OpenAIResponsesBatchLanguageModel = class _OpenAIResponsesBatchLanguageModel extends OpenAIResponsesLanguageModel {
9307
- static [WORKFLOW_SERIALIZE6](model) {
9308
- return OpenAIResponsesLanguageModel[WORKFLOW_SERIALIZE6](model);
9309
- }
9310
- static [WORKFLOW_DESERIALIZE6](options) {
9311
- return new _OpenAIResponsesBatchLanguageModel(
9312
- options.modelId,
9313
- prepareOpenAIConfigForWorkflowDeserialize(options.config)
9314
- );
9315
- }
9316
- constructor(modelId, config) {
9317
- super(modelId, config);
9318
- this.batch = new OpenAIResponsesBatch({
9319
- modelId,
9320
- config,
9321
- prepareRequest: async (request) => {
9322
- const { args: body, warnings } = await this.getArgs(request.options);
9323
- return { body, warnings };
9324
- }
9325
- });
9326
- }
9327
- experimental_doStartBatch(options) {
9328
- return this.batch.startBatch(options);
9329
- }
9330
- experimental_doGetBatchStatus(options) {
9331
- return this.batch.getBatchStatus(options);
9332
- }
9333
- experimental_doGetBatchResults(options) {
9334
- return this.batch.getBatchResults(options);
9335
- }
9336
- };
9337
9391
  function convertOpenAIBatchStatus(batch) {
9338
9392
  var _a2, _b, _c;
9339
9393
  const status = mapOpenAIBatchStatus(batch.status);
@@ -9411,7 +9465,7 @@ async function convertOpenAIErrorResponse({
9411
9465
  statusCode
9412
9466
  };
9413
9467
  }
9414
- async function convertOpenAIResponsesBatchResponse(body) {
9468
+ async function convertOpenAIBatchResult(body) {
9415
9469
  var _a2, _b, _c, _d, _e, _f, _g, _h;
9416
9470
  const validation = await safeValidateTypes({
9417
9471
  value: body,
@@ -10005,8 +10059,8 @@ import {
10005
10059
  parseProviderOptions as parseProviderOptions9,
10006
10060
  postJsonToApi as postJsonToApi7,
10007
10061
  serializeModelOptions as serializeModelOptions6,
10008
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE7,
10009
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7
10062
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
10063
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
10010
10064
  } from "@ai-sdk/provider-utils";
10011
10065
 
10012
10066
  // src/speech/openai-speech-model-options.ts
@@ -10031,13 +10085,13 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
10031
10085
  this.config = config;
10032
10086
  this.specificationVersion = "v4";
10033
10087
  }
10034
- static [WORKFLOW_SERIALIZE7](model) {
10088
+ static [WORKFLOW_SERIALIZE6](model) {
10035
10089
  return serializeModelOptions6({
10036
10090
  modelId: model.modelId,
10037
10091
  config: model.config
10038
10092
  });
10039
10093
  }
10040
- static [WORKFLOW_DESERIALIZE7](options) {
10094
+ static [WORKFLOW_DESERIALIZE6](options) {
10041
10095
  return new _OpenAISpeechModel(options.modelId, options.config);
10042
10096
  }
10043
10097
  get provider() {
@@ -10150,8 +10204,8 @@ import {
10150
10204
  safeParseJSON as safeParseJSON2,
10151
10205
  serializeModelOptions as serializeModelOptions7,
10152
10206
  toWebSocketUrl,
10153
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE8,
10154
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE8,
10207
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE7,
10208
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7,
10155
10209
  waitForWebSocketBufferDrain
10156
10210
  } from "@ai-sdk/provider-utils";
10157
10211
 
@@ -10332,13 +10386,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10332
10386
  this.config = config;
10333
10387
  this.specificationVersion = "v4";
10334
10388
  }
10335
- static [WORKFLOW_SERIALIZE8](model) {
10389
+ static [WORKFLOW_SERIALIZE7](model) {
10336
10390
  return serializeModelOptions7({
10337
10391
  modelId: model.modelId,
10338
10392
  config: model.config
10339
10393
  });
10340
10394
  }
10341
- static [WORKFLOW_DESERIALIZE8](options) {
10395
+ static [WORKFLOW_DESERIALIZE7](options) {
10342
10396
  return new _OpenAITranscriptionModel(options.modelId, options.config);
10343
10397
  }
10344
10398
  get provider() {
@@ -10744,8 +10798,8 @@ import {
10744
10798
  safeParseJSON as safeParseJSON3,
10745
10799
  serializeModelOptions as serializeModelOptions8,
10746
10800
  toWebSocketUrl as toWebSocketUrl2,
10747
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE9,
10748
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE9,
10801
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE8,
10802
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE8,
10749
10803
  waitForWebSocketBufferDrain as waitForWebSocketBufferDrain2
10750
10804
  } from "@ai-sdk/provider-utils";
10751
10805
 
@@ -10766,13 +10820,13 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
10766
10820
  this.config = config;
10767
10821
  this.specificationVersion = "v4";
10768
10822
  }
10769
- static [WORKFLOW_SERIALIZE9](model) {
10823
+ static [WORKFLOW_SERIALIZE8](model) {
10770
10824
  return serializeModelOptions8({
10771
10825
  modelId: model.modelId,
10772
10826
  config: model.config
10773
10827
  });
10774
10828
  }
10775
- static [WORKFLOW_DESERIALIZE9](options) {
10829
+ static [WORKFLOW_DESERIALIZE8](options) {
10776
10830
  return new _OpenAISpeechTranslationModel(options.modelId, options.config);
10777
10831
  }
10778
10832
  get provider() {
@@ -11134,7 +11188,7 @@ var OpenAISkills = class {
11134
11188
  };
11135
11189
 
11136
11190
  // src/version.ts
11137
- var VERSION = true ? "4.0.60" : "0.0.0-test";
11191
+ var VERSION = true ? "4.0.62" : "0.0.0-test";
11138
11192
 
11139
11193
  // src/openai-provider.ts
11140
11194
  function createOpenAI(options = {}) {
@@ -11226,7 +11280,7 @@ function createOpenAI(options = {}) {
11226
11280
  return createResponsesModel(modelId);
11227
11281
  };
11228
11282
  const createResponsesModel = (modelId) => {
11229
- return new OpenAIResponsesBatchLanguageModel(modelId, {
11283
+ return new OpenAIResponsesLanguageModel(modelId, {
11230
11284
  provider: `${providerName}.responses`,
11231
11285
  baseURL,
11232
11286
  url: ({ path }) => `${baseURL}${path}`,
@@ -11236,6 +11290,18 @@ function createOpenAI(options = {}) {
11236
11290
  fileIdPrefixes: ["file-"]
11237
11291
  });
11238
11292
  };
11293
+ const createBatch = () => new OpenAIBatch({
11294
+ provider: `${providerName}.batch`,
11295
+ config: {
11296
+ provider: `${providerName}.responses`,
11297
+ baseURL,
11298
+ url: ({ path }) => `${baseURL}${path}`,
11299
+ headers: getHeaders,
11300
+ fetch: options.fetch,
11301
+ // Soft-deprecated. TODO: remove in v8
11302
+ fileIdPrefixes: ["file-"]
11303
+ }
11304
+ });
11239
11305
  const createRealtimeModel = (modelId) => new OpenAIRealtimeModel(modelId, {
11240
11306
  provider: `${providerName}.realtime`,
11241
11307
  baseURL,
@@ -11281,6 +11347,7 @@ function createOpenAI(options = {}) {
11281
11347
  provider.speechModel = createSpeechModel;
11282
11348
  provider.files = createFiles;
11283
11349
  provider.skills = createSkills;
11350
+ provider.experimental_batch = createBatch;
11284
11351
  provider.experimental_realtime = experimentalRealtimeFactory;
11285
11352
  provider.tools = openaiTools;
11286
11353
  return provider;