@ai-sdk/openai 3.0.83 → 3.0.85

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
@@ -193,7 +193,7 @@ function isHttpErrorStatusCode(value) {
193
193
 
194
194
  // src/chat/convert-openai-chat-usage.ts
195
195
  function convertOpenAIChatUsage(usage) {
196
- var _a, _b, _c, _d, _e, _f;
196
+ var _a, _b, _c, _d, _e, _f, _g, _h;
197
197
  if (usage == null) {
198
198
  return {
199
199
  inputTokens: {
@@ -213,13 +213,14 @@ function convertOpenAIChatUsage(usage) {
213
213
  const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
214
214
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
215
215
  const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
216
- const reasoningTokens = (_f = (_e = usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
216
+ const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
217
+ const reasoningTokens = (_h = (_g = usage.completion_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : 0;
217
218
  return {
218
219
  inputTokens: {
219
220
  total: promptTokens,
220
- noCache: promptTokens - cachedTokens,
221
+ noCache: promptTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
221
222
  cacheRead: cachedTokens,
222
- cacheWrite: void 0
223
+ cacheWrite: cacheWriteTokens
223
224
  },
224
225
  outputTokens: {
225
226
  total: completionTokens,
@@ -236,23 +237,47 @@ var import_provider_utils2 = require("@ai-sdk/provider-utils");
236
237
  function serializeToolCallArguments(input) {
237
238
  return JSON.stringify(input === void 0 ? {} : input);
238
239
  }
240
+ function getPromptCacheBreakpoint(providerOptions) {
241
+ var _a;
242
+ return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
243
+ }
239
244
  function convertToOpenAIChatMessages({
240
245
  prompt,
241
246
  systemMessageMode = "system"
242
247
  }) {
243
- var _a;
248
+ var _a, _b;
244
249
  const messages = [];
245
250
  const warnings = [];
246
- for (const { role, content } of prompt) {
251
+ for (const { role, content, providerOptions } of prompt) {
247
252
  switch (role) {
248
253
  case "system": {
249
254
  switch (systemMessageMode) {
250
255
  case "system": {
251
- messages.push({ role: "system", content });
256
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
257
+ messages.push({
258
+ role: "system",
259
+ content: promptCacheBreakpoint == null ? content : [
260
+ {
261
+ type: "text",
262
+ text: content,
263
+ prompt_cache_breakpoint: promptCacheBreakpoint
264
+ }
265
+ ]
266
+ });
252
267
  break;
253
268
  }
254
269
  case "developer": {
255
- messages.push({ role: "developer", content });
270
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
271
+ messages.push({
272
+ role: "developer",
273
+ content: promptCacheBreakpoint == null ? content : [
274
+ {
275
+ type: "text",
276
+ text: content,
277
+ prompt_cache_breakpoint: promptCacheBreakpoint
278
+ }
279
+ ]
280
+ });
256
281
  break;
257
282
  }
258
283
  case "remove": {
@@ -272,19 +297,31 @@ function convertToOpenAIChatMessages({
272
297
  break;
273
298
  }
274
299
  case "user": {
275
- if (content.length === 1 && content[0].type === "text") {
300
+ if (content.length === 1 && content[0].type === "text" && getPromptCacheBreakpoint(content[0].providerOptions) == null) {
276
301
  messages.push({ role: "user", content: content[0].text });
277
302
  break;
278
303
  }
279
304
  messages.push({
280
305
  role: "user",
281
306
  content: content.map((part, index) => {
282
- var _a2, _b, _c;
307
+ var _a2, _b2, _c;
283
308
  switch (part.type) {
284
309
  case "text": {
285
- return { type: "text", text: part.text };
310
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(
311
+ part.providerOptions
312
+ );
313
+ return {
314
+ type: "text",
315
+ text: part.text,
316
+ ...promptCacheBreakpoint != null && {
317
+ prompt_cache_breakpoint: promptCacheBreakpoint
318
+ }
319
+ };
286
320
  }
287
321
  case "file": {
322
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(
323
+ part.providerOptions
324
+ );
288
325
  if (part.mediaType.startsWith("image/")) {
289
326
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
290
327
  return {
@@ -292,7 +329,10 @@ function convertToOpenAIChatMessages({
292
329
  image_url: {
293
330
  url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`,
294
331
  // OpenAI specific extension: image detail
295
- detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
332
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
333
+ },
334
+ ...promptCacheBreakpoint != null && {
335
+ prompt_cache_breakpoint: promptCacheBreakpoint
296
336
  }
297
337
  };
298
338
  } else if (part.mediaType.startsWith("audio/")) {
@@ -308,6 +348,9 @@ function convertToOpenAIChatMessages({
308
348
  input_audio: {
309
349
  data: (0, import_provider_utils2.convertToBase64)(part.data),
310
350
  format: "wav"
351
+ },
352
+ ...promptCacheBreakpoint != null && {
353
+ prompt_cache_breakpoint: promptCacheBreakpoint
311
354
  }
312
355
  };
313
356
  }
@@ -318,6 +361,9 @@ function convertToOpenAIChatMessages({
318
361
  input_audio: {
319
362
  data: (0, import_provider_utils2.convertToBase64)(part.data),
320
363
  format: "mp3"
364
+ },
365
+ ...promptCacheBreakpoint != null && {
366
+ prompt_cache_breakpoint: promptCacheBreakpoint
321
367
  }
322
368
  };
323
369
  }
@@ -338,6 +384,9 @@ function convertToOpenAIChatMessages({
338
384
  file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
339
385
  filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
340
386
  file_data: `data:application/pdf;base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`
387
+ },
388
+ ...promptCacheBreakpoint != null && {
389
+ prompt_cache_breakpoint: promptCacheBreakpoint
341
390
  }
342
391
  };
343
392
  } else {
@@ -353,11 +402,24 @@ function convertToOpenAIChatMessages({
353
402
  }
354
403
  case "assistant": {
355
404
  let text = "";
405
+ const textParts = [];
406
+ let hasPromptCacheBreakpoint = false;
356
407
  const toolCalls = [];
357
408
  for (const part of content) {
358
409
  switch (part.type) {
359
410
  case "text": {
411
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(
412
+ part.providerOptions
413
+ );
360
414
  text += part.text;
415
+ textParts.push({
416
+ type: "text",
417
+ text: part.text,
418
+ ...promptCacheBreakpoint != null && {
419
+ prompt_cache_breakpoint: promptCacheBreakpoint
420
+ }
421
+ });
422
+ hasPromptCacheBreakpoint || (hasPromptCacheBreakpoint = promptCacheBreakpoint != null);
361
423
  break;
362
424
  }
363
425
  case "tool-call": {
@@ -375,7 +437,7 @@ function convertToOpenAIChatMessages({
375
437
  }
376
438
  messages.push({
377
439
  role: "assistant",
378
- content: toolCalls.length > 0 ? text || null : text,
440
+ content: hasPromptCacheBreakpoint ? textParts : toolCalls.length > 0 ? text || null : text,
379
441
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
380
442
  });
381
443
  break;
@@ -386,6 +448,7 @@ function convertToOpenAIChatMessages({
386
448
  continue;
387
449
  }
388
450
  const output = toolResponse.output;
451
+ const promptCacheBreakpoint = (_a = output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) != null ? _a : getPromptCacheBreakpoint(toolResponse.providerOptions);
389
452
  let contentValue;
390
453
  switch (output.type) {
391
454
  case "text":
@@ -393,7 +456,7 @@ function convertToOpenAIChatMessages({
393
456
  contentValue = output.value;
394
457
  break;
395
458
  case "execution-denied":
396
- contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
459
+ contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
397
460
  break;
398
461
  case "content":
399
462
  case "json":
@@ -404,7 +467,13 @@ function convertToOpenAIChatMessages({
404
467
  messages.push({
405
468
  role: "tool",
406
469
  tool_call_id: toolResponse.toolCallId,
407
- content: contentValue
470
+ content: promptCacheBreakpoint == null ? contentValue : [
471
+ {
472
+ type: "text",
473
+ text: contentValue,
474
+ prompt_cache_breakpoint: promptCacheBreakpoint
475
+ }
476
+ ]
408
477
  });
409
478
  }
410
479
  break;
@@ -507,7 +576,8 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazySchema)(
507
576
  completion_tokens: import_v42.z.number().nullish(),
508
577
  total_tokens: import_v42.z.number().nullish(),
509
578
  prompt_tokens_details: import_v42.z.object({
510
- cached_tokens: import_v42.z.number().nullish()
579
+ cached_tokens: import_v42.z.number().nullish(),
580
+ cache_write_tokens: import_v42.z.number().nullish()
511
581
  }).nullish(),
512
582
  completion_tokens_details: import_v42.z.object({
513
583
  reasoning_tokens: import_v42.z.number().nullish(),
@@ -576,7 +646,8 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazySchema)(
576
646
  completion_tokens: import_v42.z.number().nullish(),
577
647
  total_tokens: import_v42.z.number().nullish(),
578
648
  prompt_tokens_details: import_v42.z.object({
579
- cached_tokens: import_v42.z.number().nullish()
649
+ cached_tokens: import_v42.z.number().nullish(),
650
+ cache_write_tokens: import_v42.z.number().nullish()
580
651
  }).nullish(),
581
652
  completion_tokens_details: import_v42.z.object({
582
653
  reasoning_tokens: import_v42.z.number().nullish(),
@@ -625,7 +696,7 @@ var openaiLanguageModelChatOptions = (0, import_provider_utils4.lazySchema)(
625
696
  /**
626
697
  * Reasoning effort for reasoning models. Defaults to `medium`.
627
698
  */
628
- reasoningEffort: import_v43.z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(),
699
+ reasoningEffort: import_v43.z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional(),
629
700
  /**
630
701
  * Maximum number of completion tokens to generate. Useful for reasoning models.
631
702
  */
@@ -669,11 +740,22 @@ var openaiLanguageModelChatOptions = (0, import_provider_utils4.lazySchema)(
669
740
  * Useful for improving cache hit rates and working around automatic caching issues.
670
741
  */
671
742
  promptCacheKey: import_v43.z.string().optional(),
743
+ /**
744
+ * Prompt cache behavior for GPT-5.6 and later models.
745
+ * `mode` controls whether OpenAI also places an implicit breakpoint.
746
+ * `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
747
+ */
748
+ promptCacheOptions: import_v43.z.object({
749
+ mode: import_v43.z.enum(["implicit", "explicit"]).optional(),
750
+ ttl: import_v43.z.literal("30m").optional()
751
+ }).optional(),
672
752
  /**
673
753
  * The retention policy for the prompt cache.
674
754
  * - 'in_memory': Default. Standard prompt caching behavior.
675
755
  * - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
676
- * Currently only available for 5.1 series models.
756
+ * Available for models before GPT-5.6 that support extended caching.
757
+ *
758
+ * @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
677
759
  *
678
760
  * @default 'in_memory'
679
761
  */
@@ -855,6 +937,7 @@ var OpenAIChatLanguageModel = class {
855
937
  reasoning_effort: openaiOptions.reasoningEffort,
856
938
  service_tier: openaiOptions.serviceTier,
857
939
  prompt_cache_key: openaiOptions.promptCacheKey,
940
+ prompt_cache_options: openaiOptions.promptCacheOptions,
858
941
  prompt_cache_retention: openaiOptions.promptCacheRetention,
859
942
  safety_identifier: openaiOptions.safetyIdentifier,
860
943
  // messages:
@@ -2833,7 +2916,7 @@ var import_provider_utils30 = require("@ai-sdk/provider-utils");
2833
2916
 
2834
2917
  // src/responses/convert-openai-responses-usage.ts
2835
2918
  function convertOpenAIResponsesUsage(usage) {
2836
- var _a, _b, _c, _d;
2919
+ var _a, _b, _c, _d, _e, _f;
2837
2920
  if (usage == null) {
2838
2921
  return {
2839
2922
  inputTokens: {
@@ -2853,13 +2936,14 @@ function convertOpenAIResponsesUsage(usage) {
2853
2936
  const inputTokens = usage.input_tokens;
2854
2937
  const outputTokens = usage.output_tokens;
2855
2938
  const cachedTokens = (_b = (_a = usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
2856
- const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
2939
+ const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
2940
+ const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
2857
2941
  return {
2858
2942
  inputTokens: {
2859
2943
  total: inputTokens,
2860
- noCache: inputTokens - cachedTokens,
2944
+ noCache: inputTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
2861
2945
  cacheRead: cachedTokens,
2862
- cacheWrite: void 0
2946
+ cacheWrite: cacheWriteTokens
2863
2947
  },
2864
2948
  outputTokens: {
2865
2949
  total: outputTokens,
@@ -2877,6 +2961,10 @@ var import_v421 = require("zod/v4");
2877
2961
  function serializeToolCallArguments2(input) {
2878
2962
  return JSON.stringify(input === void 0 ? {} : input);
2879
2963
  }
2964
+ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
2965
+ var _a;
2966
+ return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
2967
+ }
2880
2968
  function isFileId(data, prefixes) {
2881
2969
  if (!prefixes) return false;
2882
2970
  return prefixes.some((prefix) => data.startsWith(prefix));
@@ -2900,16 +2988,42 @@ async function convertToOpenAIResponsesInput({
2900
2988
  let input = [];
2901
2989
  const warnings = [];
2902
2990
  const processedApprovalIds = /* @__PURE__ */ new Set();
2903
- for (const { role, content } of prompt) {
2991
+ for (const { role, content, providerOptions } of prompt) {
2904
2992
  switch (role) {
2905
2993
  case "system": {
2906
2994
  switch (systemMessageMode) {
2907
2995
  case "system": {
2908
- input.push({ role: "system", content });
2996
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
2997
+ providerOptions,
2998
+ providerOptionsName
2999
+ );
3000
+ input.push({
3001
+ role: "system",
3002
+ content: promptCacheBreakpoint == null ? content : [
3003
+ {
3004
+ type: "input_text",
3005
+ text: content,
3006
+ prompt_cache_breakpoint: promptCacheBreakpoint
3007
+ }
3008
+ ]
3009
+ });
2909
3010
  break;
2910
3011
  }
2911
3012
  case "developer": {
2912
- input.push({ role: "developer", content });
3013
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3014
+ providerOptions,
3015
+ providerOptionsName
3016
+ );
3017
+ input.push({
3018
+ role: "developer",
3019
+ content: promptCacheBreakpoint == null ? content : [
3020
+ {
3021
+ type: "input_text",
3022
+ text: content,
3023
+ prompt_cache_breakpoint: promptCacheBreakpoint
3024
+ }
3025
+ ]
3026
+ });
2913
3027
  break;
2914
3028
  }
2915
3029
  case "remove": {
@@ -2935,9 +3049,23 @@ async function convertToOpenAIResponsesInput({
2935
3049
  var _a2, _b2, _c2;
2936
3050
  switch (part.type) {
2937
3051
  case "text": {
2938
- return { type: "input_text", text: part.text };
3052
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3053
+ part.providerOptions,
3054
+ providerOptionsName
3055
+ );
3056
+ return {
3057
+ type: "input_text",
3058
+ text: part.text,
3059
+ ...promptCacheBreakpoint != null && {
3060
+ prompt_cache_breakpoint: promptCacheBreakpoint
3061
+ }
3062
+ };
2939
3063
  }
2940
3064
  case "file": {
3065
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3066
+ part.providerOptions,
3067
+ providerOptionsName
3068
+ );
2941
3069
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
2942
3070
  if (mediaType.startsWith("image/")) {
2943
3071
  return {
@@ -2945,13 +3073,19 @@ async function convertToOpenAIResponsesInput({
2945
3073
  ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2946
3074
  image_url: `data:${mediaType};base64,${(0, import_provider_utils26.convertToBase64)(part.data)}`
2947
3075
  },
2948
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3076
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3077
+ ...promptCacheBreakpoint != null && {
3078
+ prompt_cache_breakpoint: promptCacheBreakpoint
3079
+ }
2949
3080
  };
2950
3081
  }
2951
3082
  if (part.data instanceof URL) {
2952
3083
  return {
2953
3084
  type: "input_file",
2954
- file_url: part.data.toString()
3085
+ file_url: part.data.toString(),
3086
+ ...promptCacheBreakpoint != null && {
3087
+ prompt_cache_breakpoint: promptCacheBreakpoint
3088
+ }
2955
3089
  };
2956
3090
  }
2957
3091
  if (mediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
@@ -2964,6 +3098,9 @@ async function convertToOpenAIResponsesInput({
2964
3098
  ...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2965
3099
  filename: (_c2 = part.filename) != null ? _c2 : mediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
2966
3100
  file_data: `data:${mediaType};base64,${(0, import_provider_utils26.convertToBase64)(part.data)}`
3101
+ },
3102
+ ...promptCacheBreakpoint != null && {
3103
+ prompt_cache_breakpoint: promptCacheBreakpoint
2967
3104
  }
2968
3105
  };
2969
3106
  }
@@ -3176,12 +3313,12 @@ async function convertToOpenAIResponsesInput({
3176
3313
  break;
3177
3314
  }
3178
3315
  case "reasoning": {
3179
- const providerOptions = await (0, import_provider_utils26.parseProviderOptions)({
3316
+ const providerOptions2 = await (0, import_provider_utils26.parseProviderOptions)({
3180
3317
  provider: providerOptionsName,
3181
3318
  providerOptions: part.providerOptions,
3182
3319
  schema: openaiResponsesReasoningProviderOptionsSchema
3183
3320
  });
3184
- const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
3321
+ const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
3185
3322
  if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
3186
3323
  break;
3187
3324
  }
@@ -3213,19 +3350,19 @@ async function convertToOpenAIResponsesInput({
3213
3350
  reasoningMessages[reasoningId] = {
3214
3351
  type: "reasoning",
3215
3352
  id: reasoningId,
3216
- encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
3353
+ encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
3217
3354
  summary: summaryParts
3218
3355
  };
3219
3356
  input.push(reasoningMessages[reasoningId]);
3220
3357
  } else {
3221
3358
  reasoningMessage.summary.push(...summaryParts);
3222
- if ((providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent) != null) {
3223
- reasoningMessage.encrypted_content = providerOptions.reasoningEncryptedContent;
3359
+ if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
3360
+ reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
3224
3361
  }
3225
3362
  }
3226
3363
  }
3227
3364
  } else {
3228
- const encryptedContent = providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent;
3365
+ const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent;
3229
3366
  if (encryptedContent != null) {
3230
3367
  const summaryParts = [];
3231
3368
  if (part.text.length > 0) {
@@ -3358,31 +3495,53 @@ async function convertToOpenAIResponsesInput({
3358
3495
  case "content":
3359
3496
  outputValue = output.value.map((item) => {
3360
3497
  var _a2, _b2, _c2, _d2, _e2;
3498
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3499
+ item.providerOptions,
3500
+ providerOptionsName
3501
+ );
3361
3502
  switch (item.type) {
3362
3503
  case "text":
3363
- return { type: "input_text", text: item.text };
3504
+ return {
3505
+ type: "input_text",
3506
+ text: item.text,
3507
+ ...promptCacheBreakpoint != null && {
3508
+ prompt_cache_breakpoint: promptCacheBreakpoint
3509
+ }
3510
+ };
3364
3511
  case "image-data":
3365
3512
  return {
3366
3513
  type: "input_image",
3367
3514
  image_url: `data:${item.mediaType};base64,${item.data}`,
3368
- detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3515
+ detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3516
+ ...promptCacheBreakpoint != null && {
3517
+ prompt_cache_breakpoint: promptCacheBreakpoint
3518
+ }
3369
3519
  };
3370
3520
  case "image-url":
3371
3521
  return {
3372
3522
  type: "input_image",
3373
3523
  image_url: item.url,
3374
- detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
3524
+ detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3525
+ ...promptCacheBreakpoint != null && {
3526
+ prompt_cache_breakpoint: promptCacheBreakpoint
3527
+ }
3375
3528
  };
3376
3529
  case "file-data":
3377
3530
  return {
3378
3531
  type: "input_file",
3379
3532
  filename: (_e2 = item.filename) != null ? _e2 : "data",
3380
- file_data: `data:${item.mediaType};base64,${item.data}`
3533
+ file_data: `data:${item.mediaType};base64,${item.data}`,
3534
+ ...promptCacheBreakpoint != null && {
3535
+ prompt_cache_breakpoint: promptCacheBreakpoint
3536
+ }
3381
3537
  };
3382
3538
  case "file-url":
3383
3539
  return {
3384
3540
  type: "input_file",
3385
- file_url: item.url
3541
+ file_url: item.url,
3542
+ ...promptCacheBreakpoint != null && {
3543
+ prompt_cache_breakpoint: promptCacheBreakpoint
3544
+ }
3386
3545
  };
3387
3546
  default:
3388
3547
  warnings.push({
@@ -3419,35 +3578,57 @@ async function convertToOpenAIResponsesInput({
3419
3578
  case "content":
3420
3579
  contentValue = output.value.map((item) => {
3421
3580
  var _a2, _b2, _c2, _d2, _e2;
3581
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3582
+ item.providerOptions,
3583
+ providerOptionsName
3584
+ );
3422
3585
  switch (item.type) {
3423
3586
  case "text": {
3424
- return { type: "input_text", text: item.text };
3587
+ return {
3588
+ type: "input_text",
3589
+ text: item.text,
3590
+ ...promptCacheBreakpoint != null && {
3591
+ prompt_cache_breakpoint: promptCacheBreakpoint
3592
+ }
3593
+ };
3425
3594
  }
3426
3595
  case "image-data": {
3427
3596
  return {
3428
3597
  type: "input_image",
3429
3598
  image_url: `data:${item.mediaType};base64,${item.data}`,
3430
- detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3599
+ detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3600
+ ...promptCacheBreakpoint != null && {
3601
+ prompt_cache_breakpoint: promptCacheBreakpoint
3602
+ }
3431
3603
  };
3432
3604
  }
3433
3605
  case "image-url": {
3434
3606
  return {
3435
3607
  type: "input_image",
3436
3608
  image_url: item.url,
3437
- detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
3609
+ detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3610
+ ...promptCacheBreakpoint != null && {
3611
+ prompt_cache_breakpoint: promptCacheBreakpoint
3612
+ }
3438
3613
  };
3439
3614
  }
3440
3615
  case "file-data": {
3441
3616
  return {
3442
3617
  type: "input_file",
3443
3618
  filename: (_e2 = item.filename) != null ? _e2 : "data",
3444
- file_data: `data:${item.mediaType};base64,${item.data}`
3619
+ file_data: `data:${item.mediaType};base64,${item.data}`,
3620
+ ...promptCacheBreakpoint != null && {
3621
+ prompt_cache_breakpoint: promptCacheBreakpoint
3622
+ }
3445
3623
  };
3446
3624
  }
3447
3625
  case "file-url": {
3448
3626
  return {
3449
3627
  type: "input_file",
3450
- file_url: item.url
3628
+ file_url: item.url,
3629
+ ...promptCacheBreakpoint != null && {
3630
+ prompt_cache_breakpoint: promptCacheBreakpoint
3631
+ }
3451
3632
  };
3452
3633
  }
3453
3634
  default: {
@@ -3569,6 +3750,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils27.lazySchema)(
3569
3750
  input_tokens: import_v422.z.number(),
3570
3751
  input_tokens_details: import_v422.z.object({
3571
3752
  cached_tokens: import_v422.z.number().nullish(),
3753
+ cache_write_tokens: import_v422.z.number().nullish(),
3572
3754
  orchestration_input_tokens: import_v422.z.number().nullish(),
3573
3755
  orchestration_input_cached_tokens: import_v422.z.number().nullish()
3574
3756
  }).nullish(),
@@ -3578,6 +3760,9 @@ var openaiResponsesChunkSchema = (0, import_provider_utils27.lazySchema)(
3578
3760
  orchestration_output_tokens: import_v422.z.number().nullish()
3579
3761
  }).nullish()
3580
3762
  }),
3763
+ reasoning: import_v422.z.object({
3764
+ context: import_v422.z.string().nullish()
3765
+ }).nullish(),
3581
3766
  service_tier: import_v422.z.string().nullish()
3582
3767
  })
3583
3768
  }),
@@ -3594,6 +3779,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils27.lazySchema)(
3594
3779
  input_tokens: import_v422.z.number(),
3595
3780
  input_tokens_details: import_v422.z.object({
3596
3781
  cached_tokens: import_v422.z.number().nullish(),
3782
+ cache_write_tokens: import_v422.z.number().nullish(),
3597
3783
  orchestration_input_tokens: import_v422.z.number().nullish(),
3598
3784
  orchestration_input_cached_tokens: import_v422.z.number().nullish()
3599
3785
  }).nullish(),
@@ -3603,6 +3789,9 @@ var openaiResponsesChunkSchema = (0, import_provider_utils27.lazySchema)(
3603
3789
  orchestration_output_tokens: import_v422.z.number().nullish()
3604
3790
  }).nullish()
3605
3791
  }).nullish(),
3792
+ reasoning: import_v422.z.object({
3793
+ context: import_v422.z.string().nullish()
3794
+ }).nullish(),
3606
3795
  service_tier: import_v422.z.string().nullish()
3607
3796
  })
3608
3797
  }),
@@ -4374,11 +4563,15 @@ var openaiResponsesResponseSchema = (0, import_provider_utils27.lazySchema)(
4374
4563
  ])
4375
4564
  ).optional(),
4376
4565
  service_tier: import_v422.z.string().nullish(),
4566
+ reasoning: import_v422.z.object({
4567
+ context: import_v422.z.string().nullish()
4568
+ }).nullish(),
4377
4569
  incomplete_details: import_v422.z.object({ reason: import_v422.z.string() }).nullish(),
4378
4570
  usage: import_v422.z.object({
4379
4571
  input_tokens: import_v422.z.number(),
4380
4572
  input_tokens_details: import_v422.z.object({
4381
4573
  cached_tokens: import_v422.z.number().nullish(),
4574
+ cache_write_tokens: import_v422.z.number().nullish(),
4382
4575
  orchestration_input_tokens: import_v422.z.number().nullish(),
4383
4576
  orchestration_input_cached_tokens: import_v422.z.number().nullish()
4384
4577
  }).nullish(),
@@ -4533,11 +4726,22 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils28.lazy
4533
4726
  * Sets a cache key to tie this prompt to cached prefixes for better caching performance.
4534
4727
  */
4535
4728
  promptCacheKey: import_v423.z.string().nullish(),
4729
+ /**
4730
+ * Prompt cache behavior for GPT-5.6 and later models.
4731
+ * `mode` controls whether OpenAI also places an implicit breakpoint.
4732
+ * `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
4733
+ */
4734
+ promptCacheOptions: import_v423.z.object({
4735
+ mode: import_v423.z.enum(["implicit", "explicit"]).optional(),
4736
+ ttl: import_v423.z.literal("30m").optional()
4737
+ }).optional(),
4536
4738
  /**
4537
4739
  * The retention policy for the prompt cache.
4538
4740
  * - 'in_memory': Default. Standard prompt caching behavior.
4539
4741
  * - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
4540
- * Currently only available for 5.1 series models.
4742
+ * Available for models before GPT-5.6 that support extended caching.
4743
+ *
4744
+ * @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
4541
4745
  *
4542
4746
  * @default 'in_memory'
4543
4747
  */
@@ -4545,14 +4749,21 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils28.lazy
4545
4749
  /**
4546
4750
  * Reasoning effort for reasoning models. Defaults to `medium`. If you use
4547
4751
  * `providerOptions` to set the `reasoningEffort` option, this model setting will be ignored.
4548
- * Valid values: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'
4549
- *
4550
- * The 'none' type for `reasoningEffort` is only available for OpenAI's GPT-5.1
4551
- * models. Also, the 'xhigh' type for `reasoningEffort` is only available for
4552
- * OpenAI's GPT-5.1-Codex-Max model. Setting `reasoningEffort` to 'none' or 'xhigh' with unsupported models will result in
4553
- * an error.
4752
+ * GPT-5.6 supports 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'.
4753
+ * Supported values vary by model.
4554
4754
  */
4555
4755
  reasoningEffort: import_v423.z.string().nullish(),
4756
+ /**
4757
+ * Controls how much model work GPT-5.6 performs before returning a final answer.
4758
+ * `standard` is the default. `pro` increases quality, latency, and token usage.
4759
+ */
4760
+ reasoningMode: import_v423.z.enum(["standard", "pro"]).optional(),
4761
+ /**
4762
+ * Controls which available reasoning items GPT-5.6 can use.
4763
+ * `auto` uses the model default, `current_turn` excludes reasoning from earlier
4764
+ * turns, and `all_turns` makes compatible earlier reasoning available.
4765
+ */
4766
+ reasoningContext: import_v423.z.enum(["auto", "current_turn", "all_turns"]).optional(),
4556
4767
  /**
4557
4768
  * Controls reasoning summary output from the model.
4558
4769
  * Set to "auto" to automatically receive the richest level available,
@@ -5154,18 +5365,25 @@ var OpenAIResponsesLanguageModel = class {
5154
5365
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
5155
5366
  include,
5156
5367
  prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
5368
+ prompt_cache_options: openaiOptions == null ? void 0 : openaiOptions.promptCacheOptions,
5157
5369
  prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
5158
5370
  safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
5159
5371
  top_logprobs: topLogprobs,
5160
5372
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
5161
5373
  // model-specific settings:
5162
- ...isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
5374
+ ...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) && {
5163
5375
  reasoning: {
5164
5376
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
5165
5377
  effort: openaiOptions.reasoningEffort
5166
5378
  },
5167
5379
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
5168
5380
  summary: openaiOptions.reasoningSummary
5381
+ },
5382
+ ...(openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null && {
5383
+ mode: openaiOptions.reasoningMode
5384
+ },
5385
+ ...(openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null && {
5386
+ context: openaiOptions.reasoningContext
5169
5387
  }
5170
5388
  }
5171
5389
  }
@@ -5204,6 +5422,20 @@ var OpenAIResponsesLanguageModel = class {
5204
5422
  details: "reasoningSummary is not supported for non-reasoning models"
5205
5423
  });
5206
5424
  }
5425
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null) {
5426
+ warnings.push({
5427
+ type: "unsupported",
5428
+ feature: "reasoningMode",
5429
+ details: "reasoningMode is not supported for non-reasoning models"
5430
+ });
5431
+ }
5432
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) {
5433
+ warnings.push({
5434
+ type: "unsupported",
5435
+ feature: "reasoningContext",
5436
+ details: "reasoningContext is not supported for non-reasoning models"
5437
+ });
5438
+ }
5207
5439
  }
5208
5440
  if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
5209
5441
  warnings.push({
@@ -5240,7 +5472,7 @@ var OpenAIResponsesLanguageModel = class {
5240
5472
  };
5241
5473
  }
5242
5474
  async doGenerate(options) {
5243
- var _a, _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;
5475
+ var _a, _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;
5244
5476
  const {
5245
5477
  args: body,
5246
5478
  warnings,
@@ -5689,7 +5921,8 @@ var OpenAIResponsesLanguageModel = class {
5689
5921
  [providerOptionsName]: {
5690
5922
  responseId: response.id,
5691
5923
  ...logprobs.length > 0 ? { logprobs } : {},
5692
- ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {}
5924
+ ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
5925
+ ...((_z = response.reasoning) == null ? void 0 : _z.context) != null ? { reasoningContext: response.reasoning.context } : {}
5693
5926
  }
5694
5927
  };
5695
5928
  const usage = response.usage;
@@ -5697,10 +5930,10 @@ var OpenAIResponsesLanguageModel = class {
5697
5930
  content,
5698
5931
  finishReason: {
5699
5932
  unified: mapOpenAIResponseFinishReason({
5700
- finishReason: (_z = response.incomplete_details) == null ? void 0 : _z.reason,
5933
+ finishReason: (_A = response.incomplete_details) == null ? void 0 : _A.reason,
5701
5934
  hasFunctionCall
5702
5935
  }),
5703
- raw: (_B = (_A = response.incomplete_details) == null ? void 0 : _A.reason) != null ? _B : void 0
5936
+ raw: (_C = (_B = response.incomplete_details) == null ? void 0 : _B.reason) != null ? _C : void 0
5704
5937
  },
5705
5938
  usage: convertOpenAIResponsesUsage(usage),
5706
5939
  request: { body },
@@ -5767,6 +6000,7 @@ var OpenAIResponsesLanguageModel = class {
5767
6000
  let hasFunctionCall = false;
5768
6001
  const activeReasoning = {};
5769
6002
  let serviceTier;
6003
+ let reasoningContext;
5770
6004
  const hostedToolSearchCallIds = [];
5771
6005
  let encounteredStreamError = false;
5772
6006
  const result = {
@@ -5776,7 +6010,7 @@ var OpenAIResponsesLanguageModel = class {
5776
6010
  controller.enqueue({ type: "stream-start", warnings });
5777
6011
  },
5778
6012
  transform(chunk, controller) {
5779
- var _a, _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;
6013
+ var _a, _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;
5780
6014
  if (options.includeRawChunks) {
5781
6015
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
5782
6016
  }
@@ -6518,8 +6752,11 @@ var OpenAIResponsesLanguageModel = class {
6518
6752
  if (typeof value.response.service_tier === "string") {
6519
6753
  serviceTier = value.response.service_tier;
6520
6754
  }
6755
+ if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
6756
+ reasoningContext = value.response.reasoning.context;
6757
+ }
6521
6758
  } else if (isResponseFailedChunk(value)) {
6522
- const incompleteReason = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason;
6759
+ const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
6523
6760
  finishReason = {
6524
6761
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
6525
6762
  finishReason: incompleteReason,
@@ -6527,7 +6764,10 @@ var OpenAIResponsesLanguageModel = class {
6527
6764
  }) : "error",
6528
6765
  raw: incompleteReason != null ? incompleteReason : "error"
6529
6766
  };
6530
- usage = (_z = value.response.usage) != null ? _z : void 0;
6767
+ usage = (_A = value.response.usage) != null ? _A : void 0;
6768
+ if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
6769
+ reasoningContext = value.response.reasoning.context;
6770
+ }
6531
6771
  if (!encounteredStreamError && value.response.error != null) {
6532
6772
  encounteredStreamError = true;
6533
6773
  controller.enqueue({
@@ -6549,7 +6789,7 @@ var OpenAIResponsesLanguageModel = class {
6549
6789
  controller.enqueue({
6550
6790
  type: "source",
6551
6791
  sourceType: "url",
6552
- id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : (0, import_provider_utils30.generateId)(),
6792
+ id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : (0, import_provider_utils30.generateId)(),
6553
6793
  url: value.annotation.url,
6554
6794
  title: value.annotation.title
6555
6795
  });
@@ -6557,7 +6797,7 @@ var OpenAIResponsesLanguageModel = class {
6557
6797
  controller.enqueue({
6558
6798
  type: "source",
6559
6799
  sourceType: "document",
6560
- id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : (0, import_provider_utils30.generateId)(),
6800
+ id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : (0, import_provider_utils30.generateId)(),
6561
6801
  mediaType: "text/plain",
6562
6802
  title: value.annotation.filename,
6563
6803
  filename: value.annotation.filename,
@@ -6573,7 +6813,7 @@ var OpenAIResponsesLanguageModel = class {
6573
6813
  controller.enqueue({
6574
6814
  type: "source",
6575
6815
  sourceType: "document",
6576
- id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : (0, import_provider_utils30.generateId)(),
6816
+ id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : (0, import_provider_utils30.generateId)(),
6577
6817
  mediaType: "text/plain",
6578
6818
  title: value.annotation.filename,
6579
6819
  filename: value.annotation.filename,
@@ -6589,7 +6829,7 @@ var OpenAIResponsesLanguageModel = class {
6589
6829
  controller.enqueue({
6590
6830
  type: "source",
6591
6831
  sourceType: "document",
6592
- id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : (0, import_provider_utils30.generateId)(),
6832
+ id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : (0, import_provider_utils30.generateId)(),
6593
6833
  mediaType: "application/octet-stream",
6594
6834
  title: value.annotation.file_id,
6595
6835
  filename: value.annotation.file_id,
@@ -6613,7 +6853,8 @@ var OpenAIResponsesLanguageModel = class {
6613
6853
  [providerOptionsName]: {
6614
6854
  responseId,
6615
6855
  ...logprobs.length > 0 ? { logprobs } : {},
6616
- ...serviceTier !== void 0 ? { serviceTier } : {}
6856
+ ...serviceTier !== void 0 ? { serviceTier } : {},
6857
+ ...reasoningContext !== void 0 ? { reasoningContext } : {}
6617
6858
  }
6618
6859
  };
6619
6860
  controller.enqueue({
@@ -7089,7 +7330,7 @@ var OpenAITranscriptionModel = class {
7089
7330
  };
7090
7331
 
7091
7332
  // src/version.ts
7092
- var VERSION = true ? "3.0.83" : "0.0.0-test";
7333
+ var VERSION = true ? "3.0.85" : "0.0.0-test";
7093
7334
 
7094
7335
  // src/openai-provider.ts
7095
7336
  function createOpenAI(options = {}) {