@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.js CHANGED
@@ -59,14 +59,18 @@ function getOpenAILanguageModelCapabilities(modelId) {
59
59
  const gptVersion = getGptVersion(modelId);
60
60
  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);
61
61
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
62
+ const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
62
63
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
63
64
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
64
65
  const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel || modelId === "codex-mini-latest" || modelId === "computer-use-preview";
65
- const supportsNonReasoningParameters = gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
66
+ const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
66
67
  const systemMessageMode = isReasoningModel ? "developer" : "system";
67
68
  return {
68
69
  supportsFlexProcessing,
69
70
  supportsPriorityProcessing,
71
+ supportsConfigurationUpdate: isGpt6OrLaterModel,
72
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
73
+ supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
70
74
  isReasoningModel,
71
75
  systemMessageMode,
72
76
  supportsNonReasoningParameters
@@ -751,6 +755,17 @@ var OpenAIChatLanguageModel = class {
751
755
  );
752
756
  warnings.push(...messageWarnings);
753
757
  const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
758
+ let resolvedReasoningEffort = openaiOptions.reasoningEffort;
759
+ if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
760
+ resolvedReasoningEffort
761
+ )) {
762
+ warnings.push({
763
+ type: "unsupported-setting",
764
+ setting: "reasoningEffort",
765
+ details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
766
+ });
767
+ resolvedReasoningEffort = void 0;
768
+ }
754
769
  const baseArgs = {
755
770
  // model id:
756
771
  model: this.modelId,
@@ -784,7 +799,7 @@ var OpenAIChatLanguageModel = class {
784
799
  store: openaiOptions.store,
785
800
  metadata: openaiOptions.metadata,
786
801
  prediction: openaiOptions.prediction,
787
- reasoning_effort: openaiOptions.reasoningEffort,
802
+ reasoning_effort: resolvedReasoningEffort,
788
803
  service_tier: openaiOptions.serviceTier,
789
804
  prompt_cache_key: openaiOptions.promptCacheKey,
790
805
  prompt_cache_options: openaiOptions.promptCacheOptions,
@@ -793,6 +808,14 @@ var OpenAIChatLanguageModel = class {
793
808
  // messages:
794
809
  messages
795
810
  };
811
+ if (modelCapabilities.supportedReasoningEfforts != null && baseArgs.prompt_cache_retention != null) {
812
+ baseArgs.prompt_cache_retention = void 0;
813
+ warnings.push({
814
+ type: "unsupported-setting",
815
+ setting: "promptCacheRetention",
816
+ details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
817
+ });
818
+ }
796
819
  if (modelCapabilities.isReasoningModel) {
797
820
  if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
798
821
  if (baseArgs.temperature != null) {
@@ -2337,11 +2360,12 @@ function isFileId(data, prefixes) {
2337
2360
  async function convertToOpenAIResponsesInput({
2338
2361
  prompt,
2339
2362
  systemMessageMode,
2363
+ explicitMessageItemType = false,
2340
2364
  fileIdPrefixes,
2341
2365
  store,
2342
2366
  hasLocalShellTool = false
2343
2367
  }) {
2344
- var _a2, _b, _c, _d, _e, _f;
2368
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2345
2369
  let input = [];
2346
2370
  const warnings = [];
2347
2371
  for (const { role, content, providerOptions } of prompt) {
@@ -2351,6 +2375,7 @@ async function convertToOpenAIResponsesInput({
2351
2375
  case "system": {
2352
2376
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2353
2377
  input.push({
2378
+ ...explicitMessageItemType && { type: "message" },
2354
2379
  role: "system",
2355
2380
  content: promptCacheBreakpoint == null ? content : [
2356
2381
  {
@@ -2365,6 +2390,7 @@ async function convertToOpenAIResponsesInput({
2365
2390
  case "developer": {
2366
2391
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2367
2392
  input.push({
2393
+ ...explicitMessageItemType && { type: "message" },
2368
2394
  role: "developer",
2369
2395
  content: promptCacheBreakpoint == null ? content : [
2370
2396
  {
@@ -2394,6 +2420,7 @@ async function convertToOpenAIResponsesInput({
2394
2420
  }
2395
2421
  case "user": {
2396
2422
  input.push({
2423
+ ...explicitMessageItemType && { type: "message" },
2397
2424
  role: "user",
2398
2425
  content: content.map((part, index) => {
2399
2426
  var _a3, _b2, _c2;
@@ -2470,6 +2497,7 @@ async function convertToOpenAIResponsesInput({
2470
2497
  break;
2471
2498
  }
2472
2499
  input.push({
2500
+ ...explicitMessageItemType && { type: "message" },
2473
2501
  role: "assistant",
2474
2502
  content: [{ type: "output_text", text: part.text }],
2475
2503
  id,
@@ -2483,6 +2511,7 @@ async function convertToOpenAIResponsesInput({
2483
2511
  break;
2484
2512
  }
2485
2513
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2514
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2486
2515
  if (store && id != null) {
2487
2516
  input.push({ type: "item_reference", id });
2488
2517
  break;
@@ -2512,6 +2541,7 @@ async function convertToOpenAIResponsesInput({
2512
2541
  call_id: part.toolCallId,
2513
2542
  name: part.toolName,
2514
2543
  arguments: JSON.stringify(part.input),
2544
+ ...isAsync != null && { async: isAsync },
2515
2545
  id
2516
2546
  });
2517
2547
  break;
@@ -2784,7 +2814,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
2784
2814
  id: import_v417.z.string(),
2785
2815
  call_id: import_v417.z.string(),
2786
2816
  name: import_v417.z.string(),
2787
- arguments: import_v417.z.string()
2817
+ arguments: import_v417.z.string(),
2818
+ async: import_v417.z.boolean().nullish()
2788
2819
  }),
2789
2820
  import_v417.z.object({
2790
2821
  type: import_v417.z.literal("web_search_call"),
@@ -2839,6 +2870,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
2839
2870
  call_id: import_v417.z.string(),
2840
2871
  name: import_v417.z.string(),
2841
2872
  arguments: import_v417.z.string(),
2873
+ async: import_v417.z.boolean().nullish(),
2842
2874
  status: import_v417.z.literal("completed")
2843
2875
  }),
2844
2876
  import_v417.z.object({
@@ -3150,7 +3182,8 @@ var openaiResponsesResponseSchema = (0, import_provider_utils22.lazyValidator)(
3150
3182
  call_id: import_v417.z.string(),
3151
3183
  name: import_v417.z.string(),
3152
3184
  arguments: import_v417.z.string(),
3153
- id: import_v417.z.string()
3185
+ id: import_v417.z.string(),
3186
+ async: import_v417.z.boolean().nullish()
3154
3187
  }),
3155
3188
  import_v417.z.object({
3156
3189
  type: import_v417.z.literal("computer_call"),
@@ -3345,6 +3378,15 @@ var openaiResponsesProviderOptionsSchema = (0, import_provider_utils23.lazyValid
3345
3378
  * Supported values vary by model.
3346
3379
  */
3347
3380
  reasoningEffort: import_v418.z.string().nullish(),
3381
+ /**
3382
+ * Updates the reasoning effort for GPT-6 and later models starting with this response
3383
+ * without changing the request-level reasoning effort. This preserves the
3384
+ * request prefix for prompt caching.
3385
+ *
3386
+ * Only supported by GPT-6 and later models in standard, single-agent mode. Cannot be
3387
+ * combined with automatic truncation.
3388
+ */
3389
+ reasoningEffortUpdate: import_v418.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
3348
3390
  /**
3349
3391
  * Controls how much model work GPT-5.6 performs before returning a final answer.
3350
3392
  * `standard` is the default. `pro` increases quality, latency, and token usage.
@@ -3374,8 +3416,10 @@ var import_provider_utils24 = require("@ai-sdk/provider-utils");
3374
3416
  async function prepareResponsesTools({
3375
3417
  tools,
3376
3418
  toolChoice,
3377
- strictJsonSchema
3419
+ strictJsonSchema,
3420
+ supportsAsyncToolCalling = true
3378
3421
  }) {
3422
+ var _a2;
3379
3423
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3380
3424
  const toolWarnings = [];
3381
3425
  if (tools == null) {
@@ -3384,15 +3428,24 @@ async function prepareResponsesTools({
3384
3428
  const openaiTools2 = [];
3385
3429
  for (const tool of tools) {
3386
3430
  switch (tool.type) {
3387
- case "function":
3431
+ case "function": {
3432
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3433
+ const async = resolveAsyncToolOption({
3434
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3435
+ supportsAsyncToolCalling,
3436
+ tool,
3437
+ toolWarnings
3438
+ });
3388
3439
  openaiTools2.push({
3389
3440
  type: "function",
3390
3441
  name: tool.name,
3391
3442
  description: tool.description,
3392
3443
  parameters: tool.inputSchema,
3393
- strict: strictJsonSchema
3444
+ strict: strictJsonSchema,
3445
+ ...async != null ? { async } : {}
3394
3446
  });
3395
3447
  break;
3448
+ }
3396
3449
  case "provider-defined": {
3397
3450
  switch (tool.id) {
3398
3451
  case "openai.file_search": {
@@ -3511,6 +3564,22 @@ async function prepareResponsesTools({
3511
3564
  }
3512
3565
  }
3513
3566
  }
3567
+ function resolveAsyncToolOption({
3568
+ value,
3569
+ supportsAsyncToolCalling,
3570
+ tool,
3571
+ toolWarnings
3572
+ }) {
3573
+ if (value !== true || supportsAsyncToolCalling) {
3574
+ return value;
3575
+ }
3576
+ toolWarnings.push({
3577
+ type: "unsupported-tool",
3578
+ tool,
3579
+ details: "Async tool calling is only supported by GPT-6 and later models."
3580
+ });
3581
+ return void 0;
3582
+ }
3514
3583
 
3515
3584
  // src/responses/openai-responses-language-model.ts
3516
3585
  var OpenAIResponsesLanguageModel = class {
@@ -3541,7 +3610,7 @@ var OpenAIResponsesLanguageModel = class {
3541
3610
  toolChoice,
3542
3611
  responseFormat
3543
3612
  }) {
3544
- var _a2, _b, _c, _d;
3613
+ var _a2, _b, _c, _d, _e, _f;
3545
3614
  const warnings = [];
3546
3615
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
3547
3616
  if (topK != null) {
@@ -3580,11 +3649,37 @@ var OpenAIResponsesLanguageModel = class {
3580
3649
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3581
3650
  prompt,
3582
3651
  systemMessageMode: modelCapabilities.systemMessageMode,
3652
+ explicitMessageItemType: this.config.explicitMessageItemType,
3583
3653
  fileIdPrefixes: this.config.fileIdPrefixes,
3584
3654
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3585
3655
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
3586
3656
  });
3587
3657
  warnings.push(...inputWarnings);
3658
+ let resolvedReasoningEffort = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort;
3659
+ if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
3660
+ resolvedReasoningEffort
3661
+ )) {
3662
+ warnings.push({
3663
+ type: "unsupported-setting",
3664
+ setting: "reasoningEffort",
3665
+ details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
3666
+ });
3667
+ resolvedReasoningEffort = void 0;
3668
+ }
3669
+ const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
3670
+ const configurationUpdateIsSupported = reasoningEffortUpdate == null || modelCapabilities.supportsConfigurationUpdate && (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) !== "pro" && (openaiOptions == null ? void 0 : openaiOptions.truncation) !== "auto";
3671
+ if (reasoningEffortUpdate != null && !configurationUpdateIsSupported) {
3672
+ warnings.push({
3673
+ type: "unsupported-setting",
3674
+ setting: "reasoningEffortUpdate",
3675
+ details: !modelCapabilities.supportsConfigurationUpdate ? "reasoningEffortUpdate is only supported by GPT-6 and later models" : "reasoningEffortUpdate requires standard reasoning mode without automatic truncation"
3676
+ });
3677
+ } else if (reasoningEffortUpdate != null) {
3678
+ input.unshift({
3679
+ type: "configuration_update",
3680
+ reasoning: { effort: reasoningEffortUpdate }
3681
+ });
3682
+ }
3588
3683
  const strictJsonSchema = (_b = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _b : false;
3589
3684
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
3590
3685
  function addInclude(key) {
@@ -3656,10 +3751,10 @@ var OpenAIResponsesLanguageModel = class {
3656
3751
  top_logprobs: topLogprobs,
3657
3752
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
3658
3753
  // model-specific settings:
3659
- ...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) && {
3754
+ ...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) && {
3660
3755
  reasoning: {
3661
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
3662
- effort: openaiOptions.reasoningEffort
3756
+ ...resolvedReasoningEffort != null && {
3757
+ effort: resolvedReasoningEffort
3663
3758
  },
3664
3759
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
3665
3760
  summary: openaiOptions.reasoningSummary
@@ -3673,6 +3768,14 @@ var OpenAIResponsesLanguageModel = class {
3673
3768
  }
3674
3769
  }
3675
3770
  };
3771
+ if (modelCapabilities.supportsConfigurationUpdate && baseArgs.prompt_cache_retention != null) {
3772
+ baseArgs.prompt_cache_retention = void 0;
3773
+ warnings.push({
3774
+ type: "unsupported-setting",
3775
+ setting: "promptCacheRetention",
3776
+ details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
3777
+ });
3778
+ }
3676
3779
  if (modelCapabilities.isReasoningModel) {
3677
3780
  if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
3678
3781
  if (baseArgs.temperature != null) {
@@ -3691,6 +3794,18 @@ var OpenAIResponsesLanguageModel = class {
3691
3794
  details: "topP is not supported for reasoning models"
3692
3795
  });
3693
3796
  }
3797
+ if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || ((_e = baseArgs.include) == null ? void 0 : _e.includes("message.output_text.logprobs")))) {
3798
+ baseArgs.top_logprobs = void 0;
3799
+ const filteredInclude = (_f = baseArgs.include) == null ? void 0 : _f.filter(
3800
+ (value) => value !== "message.output_text.logprobs"
3801
+ );
3802
+ baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
3803
+ warnings.push({
3804
+ type: "unsupported-setting",
3805
+ setting: "logprobs",
3806
+ details: "logprobs is not supported for reasoning models"
3807
+ });
3808
+ }
3694
3809
  }
3695
3810
  } else {
3696
3811
  if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
@@ -3745,7 +3860,8 @@ var OpenAIResponsesLanguageModel = class {
3745
3860
  } = await prepareResponsesTools({
3746
3861
  tools,
3747
3862
  toolChoice,
3748
- strictJsonSchema
3863
+ strictJsonSchema,
3864
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
3749
3865
  });
3750
3866
  return {
3751
3867
  webSearchToolName,
@@ -3939,7 +4055,8 @@ var OpenAIResponsesLanguageModel = class {
3939
4055
  input: part.arguments,
3940
4056
  providerMetadata: {
3941
4057
  [providerKey]: {
3942
- itemId: part.id
4058
+ itemId: part.id,
4059
+ ...part.async != null && { async: part.async }
3943
4060
  }
3944
4061
  }
3945
4062
  });
@@ -4139,7 +4256,8 @@ var OpenAIResponsesLanguageModel = class {
4139
4256
  if (value.item.type === "function_call") {
4140
4257
  ongoingToolCalls[value.output_index] = {
4141
4258
  toolName: value.item.name,
4142
- toolCallId: value.item.call_id
4259
+ toolCallId: value.item.call_id,
4260
+ async: value.item.async
4143
4261
  };
4144
4262
  controller.enqueue({
4145
4263
  type: "tool-input-start",
@@ -4263,6 +4381,7 @@ var OpenAIResponsesLanguageModel = class {
4263
4381
  }
4264
4382
  });
4265
4383
  } else if (value.item.type === "function_call") {
4384
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4266
4385
  ongoingToolCalls[value.output_index] = void 0;
4267
4386
  hasFunctionCall = true;
4268
4387
  controller.enqueue({
@@ -4276,7 +4395,8 @@ var OpenAIResponsesLanguageModel = class {
4276
4395
  input: value.item.arguments,
4277
4396
  providerMetadata: {
4278
4397
  [providerKey]: {
4279
- itemId: value.item.id
4398
+ itemId: value.item.id,
4399
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4280
4400
  }
4281
4401
  }
4282
4402
  });
@@ -5011,7 +5131,7 @@ var OpenAITranscriptionModel = class {
5011
5131
  };
5012
5132
 
5013
5133
  // src/version.ts
5014
- var VERSION = true ? "2.0.124" : "0.0.0-test";
5134
+ var VERSION = true ? "2.0.126" : "0.0.0-test";
5015
5135
 
5016
5136
  // src/openai-provider.ts
5017
5137
  function createOpenAI(options = {}) {