@ai-sdk/openai 4.0.10 → 4.0.13

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
@@ -2,6 +2,7 @@
2
2
  import {
3
3
  loadApiKey,
4
4
  loadOptionalSetting,
5
+ validateBaseURL,
5
6
  withoutTrailingSlash,
6
7
  withUserAgentSuffix
7
8
  } from "@ai-sdk/provider-utils";
@@ -181,7 +182,7 @@ function isHttpErrorStatusCode(value) {
181
182
 
182
183
  // src/chat/convert-openai-chat-usage.ts
183
184
  function convertOpenAIChatUsage(usage) {
184
- var _a, _b, _c, _d, _e, _f;
185
+ var _a, _b, _c, _d, _e, _f, _g, _h;
185
186
  if (usage == null) {
186
187
  return {
187
188
  inputTokens: {
@@ -201,13 +202,14 @@ function convertOpenAIChatUsage(usage) {
201
202
  const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
202
203
  const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
203
204
  const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
204
- const reasoningTokens = (_f = (_e = usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
205
+ const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
206
+ const reasoningTokens = (_h = (_g = usage.completion_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : 0;
205
207
  return {
206
208
  inputTokens: {
207
209
  total: promptTokens,
208
- noCache: promptTokens - cachedTokens,
210
+ noCache: promptTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
209
211
  cacheRead: cachedTokens,
210
- cacheWrite: void 0
212
+ cacheWrite: cacheWriteTokens
211
213
  },
212
214
  outputTokens: {
213
215
  total: completionTokens,
@@ -231,23 +233,47 @@ import {
231
233
  function serializeToolCallArguments(input) {
232
234
  return JSON.stringify(input === void 0 ? {} : input);
233
235
  }
236
+ function getPromptCacheBreakpoint(providerOptions) {
237
+ var _a;
238
+ return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
239
+ }
234
240
  function convertToOpenAIChatMessages({
235
241
  prompt,
236
242
  systemMessageMode = "system"
237
243
  }) {
238
- var _a;
244
+ var _a, _b;
239
245
  const messages = [];
240
246
  const warnings = [];
241
- for (const { role, content } of prompt) {
247
+ for (const { role, content, providerOptions } of prompt) {
242
248
  switch (role) {
243
249
  case "system": {
244
250
  switch (systemMessageMode) {
245
251
  case "system": {
246
- messages.push({ role: "system", content });
252
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
253
+ messages.push({
254
+ role: "system",
255
+ content: promptCacheBreakpoint == null ? content : [
256
+ {
257
+ type: "text",
258
+ text: content,
259
+ prompt_cache_breakpoint: promptCacheBreakpoint
260
+ }
261
+ ]
262
+ });
247
263
  break;
248
264
  }
249
265
  case "developer": {
250
- messages.push({ role: "developer", content });
266
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
267
+ messages.push({
268
+ role: "developer",
269
+ content: promptCacheBreakpoint == null ? content : [
270
+ {
271
+ type: "text",
272
+ text: content,
273
+ prompt_cache_breakpoint: promptCacheBreakpoint
274
+ }
275
+ ]
276
+ });
251
277
  break;
252
278
  }
253
279
  case "remove": {
@@ -267,19 +293,31 @@ function convertToOpenAIChatMessages({
267
293
  break;
268
294
  }
269
295
  case "user": {
270
- if (content.length === 1 && content[0].type === "text") {
296
+ if (content.length === 1 && content[0].type === "text" && getPromptCacheBreakpoint(content[0].providerOptions) == null) {
271
297
  messages.push({ role: "user", content: content[0].text });
272
298
  break;
273
299
  }
274
300
  messages.push({
275
301
  role: "user",
276
302
  content: content.map((part, index) => {
277
- var _a2, _b, _c;
303
+ var _a2, _b2, _c;
278
304
  switch (part.type) {
279
305
  case "text": {
280
- return { type: "text", text: part.text };
306
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(
307
+ part.providerOptions
308
+ );
309
+ return {
310
+ type: "text",
311
+ text: part.text,
312
+ ...promptCacheBreakpoint != null && {
313
+ prompt_cache_breakpoint: promptCacheBreakpoint
314
+ }
315
+ };
281
316
  }
282
317
  case "file": {
318
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(
319
+ part.providerOptions
320
+ );
283
321
  switch (part.data.type) {
284
322
  case "reference": {
285
323
  return {
@@ -289,6 +327,9 @@ function convertToOpenAIChatMessages({
289
327
  reference: part.data.reference,
290
328
  provider: "openai"
291
329
  })
330
+ },
331
+ ...promptCacheBreakpoint != null && {
332
+ prompt_cache_breakpoint: promptCacheBreakpoint
292
333
  }
293
334
  };
294
335
  }
@@ -305,7 +346,10 @@ function convertToOpenAIChatMessages({
305
346
  type: "image_url",
306
347
  image_url: {
307
348
  url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
308
- detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
349
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
350
+ },
351
+ ...promptCacheBreakpoint != null && {
352
+ prompt_cache_breakpoint: promptCacheBreakpoint
309
353
  }
310
354
  };
311
355
  } else if (topLevel === "audio") {
@@ -322,6 +366,9 @@ function convertToOpenAIChatMessages({
322
366
  input_audio: {
323
367
  data: convertToBase64(part.data.data),
324
368
  format: "wav"
369
+ },
370
+ ...promptCacheBreakpoint != null && {
371
+ prompt_cache_breakpoint: promptCacheBreakpoint
325
372
  }
326
373
  };
327
374
  }
@@ -332,6 +379,9 @@ function convertToOpenAIChatMessages({
332
379
  input_audio: {
333
380
  data: convertToBase64(part.data.data),
334
381
  format: "mp3"
382
+ },
383
+ ...promptCacheBreakpoint != null && {
384
+ prompt_cache_breakpoint: promptCacheBreakpoint
335
385
  }
336
386
  };
337
387
  }
@@ -359,6 +409,9 @@ function convertToOpenAIChatMessages({
359
409
  file: {
360
410
  filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
361
411
  file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
412
+ },
413
+ ...promptCacheBreakpoint != null && {
414
+ prompt_cache_breakpoint: promptCacheBreakpoint
362
415
  }
363
416
  };
364
417
  }
@@ -372,11 +425,24 @@ function convertToOpenAIChatMessages({
372
425
  }
373
426
  case "assistant": {
374
427
  let text = "";
428
+ const textParts = [];
429
+ let hasPromptCacheBreakpoint = false;
375
430
  const toolCalls = [];
376
431
  for (const part of content) {
377
432
  switch (part.type) {
378
433
  case "text": {
434
+ const promptCacheBreakpoint = getPromptCacheBreakpoint(
435
+ part.providerOptions
436
+ );
379
437
  text += part.text;
438
+ textParts.push({
439
+ type: "text",
440
+ text: part.text,
441
+ ...promptCacheBreakpoint != null && {
442
+ prompt_cache_breakpoint: promptCacheBreakpoint
443
+ }
444
+ });
445
+ hasPromptCacheBreakpoint || (hasPromptCacheBreakpoint = promptCacheBreakpoint != null);
380
446
  break;
381
447
  }
382
448
  case "tool-call": {
@@ -394,7 +460,7 @@ function convertToOpenAIChatMessages({
394
460
  }
395
461
  messages.push({
396
462
  role: "assistant",
397
- content: toolCalls.length > 0 ? text || null : text,
463
+ content: hasPromptCacheBreakpoint ? textParts : toolCalls.length > 0 ? text || null : text,
398
464
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
399
465
  });
400
466
  break;
@@ -405,6 +471,7 @@ function convertToOpenAIChatMessages({
405
471
  continue;
406
472
  }
407
473
  const output = toolResponse.output;
474
+ 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);
408
475
  let contentValue;
409
476
  switch (output.type) {
410
477
  case "text":
@@ -412,7 +479,7 @@ function convertToOpenAIChatMessages({
412
479
  contentValue = output.value;
413
480
  break;
414
481
  case "execution-denied":
415
- contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
482
+ contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
416
483
  break;
417
484
  case "content":
418
485
  case "json":
@@ -423,7 +490,13 @@ function convertToOpenAIChatMessages({
423
490
  messages.push({
424
491
  role: "tool",
425
492
  tool_call_id: toolResponse.toolCallId,
426
- content: contentValue
493
+ content: promptCacheBreakpoint == null ? contentValue : [
494
+ {
495
+ type: "text",
496
+ text: contentValue,
497
+ prompt_cache_breakpoint: promptCacheBreakpoint
498
+ }
499
+ ]
427
500
  });
428
501
  }
429
502
  break;
@@ -529,7 +602,8 @@ var openaiChatResponseSchema = lazySchema(
529
602
  completion_tokens: z2.number().nullish(),
530
603
  total_tokens: z2.number().nullish(),
531
604
  prompt_tokens_details: z2.object({
532
- cached_tokens: z2.number().nullish()
605
+ cached_tokens: z2.number().nullish(),
606
+ cache_write_tokens: z2.number().nullish()
533
607
  }).nullish(),
534
608
  completion_tokens_details: z2.object({
535
609
  reasoning_tokens: z2.number().nullish(),
@@ -598,7 +672,8 @@ var openaiChatChunkSchema = lazySchema(
598
672
  completion_tokens: z2.number().nullish(),
599
673
  total_tokens: z2.number().nullish(),
600
674
  prompt_tokens_details: z2.object({
601
- cached_tokens: z2.number().nullish()
675
+ cached_tokens: z2.number().nullish(),
676
+ cache_write_tokens: z2.number().nullish()
602
677
  }).nullish(),
603
678
  completion_tokens_details: z2.object({
604
679
  reasoning_tokens: z2.number().nullish(),
@@ -650,7 +725,7 @@ var openaiLanguageModelChatOptions = lazySchema2(
650
725
  /**
651
726
  * Reasoning effort for reasoning models. Defaults to `medium`.
652
727
  */
653
- reasoningEffort: z3.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(),
728
+ reasoningEffort: z3.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional(),
654
729
  /**
655
730
  * Maximum number of completion tokens to generate. Useful for reasoning models.
656
731
  */
@@ -694,11 +769,22 @@ var openaiLanguageModelChatOptions = lazySchema2(
694
769
  * Useful for improving cache hit rates and working around automatic caching issues.
695
770
  */
696
771
  promptCacheKey: z3.string().optional(),
772
+ /**
773
+ * Prompt cache behavior for GPT-5.6 and later models.
774
+ * `mode` controls whether OpenAI also places an implicit breakpoint.
775
+ * `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
776
+ */
777
+ promptCacheOptions: z3.object({
778
+ mode: z3.enum(["implicit", "explicit"]).optional(),
779
+ ttl: z3.literal("30m").optional()
780
+ }).optional(),
697
781
  /**
698
782
  * The retention policy for the prompt cache.
699
783
  * - 'in_memory': Default. Standard prompt caching behavior.
700
784
  * - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
701
- * Currently only available for 5.1 series models.
785
+ * Available for models before GPT-5.6 that support extended caching.
786
+ *
787
+ * @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
702
788
  *
703
789
  * @default 'in_memory'
704
790
  */
@@ -893,6 +979,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
893
979
  reasoning_effort: resolvedReasoningEffort,
894
980
  service_tier: openaiOptions.serviceTier,
895
981
  prompt_cache_key: openaiOptions.promptCacheKey,
982
+ prompt_cache_options: openaiOptions.promptCacheOptions,
896
983
  prompt_cache_retention: openaiOptions.promptCacheRetention,
897
984
  safety_identifier: openaiOptions.safetyIdentifier,
898
985
  // messages:
@@ -3433,7 +3520,7 @@ import {
3433
3520
 
3434
3521
  // src/responses/convert-openai-responses-usage.ts
3435
3522
  function convertOpenAIResponsesUsage(usage) {
3436
- var _a, _b, _c, _d;
3523
+ var _a, _b, _c, _d, _e, _f;
3437
3524
  if (usage == null) {
3438
3525
  return {
3439
3526
  inputTokens: {
@@ -3453,13 +3540,14 @@ function convertOpenAIResponsesUsage(usage) {
3453
3540
  const inputTokens = usage.input_tokens;
3454
3541
  const outputTokens = usage.output_tokens;
3455
3542
  const cachedTokens = (_b = (_a = usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
3456
- const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
3543
+ const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
3544
+ const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
3457
3545
  return {
3458
3546
  inputTokens: {
3459
3547
  total: inputTokens,
3460
- noCache: inputTokens - cachedTokens,
3548
+ noCache: inputTokens - cachedTokens - (cacheWriteTokens != null ? cacheWriteTokens : 0),
3461
3549
  cacheRead: cachedTokens,
3462
- cacheWrite: void 0
3550
+ cacheWrite: cacheWriteTokens
3463
3551
  },
3464
3552
  outputTokens: {
3465
3553
  total: outputTokens,
@@ -3488,6 +3576,10 @@ import { z as z23 } from "zod/v4";
3488
3576
  function serializeToolCallArguments2(input) {
3489
3577
  return JSON.stringify(input === void 0 ? {} : input);
3490
3578
  }
3579
+ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3580
+ var _a;
3581
+ return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
3582
+ }
3491
3583
  function isFileId(data, prefixes) {
3492
3584
  if (!prefixes) return false;
3493
3585
  return prefixes.some((prefix) => data.startsWith(prefix));
@@ -3511,16 +3603,42 @@ async function convertToOpenAIResponsesInput({
3511
3603
  let input = [];
3512
3604
  const warnings = [];
3513
3605
  const processedApprovalIds = /* @__PURE__ */ new Set();
3514
- for (const { role, content } of prompt) {
3606
+ for (const { role, content, providerOptions } of prompt) {
3515
3607
  switch (role) {
3516
3608
  case "system": {
3517
3609
  switch (systemMessageMode) {
3518
3610
  case "system": {
3519
- input.push({ role: "system", content });
3611
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3612
+ providerOptions,
3613
+ providerOptionsName
3614
+ );
3615
+ input.push({
3616
+ role: "system",
3617
+ content: promptCacheBreakpoint == null ? content : [
3618
+ {
3619
+ type: "input_text",
3620
+ text: content,
3621
+ prompt_cache_breakpoint: promptCacheBreakpoint
3622
+ }
3623
+ ]
3624
+ });
3520
3625
  break;
3521
3626
  }
3522
3627
  case "developer": {
3523
- input.push({ role: "developer", content });
3628
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3629
+ providerOptions,
3630
+ providerOptionsName
3631
+ );
3632
+ input.push({
3633
+ role: "developer",
3634
+ content: promptCacheBreakpoint == null ? content : [
3635
+ {
3636
+ type: "input_text",
3637
+ text: content,
3638
+ prompt_cache_breakpoint: promptCacheBreakpoint
3639
+ }
3640
+ ]
3641
+ });
3524
3642
  break;
3525
3643
  }
3526
3644
  case "remove": {
@@ -3546,9 +3664,23 @@ async function convertToOpenAIResponsesInput({
3546
3664
  var _a2, _b2, _c2, _d2, _e2;
3547
3665
  switch (part.type) {
3548
3666
  case "text": {
3549
- return { type: "input_text", text: part.text };
3667
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3668
+ part.providerOptions,
3669
+ providerOptionsName
3670
+ );
3671
+ return {
3672
+ type: "input_text",
3673
+ text: part.text,
3674
+ ...promptCacheBreakpoint != null && {
3675
+ prompt_cache_breakpoint: promptCacheBreakpoint
3676
+ }
3677
+ };
3550
3678
  }
3551
3679
  case "file": {
3680
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3681
+ part.providerOptions,
3682
+ providerOptionsName
3683
+ );
3552
3684
  switch (part.data.type) {
3553
3685
  case "reference": {
3554
3686
  const fileId = resolveProviderReference2({
@@ -3559,12 +3691,18 @@ async function convertToOpenAIResponsesInput({
3559
3691
  return {
3560
3692
  type: "input_image",
3561
3693
  file_id: fileId,
3562
- detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3694
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3695
+ ...promptCacheBreakpoint != null && {
3696
+ prompt_cache_breakpoint: promptCacheBreakpoint
3697
+ }
3563
3698
  };
3564
3699
  }
3565
3700
  return {
3566
3701
  type: "input_file",
3567
- file_id: fileId
3702
+ file_id: fileId,
3703
+ ...promptCacheBreakpoint != null && {
3704
+ prompt_cache_breakpoint: promptCacheBreakpoint
3705
+ }
3568
3706
  };
3569
3707
  }
3570
3708
  case "text": {
@@ -3581,13 +3719,19 @@ async function convertToOpenAIResponsesInput({
3581
3719
  ...part.data.type === "url" ? { image_url: part.data.url.toString() } : typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
3582
3720
  image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase642(part.data.data)}`
3583
3721
  },
3584
- detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
3722
+ detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3723
+ ...promptCacheBreakpoint != null && {
3724
+ prompt_cache_breakpoint: promptCacheBreakpoint
3725
+ }
3585
3726
  };
3586
3727
  } else {
3587
3728
  if (part.data.type === "url") {
3588
3729
  return {
3589
3730
  type: "input_file",
3590
- file_url: part.data.url.toString()
3731
+ file_url: part.data.url.toString(),
3732
+ ...promptCacheBreakpoint != null && {
3733
+ prompt_cache_breakpoint: promptCacheBreakpoint
3734
+ }
3591
3735
  };
3592
3736
  }
3593
3737
  const fullMediaType = resolveFullMediaType2({ part });
@@ -3601,6 +3745,9 @@ async function convertToOpenAIResponsesInput({
3601
3745
  ...typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
3602
3746
  filename: (_e2 = part.filename) != null ? _e2 : fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
3603
3747
  file_data: `data:${fullMediaType};base64,${convertToBase642(part.data.data)}`
3748
+ },
3749
+ ...promptCacheBreakpoint != null && {
3750
+ prompt_cache_breakpoint: promptCacheBreakpoint
3604
3751
  }
3605
3752
  };
3606
3753
  }
@@ -3617,9 +3764,9 @@ async function convertToOpenAIResponsesInput({
3617
3764
  for (const part of content) {
3618
3765
  switch (part.type) {
3619
3766
  case "text": {
3620
- const providerOptions = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName];
3621
- const id = providerOptions == null ? void 0 : providerOptions.itemId;
3622
- const phase = providerOptions == null ? void 0 : providerOptions.phase;
3767
+ const providerOptions2 = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName];
3768
+ const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
3769
+ const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
3623
3770
  if (hasConversation && id != null) {
3624
3771
  break;
3625
3772
  }
@@ -3816,12 +3963,12 @@ async function convertToOpenAIResponsesInput({
3816
3963
  break;
3817
3964
  }
3818
3965
  case "reasoning": {
3819
- const providerOptions = await parseProviderOptions6({
3966
+ const providerOptions2 = await parseProviderOptions6({
3820
3967
  provider: providerOptionsName,
3821
3968
  providerOptions: part.providerOptions,
3822
3969
  schema: openaiResponsesReasoningProviderOptionsSchema
3823
3970
  });
3824
- const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
3971
+ const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
3825
3972
  if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
3826
3973
  break;
3827
3974
  }
@@ -3853,19 +4000,19 @@ async function convertToOpenAIResponsesInput({
3853
4000
  reasoningMessages[reasoningId] = {
3854
4001
  type: "reasoning",
3855
4002
  id: reasoningId,
3856
- encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
4003
+ encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
3857
4004
  summary: summaryParts
3858
4005
  };
3859
4006
  input.push(reasoningMessages[reasoningId]);
3860
4007
  } else {
3861
4008
  reasoningMessage.summary.push(...summaryParts);
3862
- if ((providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent) != null) {
3863
- reasoningMessage.encrypted_content = providerOptions.reasoningEncryptedContent;
4009
+ if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
4010
+ reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
3864
4011
  }
3865
4012
  }
3866
4013
  }
3867
4014
  } else {
3868
- const encryptedContent = providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent;
4015
+ const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent;
3869
4016
  if (encryptedContent != null) {
3870
4017
  const summaryParts = [];
3871
4018
  if (part.text.length > 0) {
@@ -3890,8 +4037,8 @@ async function convertToOpenAIResponsesInput({
3890
4037
  }
3891
4038
  case "custom": {
3892
4039
  if (part.kind === "openai.compaction") {
3893
- const providerOptions = (_t = part.providerOptions) == null ? void 0 : _t[providerOptionsName];
3894
- const id = providerOptions == null ? void 0 : providerOptions.itemId;
4040
+ const providerOptions2 = (_t = part.providerOptions) == null ? void 0 : _t[providerOptionsName];
4041
+ const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
3895
4042
  if (hasConversation && id != null) {
3896
4043
  break;
3897
4044
  }
@@ -3899,7 +4046,7 @@ async function convertToOpenAIResponsesInput({
3899
4046
  input.push({ type: "item_reference", id });
3900
4047
  break;
3901
4048
  }
3902
- const encryptedContent = providerOptions == null ? void 0 : providerOptions.encryptedContent;
4049
+ const encryptedContent = providerOptions2 == null ? void 0 : providerOptions2.encryptedContent;
3903
4050
  if (id != null) {
3904
4051
  input.push({
3905
4052
  type: "compaction",
@@ -4020,9 +4167,19 @@ async function convertToOpenAIResponsesInput({
4020
4167
  case "content":
4021
4168
  outputValue = output.value.map((item) => {
4022
4169
  var _a2, _b2, _c2;
4170
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
4171
+ item.providerOptions,
4172
+ providerOptionsName
4173
+ );
4023
4174
  switch (item.type) {
4024
4175
  case "text":
4025
- return { type: "input_text", text: item.text };
4176
+ return {
4177
+ type: "input_text",
4178
+ text: item.text,
4179
+ ...promptCacheBreakpoint != null && {
4180
+ prompt_cache_breakpoint: promptCacheBreakpoint
4181
+ }
4182
+ };
4026
4183
  case "file": {
4027
4184
  const topLevel = getTopLevelMediaType2(item.mediaType);
4028
4185
  const imageDetail = (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
@@ -4034,13 +4191,19 @@ async function convertToOpenAIResponsesInput({
4034
4191
  return {
4035
4192
  type: "input_image",
4036
4193
  image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
4037
- detail: imageDetail
4194
+ detail: imageDetail,
4195
+ ...promptCacheBreakpoint != null && {
4196
+ prompt_cache_breakpoint: promptCacheBreakpoint
4197
+ }
4038
4198
  };
4039
4199
  }
4040
4200
  return {
4041
4201
  type: "input_file",
4042
4202
  filename: (_c2 = item.filename) != null ? _c2 : "data",
4043
- file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`
4203
+ file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
4204
+ ...promptCacheBreakpoint != null && {
4205
+ prompt_cache_breakpoint: promptCacheBreakpoint
4206
+ }
4044
4207
  };
4045
4208
  }
4046
4209
  if (item.data.type === "url") {
@@ -4048,12 +4211,18 @@ async function convertToOpenAIResponsesInput({
4048
4211
  return {
4049
4212
  type: "input_image",
4050
4213
  image_url: item.data.url.toString(),
4051
- detail: imageDetail
4214
+ detail: imageDetail,
4215
+ ...promptCacheBreakpoint != null && {
4216
+ prompt_cache_breakpoint: promptCacheBreakpoint
4217
+ }
4052
4218
  };
4053
4219
  }
4054
4220
  return {
4055
4221
  type: "input_file",
4056
- file_url: item.data.url.toString()
4222
+ file_url: item.data.url.toString(),
4223
+ ...promptCacheBreakpoint != null && {
4224
+ prompt_cache_breakpoint: promptCacheBreakpoint
4225
+ }
4057
4226
  };
4058
4227
  }
4059
4228
  warnings.push({
@@ -4097,9 +4266,19 @@ async function convertToOpenAIResponsesInput({
4097
4266
  case "content":
4098
4267
  contentValue = output.value.map((item) => {
4099
4268
  var _a2, _b2, _c2;
4269
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
4270
+ item.providerOptions,
4271
+ providerOptionsName
4272
+ );
4100
4273
  switch (item.type) {
4101
4274
  case "text": {
4102
- return { type: "input_text", text: item.text };
4275
+ return {
4276
+ type: "input_text",
4277
+ text: item.text,
4278
+ ...promptCacheBreakpoint != null && {
4279
+ prompt_cache_breakpoint: promptCacheBreakpoint
4280
+ }
4281
+ };
4103
4282
  }
4104
4283
  case "file": {
4105
4284
  const topLevel = getTopLevelMediaType2(item.mediaType);
@@ -4112,13 +4291,19 @@ async function convertToOpenAIResponsesInput({
4112
4291
  return {
4113
4292
  type: "input_image",
4114
4293
  image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
4115
- detail: imageDetail
4294
+ detail: imageDetail,
4295
+ ...promptCacheBreakpoint != null && {
4296
+ prompt_cache_breakpoint: promptCacheBreakpoint
4297
+ }
4116
4298
  };
4117
4299
  }
4118
4300
  return {
4119
4301
  type: "input_file",
4120
4302
  filename: (_c2 = item.filename) != null ? _c2 : "data",
4121
- file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`
4303
+ file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
4304
+ ...promptCacheBreakpoint != null && {
4305
+ prompt_cache_breakpoint: promptCacheBreakpoint
4306
+ }
4122
4307
  };
4123
4308
  }
4124
4309
  if (item.data.type === "url") {
@@ -4126,12 +4311,18 @@ async function convertToOpenAIResponsesInput({
4126
4311
  return {
4127
4312
  type: "input_image",
4128
4313
  image_url: item.data.url.toString(),
4129
- detail: imageDetail
4314
+ detail: imageDetail,
4315
+ ...promptCacheBreakpoint != null && {
4316
+ prompt_cache_breakpoint: promptCacheBreakpoint
4317
+ }
4130
4318
  };
4131
4319
  }
4132
4320
  return {
4133
4321
  type: "input_file",
4134
- file_url: item.data.url.toString()
4322
+ file_url: item.data.url.toString(),
4323
+ ...promptCacheBreakpoint != null && {
4324
+ prompt_cache_breakpoint: promptCacheBreakpoint
4325
+ }
4135
4326
  };
4136
4327
  }
4137
4328
  warnings.push({
@@ -4262,6 +4453,7 @@ var openaiResponsesChunkSchema = lazySchema22(
4262
4453
  input_tokens: z24.number(),
4263
4454
  input_tokens_details: z24.object({
4264
4455
  cached_tokens: z24.number().nullish(),
4456
+ cache_write_tokens: z24.number().nullish(),
4265
4457
  orchestration_input_tokens: z24.number().nullish(),
4266
4458
  orchestration_input_cached_tokens: z24.number().nullish()
4267
4459
  }).nullish(),
@@ -4271,6 +4463,9 @@ var openaiResponsesChunkSchema = lazySchema22(
4271
4463
  orchestration_output_tokens: z24.number().nullish()
4272
4464
  }).nullish()
4273
4465
  }),
4466
+ reasoning: z24.object({
4467
+ context: z24.string().nullish()
4468
+ }).nullish(),
4274
4469
  service_tier: z24.string().nullish()
4275
4470
  })
4276
4471
  }),
@@ -4287,6 +4482,7 @@ var openaiResponsesChunkSchema = lazySchema22(
4287
4482
  input_tokens: z24.number(),
4288
4483
  input_tokens_details: z24.object({
4289
4484
  cached_tokens: z24.number().nullish(),
4485
+ cache_write_tokens: z24.number().nullish(),
4290
4486
  orchestration_input_tokens: z24.number().nullish(),
4291
4487
  orchestration_input_cached_tokens: z24.number().nullish()
4292
4488
  }).nullish(),
@@ -4296,6 +4492,9 @@ var openaiResponsesChunkSchema = lazySchema22(
4296
4492
  orchestration_output_tokens: z24.number().nullish()
4297
4493
  }).nullish()
4298
4494
  }).nullish(),
4495
+ reasoning: z24.object({
4496
+ context: z24.string().nullish()
4497
+ }).nullish(),
4299
4498
  service_tier: z24.string().nullish()
4300
4499
  })
4301
4500
  }),
@@ -5082,11 +5281,15 @@ var openaiResponsesResponseSchema = lazySchema22(
5082
5281
  ])
5083
5282
  ).optional(),
5084
5283
  service_tier: z24.string().nullish(),
5284
+ reasoning: z24.object({
5285
+ context: z24.string().nullish()
5286
+ }).nullish(),
5085
5287
  incomplete_details: z24.object({ reason: z24.string() }).nullish(),
5086
5288
  usage: z24.object({
5087
5289
  input_tokens: z24.number(),
5088
5290
  input_tokens_details: z24.object({
5089
5291
  cached_tokens: z24.number().nullish(),
5292
+ cache_write_tokens: z24.number().nullish(),
5090
5293
  orchestration_input_tokens: z24.number().nullish(),
5091
5294
  orchestration_input_cached_tokens: z24.number().nullish()
5092
5295
  }).nullish(),
@@ -5244,11 +5447,22 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema23(
5244
5447
  * Sets a cache key to tie this prompt to cached prefixes for better caching performance.
5245
5448
  */
5246
5449
  promptCacheKey: z25.string().nullish(),
5450
+ /**
5451
+ * Prompt cache behavior for GPT-5.6 and later models.
5452
+ * `mode` controls whether OpenAI also places an implicit breakpoint.
5453
+ * `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
5454
+ */
5455
+ promptCacheOptions: z25.object({
5456
+ mode: z25.enum(["implicit", "explicit"]).optional(),
5457
+ ttl: z25.literal("30m").optional()
5458
+ }).optional(),
5247
5459
  /**
5248
5460
  * The retention policy for the prompt cache.
5249
5461
  * - 'in_memory': Default. Standard prompt caching behavior.
5250
5462
  * - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
5251
- * Currently only available for 5.1 series models.
5463
+ * Available for models before GPT-5.6 that support extended caching.
5464
+ *
5465
+ * @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
5252
5466
  *
5253
5467
  * @default 'in_memory'
5254
5468
  */
@@ -5256,14 +5470,21 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema23(
5256
5470
  /**
5257
5471
  * Reasoning effort for reasoning models. Defaults to `medium`. If you use
5258
5472
  * `providerOptions` to set the `reasoningEffort` option, this model setting will be ignored.
5259
- * Valid values: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'
5260
- *
5261
- * The 'none' type for `reasoningEffort` is only available for OpenAI's GPT-5.1
5262
- * models. Also, the 'xhigh' type for `reasoningEffort` is only available for
5263
- * OpenAI's GPT-5.1-Codex-Max model. Setting `reasoningEffort` to 'none' or 'xhigh' with unsupported models will result in
5264
- * an error.
5473
+ * GPT-5.6 supports 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'.
5474
+ * Supported values vary by model.
5265
5475
  */
5266
5476
  reasoningEffort: z25.string().nullish(),
5477
+ /**
5478
+ * Controls how much model work GPT-5.6 performs before returning a final answer.
5479
+ * `standard` is the default. `pro` increases quality, latency, and token usage.
5480
+ */
5481
+ reasoningMode: z25.enum(["standard", "pro"]).optional(),
5482
+ /**
5483
+ * Controls which available reasoning items GPT-5.6 can use.
5484
+ * `auto` uses the model default, `current_turn` excludes reasoning from earlier
5485
+ * turns, and `all_turns` makes compatible earlier reasoning available.
5486
+ */
5487
+ reasoningContext: z25.enum(["auto", "current_turn", "all_turns"]).optional(),
5267
5488
  /**
5268
5489
  * Controls reasoning summary output from the model.
5269
5490
  * Set to "auto" to automatically receive the richest level available,
@@ -5896,6 +6117,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
5896
6117
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
5897
6118
  include,
5898
6119
  prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
6120
+ prompt_cache_options: openaiOptions == null ? void 0 : openaiOptions.promptCacheOptions,
5899
6121
  prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
5900
6122
  safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
5901
6123
  top_logprobs: topLogprobs,
@@ -5908,13 +6130,19 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
5908
6130
  }))
5909
6131
  },
5910
6132
  // model-specific settings:
5911
- ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null) && {
6133
+ ...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) && {
5912
6134
  reasoning: {
5913
6135
  ...resolvedReasoningEffort != null && {
5914
6136
  effort: resolvedReasoningEffort
5915
6137
  },
5916
6138
  ...resolvedReasoningSummary != null && {
5917
6139
  summary: resolvedReasoningSummary
6140
+ },
6141
+ ...(openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null && {
6142
+ mode: openaiOptions.reasoningMode
6143
+ },
6144
+ ...(openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null && {
6145
+ context: openaiOptions.reasoningContext
5918
6146
  }
5919
6147
  }
5920
6148
  }
@@ -5953,6 +6181,20 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
5953
6181
  details: "reasoningSummary is not supported for non-reasoning models"
5954
6182
  });
5955
6183
  }
6184
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null) {
6185
+ warnings.push({
6186
+ type: "unsupported",
6187
+ feature: "reasoningMode",
6188
+ details: "reasoningMode is not supported for non-reasoning models"
6189
+ });
6190
+ }
6191
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) {
6192
+ warnings.push({
6193
+ type: "unsupported",
6194
+ feature: "reasoningContext",
6195
+ details: "reasoningContext is not supported for non-reasoning models"
6196
+ });
6197
+ }
5956
6198
  }
5957
6199
  if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
5958
6200
  warnings.push({
@@ -5989,7 +6231,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
5989
6231
  };
5990
6232
  }
5991
6233
  async doGenerate(options) {
5992
- 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;
6234
+ 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;
5993
6235
  const {
5994
6236
  args: body,
5995
6237
  warnings,
@@ -6452,7 +6694,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6452
6694
  [providerOptionsName]: {
6453
6695
  responseId: response.id,
6454
6696
  ...logprobs.length > 0 ? { logprobs } : {},
6455
- ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {}
6697
+ ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
6698
+ ...((_B = response.reasoning) == null ? void 0 : _B.context) != null ? { reasoningContext: response.reasoning.context } : {}
6456
6699
  }
6457
6700
  };
6458
6701
  const usage = response.usage;
@@ -6460,10 +6703,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6460
6703
  content,
6461
6704
  finishReason: {
6462
6705
  unified: mapOpenAIResponseFinishReason({
6463
- finishReason: (_B = response.incomplete_details) == null ? void 0 : _B.reason,
6706
+ finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
6464
6707
  hasFunctionCall
6465
6708
  }),
6466
- raw: (_D = (_C = response.incomplete_details) == null ? void 0 : _C.reason) != null ? _D : void 0
6709
+ raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
6467
6710
  },
6468
6711
  usage: convertOpenAIResponsesUsage(usage),
6469
6712
  request: { body },
@@ -6531,6 +6774,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6531
6774
  let hasFunctionCall = false;
6532
6775
  const activeReasoning = {};
6533
6776
  let serviceTier;
6777
+ let reasoningContext;
6534
6778
  const hostedToolSearchCallIds = [];
6535
6779
  let encounteredStreamError = false;
6536
6780
  const result = {
@@ -6540,7 +6784,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6540
6784
  controller.enqueue({ type: "stream-start", warnings });
6541
6785
  },
6542
6786
  transform(chunk, controller) {
6543
- var _a2, _b2, _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;
6787
+ var _a2, _b2, _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;
6544
6788
  if (options.includeRawChunks) {
6545
6789
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6546
6790
  }
@@ -7294,8 +7538,11 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7294
7538
  if (typeof value.response.service_tier === "string") {
7295
7539
  serviceTier = value.response.service_tier;
7296
7540
  }
7541
+ if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
7542
+ reasoningContext = value.response.reasoning.context;
7543
+ }
7297
7544
  } else if (isResponseFailedChunk(value)) {
7298
- const incompleteReason = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason;
7545
+ const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
7299
7546
  finishReason = {
7300
7547
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
7301
7548
  finishReason: incompleteReason,
@@ -7303,7 +7550,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7303
7550
  }) : "error",
7304
7551
  raw: incompleteReason != null ? incompleteReason : "error"
7305
7552
  };
7306
- usage = (_z = value.response.usage) != null ? _z : void 0;
7553
+ usage = (_A = value.response.usage) != null ? _A : void 0;
7554
+ if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
7555
+ reasoningContext = value.response.reasoning.context;
7556
+ }
7307
7557
  if (!encounteredStreamError && value.response.error != null) {
7308
7558
  encounteredStreamError = true;
7309
7559
  controller.enqueue({
@@ -7325,7 +7575,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7325
7575
  controller.enqueue({
7326
7576
  type: "source",
7327
7577
  sourceType: "url",
7328
- id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId2(),
7578
+ id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
7329
7579
  url: value.annotation.url,
7330
7580
  title: value.annotation.title
7331
7581
  });
@@ -7333,7 +7583,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7333
7583
  controller.enqueue({
7334
7584
  type: "source",
7335
7585
  sourceType: "document",
7336
- id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId2(),
7586
+ id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
7337
7587
  mediaType: "text/plain",
7338
7588
  title: value.annotation.filename,
7339
7589
  filename: value.annotation.filename,
@@ -7349,7 +7599,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7349
7599
  controller.enqueue({
7350
7600
  type: "source",
7351
7601
  sourceType: "document",
7352
- id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
7602
+ id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
7353
7603
  mediaType: "text/plain",
7354
7604
  title: value.annotation.filename,
7355
7605
  filename: value.annotation.filename,
@@ -7365,7 +7615,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7365
7615
  controller.enqueue({
7366
7616
  type: "source",
7367
7617
  sourceType: "document",
7368
- id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
7618
+ id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
7369
7619
  mediaType: "application/octet-stream",
7370
7620
  title: value.annotation.file_id,
7371
7621
  filename: value.annotation.file_id,
@@ -7389,7 +7639,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7389
7639
  [providerOptionsName]: {
7390
7640
  responseId,
7391
7641
  ...logprobs.length > 0 ? { logprobs } : {},
7392
- ...serviceTier !== void 0 ? { serviceTier } : {}
7642
+ ...serviceTier !== void 0 ? { serviceTier } : {},
7643
+ ...reasoningContext !== void 0 ? { reasoningContext } : {}
7393
7644
  }
7394
7645
  };
7395
7646
  controller.enqueue({
@@ -7657,16 +7908,16 @@ import {
7657
7908
  convertBase64ToUint8Array as convertBase64ToUint8Array2,
7658
7909
  convertToBase64 as convertToBase643,
7659
7910
  createJsonResponseHandler as createJsonResponseHandler7,
7660
- getWebSocketConstructor,
7911
+ connectToWebSocket,
7661
7912
  mediaTypeToExtension,
7662
7913
  parseProviderOptions as parseProviderOptions9,
7663
7914
  postFormDataToApi as postFormDataToApi3,
7664
- readWebSocketMessageText,
7665
7915
  safeParseJSON,
7666
7916
  serializeModelOptions as serializeModelOptions7,
7667
7917
  toWebSocketUrl,
7668
7918
  WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE7,
7669
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7
7919
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE7,
7920
+ waitForWebSocketBufferDrain
7670
7921
  } from "@ai-sdk/provider-utils";
7671
7922
 
7672
7923
  // src/transcription/openai-transcription-api.ts
@@ -8015,21 +8266,18 @@ function createOpenAIRealtimeTranscriptionStream({
8015
8266
  };
8016
8267
  return new ReadableStream({
8017
8268
  start: (controller) => {
8018
- const WebSocketConstructor = getWebSocketConstructor(webSocket);
8019
- const ws = new WebSocketConstructor(
8020
- url,
8021
- getOpenAIRealtimeProtocols(headers),
8022
- { headers }
8023
- );
8269
+ const realtimeConnection = getOpenAIRealtimeConnection(headers);
8024
8270
  let audioReader;
8271
+ let connection;
8025
8272
  cleanup = (closeCode) => {
8026
- abortSignal == null ? void 0 : abortSignal.removeEventListener("abort", abort);
8027
- void (audioReader == null ? void 0 : audioReader.cancel().catch(() => {
8028
- }));
8029
- try {
8030
- ws.close(closeCode);
8031
- } catch (e) {
8273
+ if (audioReader != null) {
8274
+ void audioReader.cancel().catch(() => {
8275
+ });
8276
+ } else {
8277
+ void audio.cancel().catch(() => {
8278
+ });
8032
8279
  }
8280
+ connection == null ? void 0 : connection.close(closeCode);
8033
8281
  };
8034
8282
  const finishWithError = (error) => {
8035
8283
  if (finished) return;
@@ -8052,42 +8300,42 @@ function createOpenAIRealtimeTranscriptionStream({
8052
8300
  controller.close();
8053
8301
  cleanup(1e3);
8054
8302
  };
8055
- const abort = () => {
8056
- var _a;
8057
- finishWithError((_a = abortSignal == null ? void 0 : abortSignal.reason) != null ? _a : new Error("Aborted"));
8058
- };
8059
- if (abortSignal == null ? void 0 : abortSignal.aborted) {
8060
- abort();
8061
- return;
8062
- }
8063
- abortSignal == null ? void 0 : abortSignal.addEventListener("abort", abort, { once: true });
8064
- const sendAudio = async () => {
8303
+ const sendAudio = async (socket) => {
8065
8304
  audioReader = audio.getReader();
8066
8305
  try {
8067
8306
  while (true) {
8068
8307
  const { done, value } = await audioReader.read();
8069
8308
  if (done || finished) break;
8070
- ws.send(
8309
+ socket.send(
8071
8310
  JSON.stringify({
8072
8311
  type: "input_audio_buffer.append",
8073
8312
  audio: convertToBase643(value)
8074
8313
  })
8075
8314
  );
8315
+ await waitForWebSocketBufferDrain(socket);
8076
8316
  }
8077
8317
  } finally {
8078
8318
  audioReader.releaseLock();
8319
+ audioReader = void 0;
8079
8320
  }
8080
8321
  if (!finished) {
8081
- ws.send(JSON.stringify({ type: "input_audio_buffer.commit" }));
8322
+ socket.send(JSON.stringify({ type: "input_audio_buffer.commit" }));
8082
8323
  }
8083
8324
  };
8084
- ws.onopen = () => {
8085
- controller.enqueue({ type: "stream-start", warnings });
8086
- ws.send(JSON.stringify(sessionUpdate));
8087
- void sendAudio().catch(finishWithError);
8088
- };
8089
- ws.onmessage = (event) => {
8090
- void readWebSocketMessageText(event.data).then(async (text) => {
8325
+ connection = connectToWebSocket({
8326
+ url,
8327
+ protocols: realtimeConnection.protocols,
8328
+ headers: realtimeConnection.headers,
8329
+ webSocket,
8330
+ abortSignal,
8331
+ onAbort: finishWithError,
8332
+ onProcessingError: finishWithError,
8333
+ onOpen: (socket) => {
8334
+ controller.enqueue({ type: "stream-start", warnings });
8335
+ socket.send(JSON.stringify(sessionUpdate));
8336
+ void sendAudio(socket).catch(finishWithError);
8337
+ },
8338
+ onMessageText: async (text) => {
8091
8339
  var _a, _b, _c, _d;
8092
8340
  const parsed = await safeParseJSON({ text });
8093
8341
  if (!parsed.success) return;
@@ -8115,17 +8363,17 @@ function createOpenAIRealtimeTranscriptionStream({
8115
8363
  break;
8116
8364
  }
8117
8365
  }
8118
- }).catch(finishWithError);
8119
- };
8120
- ws.onerror = () => {
8121
- finishWithError(new Error("OpenAI realtime transcription error"));
8122
- };
8123
- ws.onclose = () => {
8124
- if (finished) return;
8125
- finished = true;
8126
- cleanup();
8127
- controller.close();
8128
- };
8366
+ },
8367
+ onSocketError: () => {
8368
+ finishWithError(new Error("OpenAI realtime transcription error"));
8369
+ },
8370
+ onClose: () => {
8371
+ if (finished) return;
8372
+ finished = true;
8373
+ cleanup();
8374
+ controller.close();
8375
+ }
8376
+ });
8129
8377
  },
8130
8378
  cancel: () => {
8131
8379
  if (finished) return;
@@ -8162,11 +8410,26 @@ function buildOpenAIRealtimeTranscriptionSession({
8162
8410
  }
8163
8411
  };
8164
8412
  }
8165
- function getOpenAIRealtimeProtocols(headers) {
8413
+ function getOpenAIRealtimeConnection(headers) {
8166
8414
  var _a;
8167
- const authorization = (_a = headers.Authorization) != null ? _a : headers.authorization;
8168
- const token = (authorization == null ? void 0 : authorization.startsWith("Bearer ")) ? authorization.slice("Bearer ".length) : void 0;
8169
- return token == null ? ["realtime"] : ["realtime", `openai-insecure-api-key.${token}`];
8415
+ let authorization;
8416
+ for (const [key, value] of Object.entries(headers)) {
8417
+ if (key.toLowerCase() === "authorization" && value != null) {
8418
+ authorization = value;
8419
+ }
8420
+ }
8421
+ const token = (_a = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a[1];
8422
+ if (token == null) {
8423
+ return { protocols: ["realtime"], headers };
8424
+ }
8425
+ return {
8426
+ protocols: ["realtime", `openai-insecure-api-key.${token}`],
8427
+ headers: Object.fromEntries(
8428
+ Object.entries(headers).filter(
8429
+ ([key]) => key.toLowerCase() !== "authorization"
8430
+ )
8431
+ )
8432
+ };
8170
8433
  }
8171
8434
 
8172
8435
  // src/skills/openai-skills.ts
@@ -8254,16 +8517,18 @@ var OpenAISkills = class {
8254
8517
  };
8255
8518
 
8256
8519
  // src/version.ts
8257
- var VERSION = true ? "4.0.10" : "0.0.0-test";
8520
+ var VERSION = true ? "4.0.13" : "0.0.0-test";
8258
8521
 
8259
8522
  // src/openai-provider.ts
8260
8523
  function createOpenAI(options = {}) {
8261
8524
  var _a, _b;
8262
8525
  const baseURL = (_a = withoutTrailingSlash(
8263
- loadOptionalSetting({
8264
- settingValue: options.baseURL,
8265
- environmentVariableName: "OPENAI_BASE_URL"
8266
- })
8526
+ validateBaseURL(
8527
+ loadOptionalSetting({
8528
+ settingValue: options.baseURL,
8529
+ environmentVariableName: "OPENAI_BASE_URL"
8530
+ })
8531
+ )
8267
8532
  )) != null ? _a : "https://api.openai.com/v1";
8268
8533
  const providerName = (_b = options.name) != null ? _b : "openai";
8269
8534
  const getHeaders = () => withUserAgentSuffix(