@ai-sdk/openai 4.0.60 → 4.0.61

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