@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.
package/dist/index.mjs CHANGED
@@ -46,14 +46,18 @@ function getOpenAILanguageModelCapabilities(modelId) {
46
46
  const gptVersion = getGptVersion(modelId);
47
47
  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);
48
48
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
49
+ const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
49
50
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
50
51
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
51
52
  const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel || modelId === "codex-mini-latest" || modelId === "computer-use-preview";
52
- const supportsNonReasoningParameters = gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
53
+ const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
53
54
  const systemMessageMode = isReasoningModel ? "developer" : "system";
54
55
  return {
55
56
  supportsFlexProcessing,
56
57
  supportsPriorityProcessing,
58
+ supportsConfigurationUpdate: isGpt6OrLaterModel,
59
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
60
+ supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
57
61
  isReasoningModel,
58
62
  systemMessageMode,
59
63
  supportsNonReasoningParameters
@@ -748,6 +752,17 @@ var OpenAIChatLanguageModel = class {
748
752
  );
749
753
  warnings.push(...messageWarnings);
750
754
  const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
755
+ let resolvedReasoningEffort = openaiOptions.reasoningEffort;
756
+ if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
757
+ resolvedReasoningEffort
758
+ )) {
759
+ warnings.push({
760
+ type: "unsupported-setting",
761
+ setting: "reasoningEffort",
762
+ details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
763
+ });
764
+ resolvedReasoningEffort = void 0;
765
+ }
751
766
  const baseArgs = {
752
767
  // model id:
753
768
  model: this.modelId,
@@ -781,7 +796,7 @@ var OpenAIChatLanguageModel = class {
781
796
  store: openaiOptions.store,
782
797
  metadata: openaiOptions.metadata,
783
798
  prediction: openaiOptions.prediction,
784
- reasoning_effort: openaiOptions.reasoningEffort,
799
+ reasoning_effort: resolvedReasoningEffort,
785
800
  service_tier: openaiOptions.serviceTier,
786
801
  prompt_cache_key: openaiOptions.promptCacheKey,
787
802
  prompt_cache_options: openaiOptions.promptCacheOptions,
@@ -790,6 +805,14 @@ var OpenAIChatLanguageModel = class {
790
805
  // messages:
791
806
  messages
792
807
  };
808
+ if (modelCapabilities.supportedReasoningEfforts != null && baseArgs.prompt_cache_retention != null) {
809
+ baseArgs.prompt_cache_retention = void 0;
810
+ warnings.push({
811
+ type: "unsupported-setting",
812
+ setting: "promptCacheRetention",
813
+ details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
814
+ });
815
+ }
793
816
  if (modelCapabilities.isReasoningModel) {
794
817
  if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
795
818
  if (baseArgs.temperature != null) {
@@ -2407,11 +2430,12 @@ function isFileId(data, prefixes) {
2407
2430
  async function convertToOpenAIResponsesInput({
2408
2431
  prompt,
2409
2432
  systemMessageMode,
2433
+ explicitMessageItemType = false,
2410
2434
  fileIdPrefixes,
2411
2435
  store,
2412
2436
  hasLocalShellTool = false
2413
2437
  }) {
2414
- var _a2, _b, _c, _d, _e, _f;
2438
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2415
2439
  let input = [];
2416
2440
  const warnings = [];
2417
2441
  for (const { role, content, providerOptions } of prompt) {
@@ -2421,6 +2445,7 @@ async function convertToOpenAIResponsesInput({
2421
2445
  case "system": {
2422
2446
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2423
2447
  input.push({
2448
+ ...explicitMessageItemType && { type: "message" },
2424
2449
  role: "system",
2425
2450
  content: promptCacheBreakpoint == null ? content : [
2426
2451
  {
@@ -2435,6 +2460,7 @@ async function convertToOpenAIResponsesInput({
2435
2460
  case "developer": {
2436
2461
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2437
2462
  input.push({
2463
+ ...explicitMessageItemType && { type: "message" },
2438
2464
  role: "developer",
2439
2465
  content: promptCacheBreakpoint == null ? content : [
2440
2466
  {
@@ -2464,6 +2490,7 @@ async function convertToOpenAIResponsesInput({
2464
2490
  }
2465
2491
  case "user": {
2466
2492
  input.push({
2493
+ ...explicitMessageItemType && { type: "message" },
2467
2494
  role: "user",
2468
2495
  content: content.map((part, index) => {
2469
2496
  var _a3, _b2, _c2;
@@ -2540,6 +2567,7 @@ async function convertToOpenAIResponsesInput({
2540
2567
  break;
2541
2568
  }
2542
2569
  input.push({
2570
+ ...explicitMessageItemType && { type: "message" },
2543
2571
  role: "assistant",
2544
2572
  content: [{ type: "output_text", text: part.text }],
2545
2573
  id,
@@ -2553,6 +2581,7 @@ async function convertToOpenAIResponsesInput({
2553
2581
  break;
2554
2582
  }
2555
2583
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2584
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2556
2585
  if (store && id != null) {
2557
2586
  input.push({ type: "item_reference", id });
2558
2587
  break;
@@ -2582,6 +2611,7 @@ async function convertToOpenAIResponsesInput({
2582
2611
  call_id: part.toolCallId,
2583
2612
  name: part.toolName,
2584
2613
  arguments: JSON.stringify(part.input),
2614
+ ...isAsync != null && { async: isAsync },
2585
2615
  id
2586
2616
  });
2587
2617
  break;
@@ -2857,7 +2887,8 @@ var openaiResponsesChunkSchema = lazyValidator9(
2857
2887
  id: z17.string(),
2858
2888
  call_id: z17.string(),
2859
2889
  name: z17.string(),
2860
- arguments: z17.string()
2890
+ arguments: z17.string(),
2891
+ async: z17.boolean().nullish()
2861
2892
  }),
2862
2893
  z17.object({
2863
2894
  type: z17.literal("web_search_call"),
@@ -2912,6 +2943,7 @@ var openaiResponsesChunkSchema = lazyValidator9(
2912
2943
  call_id: z17.string(),
2913
2944
  name: z17.string(),
2914
2945
  arguments: z17.string(),
2946
+ async: z17.boolean().nullish(),
2915
2947
  status: z17.literal("completed")
2916
2948
  }),
2917
2949
  z17.object({
@@ -3223,7 +3255,8 @@ var openaiResponsesResponseSchema = lazyValidator9(
3223
3255
  call_id: z17.string(),
3224
3256
  name: z17.string(),
3225
3257
  arguments: z17.string(),
3226
- id: z17.string()
3258
+ id: z17.string(),
3259
+ async: z17.boolean().nullish()
3227
3260
  }),
3228
3261
  z17.object({
3229
3262
  type: z17.literal("computer_call"),
@@ -3421,6 +3454,15 @@ var openaiResponsesProviderOptionsSchema = lazyValidator10(
3421
3454
  * Supported values vary by model.
3422
3455
  */
3423
3456
  reasoningEffort: z18.string().nullish(),
3457
+ /**
3458
+ * Updates the reasoning effort for GPT-6 and later models starting with this response
3459
+ * without changing the request-level reasoning effort. This preserves the
3460
+ * request prefix for prompt caching.
3461
+ *
3462
+ * Only supported by GPT-6 and later models in standard, single-agent mode. Cannot be
3463
+ * combined with automatic truncation.
3464
+ */
3465
+ reasoningEffortUpdate: z18.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
3424
3466
  /**
3425
3467
  * Controls how much model work GPT-5.6 performs before returning a final answer.
3426
3468
  * `standard` is the default. `pro` increases quality, latency, and token usage.
@@ -3452,8 +3494,10 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
3452
3494
  async function prepareResponsesTools({
3453
3495
  tools,
3454
3496
  toolChoice,
3455
- strictJsonSchema
3497
+ strictJsonSchema,
3498
+ supportsAsyncToolCalling = true
3456
3499
  }) {
3500
+ var _a2;
3457
3501
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3458
3502
  const toolWarnings = [];
3459
3503
  if (tools == null) {
@@ -3462,15 +3506,24 @@ async function prepareResponsesTools({
3462
3506
  const openaiTools2 = [];
3463
3507
  for (const tool of tools) {
3464
3508
  switch (tool.type) {
3465
- case "function":
3509
+ case "function": {
3510
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3511
+ const async = resolveAsyncToolOption({
3512
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3513
+ supportsAsyncToolCalling,
3514
+ tool,
3515
+ toolWarnings
3516
+ });
3466
3517
  openaiTools2.push({
3467
3518
  type: "function",
3468
3519
  name: tool.name,
3469
3520
  description: tool.description,
3470
3521
  parameters: tool.inputSchema,
3471
- strict: strictJsonSchema
3522
+ strict: strictJsonSchema,
3523
+ ...async != null ? { async } : {}
3472
3524
  });
3473
3525
  break;
3526
+ }
3474
3527
  case "provider-defined": {
3475
3528
  switch (tool.id) {
3476
3529
  case "openai.file_search": {
@@ -3589,6 +3642,22 @@ async function prepareResponsesTools({
3589
3642
  }
3590
3643
  }
3591
3644
  }
3645
+ function resolveAsyncToolOption({
3646
+ value,
3647
+ supportsAsyncToolCalling,
3648
+ tool,
3649
+ toolWarnings
3650
+ }) {
3651
+ if (value !== true || supportsAsyncToolCalling) {
3652
+ return value;
3653
+ }
3654
+ toolWarnings.push({
3655
+ type: "unsupported-tool",
3656
+ tool,
3657
+ details: "Async tool calling is only supported by GPT-6 and later models."
3658
+ });
3659
+ return void 0;
3660
+ }
3592
3661
 
3593
3662
  // src/responses/openai-responses-language-model.ts
3594
3663
  var OpenAIResponsesLanguageModel = class {
@@ -3619,7 +3688,7 @@ var OpenAIResponsesLanguageModel = class {
3619
3688
  toolChoice,
3620
3689
  responseFormat
3621
3690
  }) {
3622
- var _a2, _b, _c, _d;
3691
+ var _a2, _b, _c, _d, _e, _f;
3623
3692
  const warnings = [];
3624
3693
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
3625
3694
  if (topK != null) {
@@ -3658,11 +3727,37 @@ var OpenAIResponsesLanguageModel = class {
3658
3727
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3659
3728
  prompt,
3660
3729
  systemMessageMode: modelCapabilities.systemMessageMode,
3730
+ explicitMessageItemType: this.config.explicitMessageItemType,
3661
3731
  fileIdPrefixes: this.config.fileIdPrefixes,
3662
3732
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3663
3733
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
3664
3734
  });
3665
3735
  warnings.push(...inputWarnings);
3736
+ let resolvedReasoningEffort = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort;
3737
+ if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
3738
+ resolvedReasoningEffort
3739
+ )) {
3740
+ warnings.push({
3741
+ type: "unsupported-setting",
3742
+ setting: "reasoningEffort",
3743
+ details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
3744
+ });
3745
+ resolvedReasoningEffort = void 0;
3746
+ }
3747
+ const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
3748
+ const configurationUpdateIsSupported = reasoningEffortUpdate == null || modelCapabilities.supportsConfigurationUpdate && (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) !== "pro" && (openaiOptions == null ? void 0 : openaiOptions.truncation) !== "auto";
3749
+ if (reasoningEffortUpdate != null && !configurationUpdateIsSupported) {
3750
+ warnings.push({
3751
+ type: "unsupported-setting",
3752
+ setting: "reasoningEffortUpdate",
3753
+ details: !modelCapabilities.supportsConfigurationUpdate ? "reasoningEffortUpdate is only supported by GPT-6 and later models" : "reasoningEffortUpdate requires standard reasoning mode without automatic truncation"
3754
+ });
3755
+ } else if (reasoningEffortUpdate != null) {
3756
+ input.unshift({
3757
+ type: "configuration_update",
3758
+ reasoning: { effort: reasoningEffortUpdate }
3759
+ });
3760
+ }
3666
3761
  const strictJsonSchema = (_b = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _b : false;
3667
3762
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
3668
3763
  function addInclude(key) {
@@ -3734,10 +3829,10 @@ var OpenAIResponsesLanguageModel = class {
3734
3829
  top_logprobs: topLogprobs,
3735
3830
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
3736
3831
  // model-specific settings:
3737
- ...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) && {
3832
+ ...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) && {
3738
3833
  reasoning: {
3739
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
3740
- effort: openaiOptions.reasoningEffort
3834
+ ...resolvedReasoningEffort != null && {
3835
+ effort: resolvedReasoningEffort
3741
3836
  },
3742
3837
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
3743
3838
  summary: openaiOptions.reasoningSummary
@@ -3751,6 +3846,14 @@ var OpenAIResponsesLanguageModel = class {
3751
3846
  }
3752
3847
  }
3753
3848
  };
3849
+ if (modelCapabilities.supportsConfigurationUpdate && baseArgs.prompt_cache_retention != null) {
3850
+ baseArgs.prompt_cache_retention = void 0;
3851
+ warnings.push({
3852
+ type: "unsupported-setting",
3853
+ setting: "promptCacheRetention",
3854
+ details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
3855
+ });
3856
+ }
3754
3857
  if (modelCapabilities.isReasoningModel) {
3755
3858
  if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
3756
3859
  if (baseArgs.temperature != null) {
@@ -3769,6 +3872,18 @@ var OpenAIResponsesLanguageModel = class {
3769
3872
  details: "topP is not supported for reasoning models"
3770
3873
  });
3771
3874
  }
3875
+ if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || ((_e = baseArgs.include) == null ? void 0 : _e.includes("message.output_text.logprobs")))) {
3876
+ baseArgs.top_logprobs = void 0;
3877
+ const filteredInclude = (_f = baseArgs.include) == null ? void 0 : _f.filter(
3878
+ (value) => value !== "message.output_text.logprobs"
3879
+ );
3880
+ baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
3881
+ warnings.push({
3882
+ type: "unsupported-setting",
3883
+ setting: "logprobs",
3884
+ details: "logprobs is not supported for reasoning models"
3885
+ });
3886
+ }
3772
3887
  }
3773
3888
  } else {
3774
3889
  if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
@@ -3823,7 +3938,8 @@ var OpenAIResponsesLanguageModel = class {
3823
3938
  } = await prepareResponsesTools({
3824
3939
  tools,
3825
3940
  toolChoice,
3826
- strictJsonSchema
3941
+ strictJsonSchema,
3942
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
3827
3943
  });
3828
3944
  return {
3829
3945
  webSearchToolName,
@@ -4017,7 +4133,8 @@ var OpenAIResponsesLanguageModel = class {
4017
4133
  input: part.arguments,
4018
4134
  providerMetadata: {
4019
4135
  [providerKey]: {
4020
- itemId: part.id
4136
+ itemId: part.id,
4137
+ ...part.async != null && { async: part.async }
4021
4138
  }
4022
4139
  }
4023
4140
  });
@@ -4217,7 +4334,8 @@ var OpenAIResponsesLanguageModel = class {
4217
4334
  if (value.item.type === "function_call") {
4218
4335
  ongoingToolCalls[value.output_index] = {
4219
4336
  toolName: value.item.name,
4220
- toolCallId: value.item.call_id
4337
+ toolCallId: value.item.call_id,
4338
+ async: value.item.async
4221
4339
  };
4222
4340
  controller.enqueue({
4223
4341
  type: "tool-input-start",
@@ -4341,6 +4459,7 @@ var OpenAIResponsesLanguageModel = class {
4341
4459
  }
4342
4460
  });
4343
4461
  } else if (value.item.type === "function_call") {
4462
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4344
4463
  ongoingToolCalls[value.output_index] = void 0;
4345
4464
  hasFunctionCall = true;
4346
4465
  controller.enqueue({
@@ -4354,7 +4473,8 @@ var OpenAIResponsesLanguageModel = class {
4354
4473
  input: value.item.arguments,
4355
4474
  providerMetadata: {
4356
4475
  [providerKey]: {
4357
- itemId: value.item.id
4476
+ itemId: value.item.id,
4477
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4358
4478
  }
4359
4479
  }
4360
4480
  });
@@ -5107,7 +5227,7 @@ var OpenAITranscriptionModel = class {
5107
5227
  };
5108
5228
 
5109
5229
  // src/version.ts
5110
- var VERSION = true ? "2.0.124" : "0.0.0-test";
5230
+ var VERSION = true ? "2.0.126" : "0.0.0-test";
5111
5231
 
5112
5232
  // src/openai-provider.ts
5113
5233
  function createOpenAI(options = {}) {