@ai-sdk/openai 2.0.124 → 2.0.126

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.
@@ -38,14 +38,18 @@ function getOpenAILanguageModelCapabilities(modelId) {
38
38
  const gptVersion = getGptVersion(modelId);
39
39
  const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a2 = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a2.startsWith("chat")) != null ? _b : false);
40
40
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
41
+ const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
41
42
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
42
43
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
43
44
  const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel || modelId === "codex-mini-latest" || modelId === "computer-use-preview";
44
- const supportsNonReasoningParameters = gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
45
+ const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
45
46
  const systemMessageMode = isReasoningModel ? "developer" : "system";
46
47
  return {
47
48
  supportsFlexProcessing,
48
49
  supportsPriorityProcessing,
50
+ supportsConfigurationUpdate: isGpt6OrLaterModel,
51
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
52
+ supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
49
53
  isReasoningModel,
50
54
  systemMessageMode,
51
55
  supportsNonReasoningParameters
@@ -740,6 +744,17 @@ var OpenAIChatLanguageModel = class {
740
744
  );
741
745
  warnings.push(...messageWarnings);
742
746
  const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
747
+ let resolvedReasoningEffort = openaiOptions.reasoningEffort;
748
+ if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
749
+ resolvedReasoningEffort
750
+ )) {
751
+ warnings.push({
752
+ type: "unsupported-setting",
753
+ setting: "reasoningEffort",
754
+ details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
755
+ });
756
+ resolvedReasoningEffort = void 0;
757
+ }
743
758
  const baseArgs = {
744
759
  // model id:
745
760
  model: this.modelId,
@@ -773,7 +788,7 @@ var OpenAIChatLanguageModel = class {
773
788
  store: openaiOptions.store,
774
789
  metadata: openaiOptions.metadata,
775
790
  prediction: openaiOptions.prediction,
776
- reasoning_effort: openaiOptions.reasoningEffort,
791
+ reasoning_effort: resolvedReasoningEffort,
777
792
  service_tier: openaiOptions.serviceTier,
778
793
  prompt_cache_key: openaiOptions.promptCacheKey,
779
794
  prompt_cache_options: openaiOptions.promptCacheOptions,
@@ -782,6 +797,14 @@ var OpenAIChatLanguageModel = class {
782
797
  // messages:
783
798
  messages
784
799
  };
800
+ if (modelCapabilities.supportedReasoningEfforts != null && baseArgs.prompt_cache_retention != null) {
801
+ baseArgs.prompt_cache_retention = void 0;
802
+ warnings.push({
803
+ type: "unsupported-setting",
804
+ setting: "promptCacheRetention",
805
+ details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
806
+ });
807
+ }
785
808
  if (modelCapabilities.isReasoningModel) {
786
809
  if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
787
810
  if (baseArgs.temperature != null) {
@@ -2441,11 +2464,12 @@ function isFileId(data, prefixes) {
2441
2464
  async function convertToOpenAIResponsesInput({
2442
2465
  prompt,
2443
2466
  systemMessageMode,
2467
+ explicitMessageItemType = false,
2444
2468
  fileIdPrefixes,
2445
2469
  store,
2446
2470
  hasLocalShellTool = false
2447
2471
  }) {
2448
- var _a2, _b, _c, _d, _e, _f;
2472
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2449
2473
  let input = [];
2450
2474
  const warnings = [];
2451
2475
  for (const { role, content, providerOptions } of prompt) {
@@ -2455,6 +2479,7 @@ async function convertToOpenAIResponsesInput({
2455
2479
  case "system": {
2456
2480
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2457
2481
  input.push({
2482
+ ...explicitMessageItemType && { type: "message" },
2458
2483
  role: "system",
2459
2484
  content: promptCacheBreakpoint == null ? content : [
2460
2485
  {
@@ -2469,6 +2494,7 @@ async function convertToOpenAIResponsesInput({
2469
2494
  case "developer": {
2470
2495
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2471
2496
  input.push({
2497
+ ...explicitMessageItemType && { type: "message" },
2472
2498
  role: "developer",
2473
2499
  content: promptCacheBreakpoint == null ? content : [
2474
2500
  {
@@ -2498,6 +2524,7 @@ async function convertToOpenAIResponsesInput({
2498
2524
  }
2499
2525
  case "user": {
2500
2526
  input.push({
2527
+ ...explicitMessageItemType && { type: "message" },
2501
2528
  role: "user",
2502
2529
  content: content.map((part, index) => {
2503
2530
  var _a3, _b2, _c2;
@@ -2574,6 +2601,7 @@ async function convertToOpenAIResponsesInput({
2574
2601
  break;
2575
2602
  }
2576
2603
  input.push({
2604
+ ...explicitMessageItemType && { type: "message" },
2577
2605
  role: "assistant",
2578
2606
  content: [{ type: "output_text", text: part.text }],
2579
2607
  id,
@@ -2587,6 +2615,7 @@ async function convertToOpenAIResponsesInput({
2587
2615
  break;
2588
2616
  }
2589
2617
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2618
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2590
2619
  if (store && id != null) {
2591
2620
  input.push({ type: "item_reference", id });
2592
2621
  break;
@@ -2616,6 +2645,7 @@ async function convertToOpenAIResponsesInput({
2616
2645
  call_id: part.toolCallId,
2617
2646
  name: part.toolName,
2618
2647
  arguments: JSON.stringify(part.input),
2648
+ ...isAsync != null && { async: isAsync },
2619
2649
  id
2620
2650
  });
2621
2651
  break;
@@ -2891,7 +2921,8 @@ var openaiResponsesChunkSchema = lazyValidator12(
2891
2921
  id: z15.string(),
2892
2922
  call_id: z15.string(),
2893
2923
  name: z15.string(),
2894
- arguments: z15.string()
2924
+ arguments: z15.string(),
2925
+ async: z15.boolean().nullish()
2895
2926
  }),
2896
2927
  z15.object({
2897
2928
  type: z15.literal("web_search_call"),
@@ -2946,6 +2977,7 @@ var openaiResponsesChunkSchema = lazyValidator12(
2946
2977
  call_id: z15.string(),
2947
2978
  name: z15.string(),
2948
2979
  arguments: z15.string(),
2980
+ async: z15.boolean().nullish(),
2949
2981
  status: z15.literal("completed")
2950
2982
  }),
2951
2983
  z15.object({
@@ -3257,7 +3289,8 @@ var openaiResponsesResponseSchema = lazyValidator12(
3257
3289
  call_id: z15.string(),
3258
3290
  name: z15.string(),
3259
3291
  arguments: z15.string(),
3260
- id: z15.string()
3292
+ id: z15.string(),
3293
+ async: z15.boolean().nullish()
3261
3294
  }),
3262
3295
  z15.object({
3263
3296
  type: z15.literal("computer_call"),
@@ -3455,6 +3488,15 @@ var openaiResponsesProviderOptionsSchema = lazyValidator13(
3455
3488
  * Supported values vary by model.
3456
3489
  */
3457
3490
  reasoningEffort: z16.string().nullish(),
3491
+ /**
3492
+ * Updates the reasoning effort for GPT-6 and later models starting with this response
3493
+ * without changing the request-level reasoning effort. This preserves the
3494
+ * request prefix for prompt caching.
3495
+ *
3496
+ * Only supported by GPT-6 and later models in standard, single-agent mode. Cannot be
3497
+ * combined with automatic truncation.
3498
+ */
3499
+ reasoningEffortUpdate: z16.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
3458
3500
  /**
3459
3501
  * Controls how much model work GPT-5.6 performs before returning a final answer.
3460
3502
  * `standard` is the default. `pro` increases quality, latency, and token usage.
@@ -3745,8 +3787,10 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
3745
3787
  async function prepareResponsesTools({
3746
3788
  tools,
3747
3789
  toolChoice,
3748
- strictJsonSchema
3790
+ strictJsonSchema,
3791
+ supportsAsyncToolCalling = true
3749
3792
  }) {
3793
+ var _a2;
3750
3794
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3751
3795
  const toolWarnings = [];
3752
3796
  if (tools == null) {
@@ -3755,15 +3799,24 @@ async function prepareResponsesTools({
3755
3799
  const openaiTools = [];
3756
3800
  for (const tool of tools) {
3757
3801
  switch (tool.type) {
3758
- case "function":
3802
+ case "function": {
3803
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3804
+ const async = resolveAsyncToolOption({
3805
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3806
+ supportsAsyncToolCalling,
3807
+ tool,
3808
+ toolWarnings
3809
+ });
3759
3810
  openaiTools.push({
3760
3811
  type: "function",
3761
3812
  name: tool.name,
3762
3813
  description: tool.description,
3763
3814
  parameters: tool.inputSchema,
3764
- strict: strictJsonSchema
3815
+ strict: strictJsonSchema,
3816
+ ...async != null ? { async } : {}
3765
3817
  });
3766
3818
  break;
3819
+ }
3767
3820
  case "provider-defined": {
3768
3821
  switch (tool.id) {
3769
3822
  case "openai.file_search": {
@@ -3882,6 +3935,22 @@ async function prepareResponsesTools({
3882
3935
  }
3883
3936
  }
3884
3937
  }
3938
+ function resolveAsyncToolOption({
3939
+ value,
3940
+ supportsAsyncToolCalling,
3941
+ tool,
3942
+ toolWarnings
3943
+ }) {
3944
+ if (value !== true || supportsAsyncToolCalling) {
3945
+ return value;
3946
+ }
3947
+ toolWarnings.push({
3948
+ type: "unsupported-tool",
3949
+ tool,
3950
+ details: "Async tool calling is only supported by GPT-6 and later models."
3951
+ });
3952
+ return void 0;
3953
+ }
3885
3954
 
3886
3955
  // src/responses/openai-responses-language-model.ts
3887
3956
  var OpenAIResponsesLanguageModel = class {
@@ -3912,7 +3981,7 @@ var OpenAIResponsesLanguageModel = class {
3912
3981
  toolChoice,
3913
3982
  responseFormat
3914
3983
  }) {
3915
- var _a2, _b, _c, _d;
3984
+ var _a2, _b, _c, _d, _e, _f;
3916
3985
  const warnings = [];
3917
3986
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
3918
3987
  if (topK != null) {
@@ -3951,11 +4020,37 @@ var OpenAIResponsesLanguageModel = class {
3951
4020
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3952
4021
  prompt,
3953
4022
  systemMessageMode: modelCapabilities.systemMessageMode,
4023
+ explicitMessageItemType: this.config.explicitMessageItemType,
3954
4024
  fileIdPrefixes: this.config.fileIdPrefixes,
3955
4025
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3956
4026
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
3957
4027
  });
3958
4028
  warnings.push(...inputWarnings);
4029
+ let resolvedReasoningEffort = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort;
4030
+ if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
4031
+ resolvedReasoningEffort
4032
+ )) {
4033
+ warnings.push({
4034
+ type: "unsupported-setting",
4035
+ setting: "reasoningEffort",
4036
+ details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
4037
+ });
4038
+ resolvedReasoningEffort = void 0;
4039
+ }
4040
+ const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
4041
+ const configurationUpdateIsSupported = reasoningEffortUpdate == null || modelCapabilities.supportsConfigurationUpdate && (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) !== "pro" && (openaiOptions == null ? void 0 : openaiOptions.truncation) !== "auto";
4042
+ if (reasoningEffortUpdate != null && !configurationUpdateIsSupported) {
4043
+ warnings.push({
4044
+ type: "unsupported-setting",
4045
+ setting: "reasoningEffortUpdate",
4046
+ details: !modelCapabilities.supportsConfigurationUpdate ? "reasoningEffortUpdate is only supported by GPT-6 and later models" : "reasoningEffortUpdate requires standard reasoning mode without automatic truncation"
4047
+ });
4048
+ } else if (reasoningEffortUpdate != null) {
4049
+ input.unshift({
4050
+ type: "configuration_update",
4051
+ reasoning: { effort: reasoningEffortUpdate }
4052
+ });
4053
+ }
3959
4054
  const strictJsonSchema = (_b = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _b : false;
3960
4055
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
3961
4056
  function addInclude(key) {
@@ -4027,10 +4122,10 @@ var OpenAIResponsesLanguageModel = class {
4027
4122
  top_logprobs: topLogprobs,
4028
4123
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
4029
4124
  // model-specific settings:
4030
- ...modelCapabilities.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) && {
4125
+ ...modelCapabilities.isReasoningModel && (resolvedReasoningEffort != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) && {
4031
4126
  reasoning: {
4032
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
4033
- effort: openaiOptions.reasoningEffort
4127
+ ...resolvedReasoningEffort != null && {
4128
+ effort: resolvedReasoningEffort
4034
4129
  },
4035
4130
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
4036
4131
  summary: openaiOptions.reasoningSummary
@@ -4044,6 +4139,14 @@ var OpenAIResponsesLanguageModel = class {
4044
4139
  }
4045
4140
  }
4046
4141
  };
4142
+ if (modelCapabilities.supportsConfigurationUpdate && baseArgs.prompt_cache_retention != null) {
4143
+ baseArgs.prompt_cache_retention = void 0;
4144
+ warnings.push({
4145
+ type: "unsupported-setting",
4146
+ setting: "promptCacheRetention",
4147
+ details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
4148
+ });
4149
+ }
4047
4150
  if (modelCapabilities.isReasoningModel) {
4048
4151
  if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
4049
4152
  if (baseArgs.temperature != null) {
@@ -4062,6 +4165,18 @@ var OpenAIResponsesLanguageModel = class {
4062
4165
  details: "topP is not supported for reasoning models"
4063
4166
  });
4064
4167
  }
4168
+ if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || ((_e = baseArgs.include) == null ? void 0 : _e.includes("message.output_text.logprobs")))) {
4169
+ baseArgs.top_logprobs = void 0;
4170
+ const filteredInclude = (_f = baseArgs.include) == null ? void 0 : _f.filter(
4171
+ (value) => value !== "message.output_text.logprobs"
4172
+ );
4173
+ baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
4174
+ warnings.push({
4175
+ type: "unsupported-setting",
4176
+ setting: "logprobs",
4177
+ details: "logprobs is not supported for reasoning models"
4178
+ });
4179
+ }
4065
4180
  }
4066
4181
  } else {
4067
4182
  if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
@@ -4116,7 +4231,8 @@ var OpenAIResponsesLanguageModel = class {
4116
4231
  } = await prepareResponsesTools({
4117
4232
  tools,
4118
4233
  toolChoice,
4119
- strictJsonSchema
4234
+ strictJsonSchema,
4235
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
4120
4236
  });
4121
4237
  return {
4122
4238
  webSearchToolName,
@@ -4310,7 +4426,8 @@ var OpenAIResponsesLanguageModel = class {
4310
4426
  input: part.arguments,
4311
4427
  providerMetadata: {
4312
4428
  [providerKey]: {
4313
- itemId: part.id
4429
+ itemId: part.id,
4430
+ ...part.async != null && { async: part.async }
4314
4431
  }
4315
4432
  }
4316
4433
  });
@@ -4510,7 +4627,8 @@ var OpenAIResponsesLanguageModel = class {
4510
4627
  if (value.item.type === "function_call") {
4511
4628
  ongoingToolCalls[value.output_index] = {
4512
4629
  toolName: value.item.name,
4513
- toolCallId: value.item.call_id
4630
+ toolCallId: value.item.call_id,
4631
+ async: value.item.async
4514
4632
  };
4515
4633
  controller.enqueue({
4516
4634
  type: "tool-input-start",
@@ -4634,6 +4752,7 @@ var OpenAIResponsesLanguageModel = class {
4634
4752
  }
4635
4753
  });
4636
4754
  } else if (value.item.type === "function_call") {
4755
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4637
4756
  ongoingToolCalls[value.output_index] = void 0;
4638
4757
  hasFunctionCall = true;
4639
4758
  controller.enqueue({
@@ -4647,7 +4766,8 @@ var OpenAIResponsesLanguageModel = class {
4647
4766
  input: value.item.arguments,
4648
4767
  providerMetadata: {
4649
4768
  [providerKey]: {
4650
- itemId: value.item.id
4769
+ itemId: value.item.id,
4770
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4651
4771
  }
4652
4772
  }
4653
4773
  });