@ai-sdk/openai 3.0.136 → 3.0.138

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
@@ -658,10 +658,13 @@ function getResponseMetadata({
658
658
  }
659
659
 
660
660
  // src/chat/map-openai-finish-reason.ts
661
- function mapOpenAIFinishReason(finishReason) {
661
+ function mapOpenAIFinishReason({
662
+ finishReason,
663
+ hasRefusal = false
664
+ }) {
662
665
  switch (finishReason) {
663
666
  case "stop":
664
- return "stop";
667
+ return hasRefusal ? "content-filter" : "stop";
665
668
  case "length":
666
669
  return "length";
667
670
  case "content_filter":
@@ -688,6 +691,8 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazySchema)(
688
691
  message: import_v42.z.object({
689
692
  role: import_v42.z.literal("assistant").nullish(),
690
693
  content: import_v42.z.string().nullish(),
694
+ // set instead of `content` when the model refuses to answer:
695
+ refusal: import_v42.z.string().nullish(),
691
696
  audio: import_v42.z.object({
692
697
  transcript: import_v42.z.string().nullish()
693
698
  }).nullish(),
@@ -726,6 +731,20 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazySchema)(
726
731
  })
727
732
  )
728
733
  })
734
+ ).nullish(),
735
+ // logprobs of the refusal tokens (set instead of `content` when
736
+ // the model refuses to answer):
737
+ refusal: import_v42.z.array(
738
+ import_v42.z.object({
739
+ token: import_v42.z.string(),
740
+ logprob: import_v42.z.number(),
741
+ top_logprobs: import_v42.z.array(
742
+ import_v42.z.object({
743
+ token: import_v42.z.string(),
744
+ logprob: import_v42.z.number()
745
+ })
746
+ )
747
+ })
729
748
  ).nullish()
730
749
  }).nullish(),
731
750
  finish_reason: import_v42.z.string().nullish()
@@ -760,6 +779,8 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazySchema)(
760
779
  delta: import_v42.z.object({
761
780
  role: import_v42.z.enum(["assistant"]).nullish(),
762
781
  content: import_v42.z.string().nullish(),
782
+ // set instead of `content` when the model refuses to answer:
783
+ refusal: import_v42.z.string().nullish(),
763
784
  tool_calls: import_v42.z.array(
764
785
  import_v42.z.object({
765
786
  index: import_v42.z.number(),
@@ -795,6 +816,20 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazySchema)(
795
816
  })
796
817
  )
797
818
  })
819
+ ).nullish(),
820
+ // logprobs of the refusal tokens (set instead of `content` when
821
+ // the model refuses to answer):
822
+ refusal: import_v42.z.array(
823
+ import_v42.z.object({
824
+ token: import_v42.z.string(),
825
+ logprob: import_v42.z.number(),
826
+ top_logprobs: import_v42.z.array(
827
+ import_v42.z.object({
828
+ token: import_v42.z.string(),
829
+ logprob: import_v42.z.number()
830
+ })
831
+ )
832
+ })
798
833
  ).nullish()
799
834
  }).nullish(),
800
835
  finish_reason: import_v42.z.string().nullish(),
@@ -1231,7 +1266,7 @@ var OpenAIChatLanguageModel = class {
1231
1266
  };
1232
1267
  }
1233
1268
  async doGenerate(options) {
1234
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1269
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
1235
1270
  const { args: body, warnings } = await this.getArgs(options);
1236
1271
  const {
1237
1272
  responseHeaders,
@@ -1263,6 +1298,11 @@ var OpenAIChatLanguageModel = class {
1263
1298
  if (text != null && text.length > 0) {
1264
1299
  content.push({ type: "text", text });
1265
1300
  }
1301
+ const refusal = choice.message.refusal;
1302
+ const hasRefusal = refusal != null && refusal.length > 0;
1303
+ if (hasRefusal) {
1304
+ content.push({ type: "text", text: refusal });
1305
+ }
1266
1306
  for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
1267
1307
  content.push({
1268
1308
  type: "tool-call",
@@ -1289,14 +1329,22 @@ var OpenAIChatLanguageModel = class {
1289
1329
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
1290
1330
  providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
1291
1331
  }
1292
- if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
1293
- providerMetadata.openai.logprobs = choice.logprobs.content;
1332
+ const contentLogprobs = (_g = choice.logprobs) == null ? void 0 : _g.content;
1333
+ const refusalLogprobs = (_h = choice.logprobs) == null ? void 0 : _h.refusal;
1334
+ if (contentLogprobs != null || refusalLogprobs != null) {
1335
+ providerMetadata.openai.logprobs = [
1336
+ ...contentLogprobs != null ? contentLogprobs : [],
1337
+ ...refusalLogprobs != null ? refusalLogprobs : []
1338
+ ];
1294
1339
  }
1295
1340
  return {
1296
1341
  content,
1297
1342
  finishReason: {
1298
- unified: mapOpenAIFinishReason(choice.finish_reason),
1299
- raw: (_h = choice.finish_reason) != null ? _h : void 0
1343
+ unified: mapOpenAIFinishReason({
1344
+ finishReason: choice.finish_reason,
1345
+ hasRefusal
1346
+ }),
1347
+ raw: (_i = choice.finish_reason) != null ? _i : void 0
1300
1348
  },
1301
1349
  usage: convertOpenAIChatUsage(response.usage),
1302
1350
  request: { body },
@@ -1349,6 +1397,10 @@ var OpenAIChatLanguageModel = class {
1349
1397
  let usage = void 0;
1350
1398
  let metadataExtracted = false;
1351
1399
  let isActiveText = false;
1400
+ let hasRefusal = false;
1401
+ let rawFinishReason = void 0;
1402
+ let hasLogprobs = false;
1403
+ const streamedLogprobs = [];
1352
1404
  const providerMetadata = { openai: {} };
1353
1405
  const result = {
1354
1406
  stream: checkedResponse.pipeThrough(
@@ -1361,18 +1413,20 @@ var OpenAIChatLanguageModel = class {
1361
1413
  controller.enqueue({ type: "stream-start", warnings });
1362
1414
  },
1363
1415
  transform(chunk, controller) {
1364
- var _a2, _b, _c, _d, _e;
1416
+ var _a2, _b, _c, _d;
1365
1417
  if (options.includeRawChunks) {
1366
1418
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1367
1419
  }
1368
1420
  if (!chunk.success) {
1369
1421
  finishReason = { unified: "error", raw: void 0 };
1422
+ rawFinishReason = void 0;
1370
1423
  controller.enqueue({ type: "error", error: chunk.error });
1371
1424
  return;
1372
1425
  }
1373
1426
  const value = chunk.value;
1374
1427
  if ("error" in value) {
1375
1428
  finishReason = { unified: "error", raw: void 0 };
1429
+ rawFinishReason = void 0;
1376
1430
  controller.enqueue({ type: "error", error: value.error });
1377
1431
  return;
1378
1432
  }
@@ -1397,19 +1451,35 @@ var OpenAIChatLanguageModel = class {
1397
1451
  }
1398
1452
  const choice = value.choices[0];
1399
1453
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1400
- finishReason = {
1401
- unified: mapOpenAIFinishReason(choice.finish_reason),
1402
- raw: choice.finish_reason
1403
- };
1454
+ rawFinishReason = choice.finish_reason;
1404
1455
  }
1405
- if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
1406
- providerMetadata.openai.logprobs = choice.logprobs.content;
1456
+ if ((choice == null ? void 0 : choice.logprobs) != null) {
1457
+ const contentLogprobs = choice.logprobs.content;
1458
+ const refusalLogprobs = choice.logprobs.refusal;
1459
+ if (contentLogprobs != null || refusalLogprobs != null) {
1460
+ hasLogprobs = true;
1461
+ streamedLogprobs.push(
1462
+ ...contentLogprobs != null ? contentLogprobs : [],
1463
+ ...refusalLogprobs != null ? refusalLogprobs : []
1464
+ );
1465
+ }
1407
1466
  }
1408
1467
  if ((choice == null ? void 0 : choice.delta) == null) {
1409
1468
  return;
1410
1469
  }
1411
1470
  const delta = choice.delta;
1412
- if (delta.content != null) {
1471
+ const textDeltas = [];
1472
+ if (delta.content != null && delta.content.length > 0) {
1473
+ textDeltas.push(delta.content);
1474
+ }
1475
+ if (delta.refusal != null && delta.refusal.length > 0) {
1476
+ hasRefusal = true;
1477
+ textDeltas.push(delta.refusal);
1478
+ }
1479
+ if (textDeltas.length === 0 && delta.content === "") {
1480
+ textDeltas.push(delta.content);
1481
+ }
1482
+ for (const textDelta of textDeltas) {
1413
1483
  if (!isActiveText) {
1414
1484
  controller.enqueue({ type: "text-start", id: "0" });
1415
1485
  isActiveText = true;
@@ -1417,7 +1487,7 @@ var OpenAIChatLanguageModel = class {
1417
1487
  controller.enqueue({
1418
1488
  type: "text-delta",
1419
1489
  id: "0",
1420
- delta: delta.content
1490
+ delta: textDelta
1421
1491
  });
1422
1492
  }
1423
1493
  if (delta.tool_calls != null) {
@@ -1442,6 +1512,18 @@ var OpenAIChatLanguageModel = class {
1442
1512
  controller.enqueue({ type: "text-end", id: "0" });
1443
1513
  }
1444
1514
  toolCallTracker.flush();
1515
+ if (rawFinishReason != null) {
1516
+ finishReason = {
1517
+ unified: mapOpenAIFinishReason({
1518
+ finishReason: rawFinishReason,
1519
+ hasRefusal
1520
+ }),
1521
+ raw: rawFinishReason
1522
+ };
1523
+ }
1524
+ if (hasLogprobs) {
1525
+ providerMetadata.openai.logprobs = streamedLogprobs;
1526
+ }
1445
1527
  controller.enqueue({
1446
1528
  type: "finish",
1447
1529
  finishReason,
@@ -1463,7 +1545,7 @@ function isOpenAIChatOutputChunk(chunk) {
1463
1545
  }
1464
1546
  return chunk.choices.some((choice) => {
1465
1547
  const delta = choice.delta;
1466
- return (delta == null ? void 0 : delta.content) != null && delta.content.length > 0 || (delta == null ? void 0 : delta.tool_calls) != null && delta.tool_calls.length > 0 || (delta == null ? void 0 : delta.annotations) != null && delta.annotations.length > 0;
1548
+ return (delta == null ? void 0 : delta.content) != null && delta.content.length > 0 || (delta == null ? void 0 : delta.refusal) != null && delta.refusal.length > 0 || (delta == null ? void 0 : delta.tool_calls) != null && delta.tool_calls.length > 0 || (delta == null ? void 0 : delta.annotations) != null && delta.annotations.length > 0;
1467
1549
  });
1468
1550
  }
1469
1551
 
@@ -2065,6 +2147,7 @@ var OpenAIEmbeddingModel = class {
2065
2147
  };
2066
2148
 
2067
2149
  // src/image/openai-image-model.ts
2150
+ var import_provider7 = require("@ai-sdk/provider");
2068
2151
  var import_provider_utils14 = require("@ai-sdk/provider-utils");
2069
2152
 
2070
2153
  // src/image/openai-image-api.ts
@@ -2107,6 +2190,8 @@ var modelMaxImagesPerCall = {
2107
2190
  "gpt-image-1-mini": 10,
2108
2191
  "gpt-image-1.5": 10,
2109
2192
  "gpt-image-2": 10,
2193
+ "gpt-image-2.6-flare": 10,
2194
+ "gpt-image-2.6-sunburst": 10,
2110
2195
  "gpt-image-2.5-flare": 10,
2111
2196
  "gpt-image-2.5-flare-2026-09-08": 10,
2112
2197
  "gpt-image-2.5-sunburst": 10,
@@ -2142,6 +2227,11 @@ var baseImageModelOptionsObject = () => import_v49.z.object({
2142
2227
  * Format in which the generated image(s) are returned.
2143
2228
  */
2144
2229
  outputFormat: import_v49.z.enum(["png", "jpeg", "webp"]).optional(),
2230
+ /**
2231
+ * How much detail the model puts into the image. Supported by GPT Image
2232
+ * 2.6 models. The API defaults to `high`.
2233
+ */
2234
+ complexity: import_v49.z.enum(["low", "medium", "high"]).optional(),
2145
2235
  /**
2146
2236
  * Compression level (0-100) for the generated image(s). Applies to the
2147
2237
  * `jpeg` and `webp` output formats.
@@ -2151,7 +2241,13 @@ var baseImageModelOptionsObject = () => import_v49.z.object({
2151
2241
  * A unique identifier representing your end-user, which can help OpenAI
2152
2242
  * to monitor and detect abuse.
2153
2243
  */
2154
- user: import_v49.z.string().optional()
2244
+ user: import_v49.z.string().optional(),
2245
+ /**
2246
+ * A stable identifier used to help detect users of your application that
2247
+ * may be violating OpenAI's usage policies. Should be a hashed username
2248
+ * or email address.
2249
+ */
2250
+ safetyIdentifier: import_v49.z.string().max(128).optional()
2155
2251
  });
2156
2252
  var openaiImageModelOptions = (0, import_provider_utils13.lazySchema)(
2157
2253
  () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject())
@@ -2165,6 +2261,22 @@ var openaiImageModelGenerationOptions = (0, import_provider_utils13.lazySchema)(
2165
2261
  * looking images.
2166
2262
  */
2167
2263
  style: import_v49.z.enum(["vivid", "natural"]).optional(),
2264
+ /**
2265
+ * Format in which the generated image(s) are returned. `gif` produces
2266
+ * an animated GIF and is supported by GPT Image 2.6 models.
2267
+ */
2268
+ outputFormat: import_v49.z.enum(["png", "jpeg", "webp", "gif"]).optional(),
2269
+ /**
2270
+ * Number of frames (2-64) of an animated GIF. Only applies to the `gif`
2271
+ * output format. The API defaults to 9.
2272
+ */
2273
+ frameCount: import_v49.z.number().int().min(2).max(64).optional(),
2274
+ /**
2275
+ * Duration of each frame in milliseconds (20-2000) of an animated GIF.
2276
+ * The API rounds it to the nearest 10 ms. Only applies to the `gif`
2277
+ * output format. The API defaults to 200.
2278
+ */
2279
+ frameDurationMs: import_v49.z.number().int().min(20).max(2e3).optional(),
2168
2280
  /**
2169
2281
  * Content moderation level for the generated image(s). `low` applies
2170
2282
  * less restrictive filtering.
@@ -2179,7 +2291,14 @@ var openaiImageModelEditOptions = (0, import_provider_utils13.lazySchema)(
2179
2291
  /**
2180
2292
  * Fidelity of the output image(s) to the input image(s).
2181
2293
  */
2182
- inputFidelity: import_v49.z.enum(["high", "low"]).optional()
2294
+ inputFidelity: import_v49.z.enum(["high", "low"]).optional(),
2295
+ /**
2296
+ * A transparent PNG overlaid on the first input image to mark up the
2297
+ * regions to change, as an HTTPS URL or a base64 data URL. It must match
2298
+ * the dimensions of the first image. Supported by GPT Image 2.5 and 2.6
2299
+ * models. Cannot be combined with a `mask`.
2300
+ */
2301
+ markup: import_v49.z.string().optional()
2183
2302
  })
2184
2303
  )
2185
2304
  );
@@ -2228,6 +2347,12 @@ var OpenAIImageModel = class {
2228
2347
  providerOptions,
2229
2348
  schema: openaiImageModelEditOptions
2230
2349
  })) != null ? _d : {};
2350
+ if (mask != null && openaiOptions2.markup != null) {
2351
+ throw new import_provider7.InvalidArgumentError({
2352
+ argument: "providerOptions.openai.markup",
2353
+ message: "`markup` cannot be combined with `mask`."
2354
+ });
2355
+ }
2231
2356
  const { value: response2, responseHeaders: responseHeaders2 } = await (0, import_provider_utils14.postFormDataToApi)({
2232
2357
  url: this.config.url({
2233
2358
  path: "/images/edits",
@@ -2252,14 +2377,17 @@ var OpenAIImageModel = class {
2252
2377
  )
2253
2378
  ),
2254
2379
  mask: mask != null ? await fileToBlob(mask) : void 0,
2380
+ markup: openaiOptions2.markup != null ? await markupToBlob(openaiOptions2.markup) : void 0,
2255
2381
  n,
2256
2382
  size,
2257
2383
  quality: openaiOptions2.quality,
2258
2384
  background: openaiOptions2.background,
2259
2385
  output_format: openaiOptions2.outputFormat,
2260
2386
  output_compression: openaiOptions2.outputCompression,
2387
+ complexity: openaiOptions2.complexity,
2261
2388
  input_fidelity: openaiOptions2.inputFidelity,
2262
- user: openaiOptions2.user
2389
+ user: openaiOptions2.user,
2390
+ safety_identifier: openaiOptions2.safetyIdentifier
2263
2391
  }),
2264
2392
  failedResponseHandler: openaiFailedResponseHandler,
2265
2393
  successfulResponseHandler: (0, import_provider_utils14.createJsonResponseHandler)(
@@ -2325,7 +2453,11 @@ var OpenAIImageModel = class {
2325
2453
  moderation: openaiOptions.moderation,
2326
2454
  output_format: openaiOptions.outputFormat,
2327
2455
  output_compression: openaiOptions.outputCompression,
2456
+ complexity: openaiOptions.complexity,
2457
+ frame_count: openaiOptions.frameCount,
2458
+ frame_duration_ms: openaiOptions.frameDurationMs,
2328
2459
  user: openaiOptions.user,
2460
+ safety_identifier: openaiOptions.safetyIdentifier,
2329
2461
  ...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
2330
2462
  },
2331
2463
  failedResponseHandler: openaiFailedResponseHandler,
@@ -2388,6 +2520,21 @@ function distributeTokenDetails(details, index, total) {
2388
2520
  }
2389
2521
  return result;
2390
2522
  }
2523
+ async function markupToBlob(markup) {
2524
+ const dataUrl = /^data:([^;,]*)(;base64)?,(.*)$/s.exec(markup);
2525
+ if (dataUrl == null) {
2526
+ return (0, import_provider_utils14.downloadBlob)(markup);
2527
+ }
2528
+ if (dataUrl[2] == null) {
2529
+ throw new import_provider7.InvalidArgumentError({
2530
+ argument: "providerOptions.openai.markup",
2531
+ message: "`markup` data URLs must be base64 encoded."
2532
+ });
2533
+ }
2534
+ return new Blob([(0, import_provider_utils14.convertBase64ToUint8Array)(dataUrl[3])], {
2535
+ type: dataUrl[1] || "image/png"
2536
+ });
2537
+ }
2391
2538
  async function fileToBlob(file) {
2392
2539
  if (!file) return void 0;
2393
2540
  if (file.type === "url") {
@@ -3043,7 +3190,7 @@ var openaiTools = {
3043
3190
  };
3044
3191
 
3045
3192
  // src/responses/openai-responses-language-model.ts
3046
- var import_provider10 = require("@ai-sdk/provider");
3193
+ var import_provider11 = require("@ai-sdk/provider");
3047
3194
  var import_provider_utils31 = require("@ai-sdk/provider-utils");
3048
3195
 
3049
3196
  // src/responses/convert-openai-responses-usage.ts
@@ -3087,7 +3234,7 @@ function convertOpenAIResponsesUsage(usage) {
3087
3234
  }
3088
3235
 
3089
3236
  // src/responses/convert-to-openai-responses-input.ts
3090
- var import_provider8 = require("@ai-sdk/provider");
3237
+ var import_provider9 = require("@ai-sdk/provider");
3091
3238
  var import_provider_utils28 = require("@ai-sdk/provider-utils");
3092
3239
  var import_v422 = require("zod/v4");
3093
3240
 
@@ -3395,7 +3542,7 @@ var openaiResponsesSystemMessageOptionsSchema = (0, import_provider_utils26.lazy
3395
3542
  );
3396
3543
 
3397
3544
  // src/responses/expand-parallel-tool-call.ts
3398
- var import_provider7 = require("@ai-sdk/provider");
3545
+ var import_provider8 = require("@ai-sdk/provider");
3399
3546
  var import_provider_utils27 = require("@ai-sdk/provider-utils");
3400
3547
  var parallelToolName = "parallel";
3401
3548
  var recipientNamePrefix = "functions.";
@@ -3405,7 +3552,7 @@ function getParallelToolCallMetadata({
3405
3552
  }) {
3406
3553
  var _a2;
3407
3554
  const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
3408
- if (!(0, import_provider7.isJSONObject)(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
3555
+ if (!(0, import_provider8.isJSONObject)(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
3409
3556
  return void 0;
3410
3557
  }
3411
3558
  return metadata;
@@ -3426,7 +3573,7 @@ async function expandParallelToolCall({
3426
3573
  return void 0;
3427
3574
  }
3428
3575
  const parsedInput = await (0, import_provider_utils27.safeParseJSON)({ text: toolCall.input });
3429
- if (!parsedInput.success || !(0, import_provider7.isJSONObject)(parsedInput.value)) {
3576
+ if (!parsedInput.success || !(0, import_provider8.isJSONObject)(parsedInput.value)) {
3430
3577
  return void 0;
3431
3578
  }
3432
3579
  const toolUses = parsedInput.value.tool_uses;
@@ -3436,12 +3583,12 @@ async function expandParallelToolCall({
3436
3583
  const availableToolNames = new Set(tools.map((tool) => tool.name));
3437
3584
  const expandedToolCalls = [];
3438
3585
  for (const [index, toolUse] of toolUses.entries()) {
3439
- if (!(0, import_provider7.isJSONObject)(toolUse)) {
3586
+ if (!(0, import_provider8.isJSONObject)(toolUse)) {
3440
3587
  return void 0;
3441
3588
  }
3442
3589
  const recipientName = toolUse.recipient_name;
3443
3590
  const parameters = toolUse.parameters;
3444
- if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !(0, import_provider7.isJSONObject)(parameters)) {
3591
+ if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !(0, import_provider8.isJSONObject)(parameters)) {
3445
3592
  return void 0;
3446
3593
  }
3447
3594
  const toolName = recipientName.slice(recipientNamePrefix.length);
@@ -3769,7 +3916,7 @@ async function convertToOpenAIResponsesInput({
3769
3916
  if (effort != null) {
3770
3917
  const unsupportedReason = content !== "" ? "Message-level reasoningEffortUpdate requires empty system message content." : configurationUpdateUnsupportedReason;
3771
3918
  if (unsupportedReason != null) {
3772
- throw new import_provider8.UnsupportedFunctionalityError({
3919
+ throw new import_provider9.UnsupportedFunctionalityError({
3773
3920
  functionality: "Message-level reasoningEffortUpdate",
3774
3921
  message: unsupportedReason
3775
3922
  });
@@ -3881,7 +4028,7 @@ async function convertToOpenAIResponsesInput({
3881
4028
  };
3882
4029
  }
3883
4030
  if (mediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
3884
- throw new import_provider8.UnsupportedFunctionalityError({
4031
+ throw new import_provider9.UnsupportedFunctionalityError({
3885
4032
  functionality: `file part media type ${mediaType}`
3886
4033
  });
3887
4034
  }
@@ -4528,12 +4675,14 @@ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils28.
4528
4675
  // src/responses/map-openai-responses-finish-reason.ts
4529
4676
  function mapOpenAIResponseFinishReason({
4530
4677
  finishReason,
4531
- hasFunctionCall
4678
+ hasFunctionCall,
4679
+ hasRefusal = false
4532
4680
  }) {
4533
4681
  switch (finishReason) {
4534
4682
  case void 0:
4535
4683
  case null:
4536
- return hasFunctionCall ? "tool-calls" : "stop";
4684
+ if (hasFunctionCall) return "tool-calls";
4685
+ return hasRefusal ? "content-filter" : "stop";
4537
4686
  case "max_output_tokens":
4538
4687
  return "length";
4539
4688
  case "content_filter":
@@ -4640,6 +4789,8 @@ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
4640
4789
  "response.output_item.done",
4641
4790
  "response.output_text.annotation.added",
4642
4791
  "response.output_text.delta",
4792
+ "response.refusal.delta",
4793
+ "response.refusal.done",
4643
4794
  "response.reasoning_summary_part.added",
4644
4795
  "response.reasoning_summary_part.done",
4645
4796
  "response.reasoning_summary_text.delta"
@@ -4696,6 +4847,20 @@ var openaiResponsesChunkSchema = (0, import_provider_utils29.lazySchema)(
4696
4847
  })
4697
4848
  ).nullish()
4698
4849
  }),
4850
+ import_v423.z.object({
4851
+ type: import_v423.z.literal("response.refusal.delta"),
4852
+ item_id: import_v423.z.string(),
4853
+ output_index: import_v423.z.number().nullish(),
4854
+ content_index: import_v423.z.number().nullish(),
4855
+ delta: import_v423.z.string()
4856
+ }),
4857
+ import_v423.z.object({
4858
+ type: import_v423.z.literal("response.refusal.done"),
4859
+ item_id: import_v423.z.string(),
4860
+ output_index: import_v423.z.number().nullish(),
4861
+ content_index: import_v423.z.number().nullish(),
4862
+ refusal: import_v423.z.string()
4863
+ }),
4699
4864
  import_v423.z.object({
4700
4865
  type: import_v423.z.enum(["response.completed", "response.incomplete"]),
4701
4866
  response: import_v423.z.object({
@@ -5221,53 +5386,60 @@ var openaiResponsesResponseSchema = (0, import_provider_utils29.lazySchema)(
5221
5386
  role: import_v423.z.literal("assistant"),
5222
5387
  id: import_v423.z.string(),
5223
5388
  phase: import_v423.z.enum(["commentary", "final_answer"]).nullish(),
5389
+ // the API returns either text or a refusal as content parts:
5224
5390
  content: import_v423.z.array(
5225
- import_v423.z.object({
5226
- type: import_v423.z.literal("output_text"),
5227
- text: import_v423.z.string(),
5228
- logprobs: import_v423.z.array(
5229
- import_v423.z.object({
5230
- token: import_v423.z.string(),
5231
- logprob: import_v423.z.number(),
5232
- top_logprobs: import_v423.z.array(
5233
- import_v423.z.object({
5234
- token: import_v423.z.string(),
5235
- logprob: import_v423.z.number()
5236
- })
5237
- )
5238
- })
5239
- ).nullish(),
5240
- annotations: import_v423.z.array(
5241
- import_v423.z.discriminatedUnion("type", [
5242
- import_v423.z.object({
5243
- type: import_v423.z.literal("url_citation"),
5244
- start_index: import_v423.z.number(),
5245
- end_index: import_v423.z.number(),
5246
- url: import_v423.z.string(),
5247
- title: import_v423.z.string()
5248
- }),
5249
- import_v423.z.object({
5250
- type: import_v423.z.literal("file_citation"),
5251
- file_id: import_v423.z.string(),
5252
- filename: import_v423.z.string(),
5253
- index: import_v423.z.number()
5254
- }),
5255
- import_v423.z.object({
5256
- type: import_v423.z.literal("container_file_citation"),
5257
- container_id: import_v423.z.string(),
5258
- file_id: import_v423.z.string(),
5259
- filename: import_v423.z.string(),
5260
- start_index: import_v423.z.number(),
5261
- end_index: import_v423.z.number()
5262
- }),
5391
+ import_v423.z.discriminatedUnion("type", [
5392
+ import_v423.z.object({
5393
+ type: import_v423.z.literal("output_text"),
5394
+ text: import_v423.z.string(),
5395
+ logprobs: import_v423.z.array(
5263
5396
  import_v423.z.object({
5264
- type: import_v423.z.literal("file_path"),
5265
- file_id: import_v423.z.string(),
5266
- index: import_v423.z.number()
5397
+ token: import_v423.z.string(),
5398
+ logprob: import_v423.z.number(),
5399
+ top_logprobs: import_v423.z.array(
5400
+ import_v423.z.object({
5401
+ token: import_v423.z.string(),
5402
+ logprob: import_v423.z.number()
5403
+ })
5404
+ )
5267
5405
  })
5268
- ])
5269
- )
5270
- })
5406
+ ).nullish(),
5407
+ annotations: import_v423.z.array(
5408
+ import_v423.z.discriminatedUnion("type", [
5409
+ import_v423.z.object({
5410
+ type: import_v423.z.literal("url_citation"),
5411
+ start_index: import_v423.z.number(),
5412
+ end_index: import_v423.z.number(),
5413
+ url: import_v423.z.string(),
5414
+ title: import_v423.z.string()
5415
+ }),
5416
+ import_v423.z.object({
5417
+ type: import_v423.z.literal("file_citation"),
5418
+ file_id: import_v423.z.string(),
5419
+ filename: import_v423.z.string(),
5420
+ index: import_v423.z.number()
5421
+ }),
5422
+ import_v423.z.object({
5423
+ type: import_v423.z.literal("container_file_citation"),
5424
+ container_id: import_v423.z.string(),
5425
+ file_id: import_v423.z.string(),
5426
+ filename: import_v423.z.string(),
5427
+ start_index: import_v423.z.number(),
5428
+ end_index: import_v423.z.number()
5429
+ }),
5430
+ import_v423.z.object({
5431
+ type: import_v423.z.literal("file_path"),
5432
+ file_id: import_v423.z.string(),
5433
+ index: import_v423.z.number()
5434
+ })
5435
+ ])
5436
+ )
5437
+ }),
5438
+ import_v423.z.object({
5439
+ type: import_v423.z.literal("refusal"),
5440
+ refusal: import_v423.z.string()
5441
+ })
5442
+ ])
5271
5443
  )
5272
5444
  }),
5273
5445
  import_v423.z.object({
@@ -5496,7 +5668,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils29.lazySchema)(
5496
5668
  );
5497
5669
 
5498
5670
  // src/responses/openai-responses-prepare-tools.ts
5499
- var import_provider9 = require("@ai-sdk/provider");
5671
+ var import_provider10 = require("@ai-sdk/provider");
5500
5672
  var import_provider_utils30 = require("@ai-sdk/provider-utils");
5501
5673
  async function prepareResponsesTools({
5502
5674
  tools,
@@ -5559,7 +5731,7 @@ async function prepareResponsesTools({
5559
5731
  namespaceTools.set(namespace.name, namespaceTool);
5560
5732
  openaiTools2.push(namespaceTool);
5561
5733
  } else if (namespaceTool.description !== namespace.description) {
5562
- throw new import_provider9.UnsupportedFunctionalityError({
5734
+ throw new import_provider10.UnsupportedFunctionalityError({
5563
5735
  functionality: `conflicting descriptions for OpenAI tool namespace "${namespace.name}"`
5564
5736
  });
5565
5737
  }
@@ -5813,7 +5985,7 @@ async function prepareResponsesTools({
5813
5985
  allowedToolEntries.push(resolution.entry);
5814
5986
  }
5815
5987
  if (allowedToolEntries.length === 0) {
5816
- throw new import_provider9.UnsupportedFunctionalityError({
5988
+ throw new import_provider10.UnsupportedFunctionalityError({
5817
5989
  functionality: `allowedTools with only tools that cannot be allow-listed (${droppedToolNames.join(
5818
5990
  ", "
5819
5991
  )})`
@@ -5848,7 +6020,7 @@ async function prepareResponsesTools({
5848
6020
  }
5849
6021
  default: {
5850
6022
  const _exhaustiveCheck = type;
5851
- throw new import_provider9.UnsupportedFunctionalityError({
6023
+ throw new import_provider10.UnsupportedFunctionalityError({
5852
6024
  functionality: `tool choice type: ${_exhaustiveCheck}`
5853
6025
  });
5854
6026
  }
@@ -6156,7 +6328,7 @@ var OpenAIResponsesLanguageModel = class {
6156
6328
  }
6157
6329
  for (let i = 1; i < input.length; i++) {
6158
6330
  if (input[i - 1].type === "configuration_update" && input[i].type === "configuration_update") {
6159
- throw new import_provider10.UnsupportedFunctionalityError({
6331
+ throw new import_provider11.UnsupportedFunctionalityError({
6160
6332
  functionality: "Adjacent reasoning effort configuration updates"
6161
6333
  });
6162
6334
  }
@@ -6385,7 +6557,7 @@ var OpenAIResponsesLanguageModel = class {
6385
6557
  fetch: this.config.fetch
6386
6558
  });
6387
6559
  if (response.error) {
6388
- throw new import_provider10.APICallError({
6560
+ throw new import_provider11.APICallError({
6389
6561
  message: response.error.message,
6390
6562
  url,
6391
6563
  requestBodyValues: body,
@@ -6402,6 +6574,7 @@ var OpenAIResponsesLanguageModel = class {
6402
6574
  )) != null ? _b : [];
6403
6575
  let hasFunctionCall = false;
6404
6576
  const hostedToolSearchCallIds = [];
6577
+ let hasRefusal = false;
6405
6578
  for (const part of response.output) {
6406
6579
  switch (part.type) {
6407
6580
  case "reasoning": {
@@ -6535,6 +6708,20 @@ var OpenAIResponsesLanguageModel = class {
6535
6708
  }
6536
6709
  case "message": {
6537
6710
  for (const contentPart of part.content) {
6711
+ if (contentPart.type === "refusal") {
6712
+ hasRefusal = true;
6713
+ content.push({
6714
+ type: "text",
6715
+ text: contentPart.refusal,
6716
+ providerMetadata: {
6717
+ [providerOptionsName]: {
6718
+ itemId: part.id,
6719
+ ...part.phase != null && { phase: part.phase }
6720
+ }
6721
+ }
6722
+ });
6723
+ continue;
6724
+ }
6538
6725
  if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
6539
6726
  logprobs.push(contentPart.logprobs);
6540
6727
  }
@@ -6834,7 +7021,8 @@ var OpenAIResponsesLanguageModel = class {
6834
7021
  finishReason: {
6835
7022
  unified: mapOpenAIResponseFinishReason({
6836
7023
  finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
6837
- hasFunctionCall
7024
+ hasFunctionCall,
7025
+ hasRefusal
6838
7026
  }),
6839
7027
  raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
6840
7028
  },
@@ -6905,6 +7093,7 @@ var OpenAIResponsesLanguageModel = class {
6905
7093
  const ongoingAnnotations = [];
6906
7094
  let activeMessagePhase;
6907
7095
  let hasFunctionCall = false;
7096
+ let hasRefusal = false;
6908
7097
  const activeReasoning = {};
6909
7098
  let serviceTier;
6910
7099
  let reasoningContext;
@@ -7678,6 +7867,15 @@ var OpenAIResponsesLanguageModel = class {
7678
7867
  if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
7679
7868
  logprobs.push(value.logprobs);
7680
7869
  }
7870
+ } else if (isRefusalDeltaChunk(value)) {
7871
+ hasRefusal = true;
7872
+ controller.enqueue({
7873
+ type: "text-delta",
7874
+ id: value.item_id,
7875
+ delta: value.delta
7876
+ });
7877
+ } else if (isRefusalDoneChunk(value)) {
7878
+ hasRefusal = true;
7681
7879
  } else if (value.type === "response.reasoning_summary_part.added") {
7682
7880
  if (value.summary_index > 0) {
7683
7881
  const activeReasoningPart = activeReasoning[value.item_id];
@@ -7740,7 +7938,8 @@ var OpenAIResponsesLanguageModel = class {
7740
7938
  finishReason = {
7741
7939
  unified: mapOpenAIResponseFinishReason({
7742
7940
  finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7743
- hasFunctionCall
7941
+ hasFunctionCall,
7942
+ hasRefusal
7744
7943
  }),
7745
7944
  raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7746
7945
  };
@@ -7894,6 +8093,12 @@ var OpenAIResponsesLanguageModel = class {
7894
8093
  function isTextDeltaChunk(chunk) {
7895
8094
  return chunk.type === "response.output_text.delta";
7896
8095
  }
8096
+ function isRefusalDeltaChunk(chunk) {
8097
+ return chunk.type === "response.refusal.delta";
8098
+ }
8099
+ function isRefusalDoneChunk(chunk) {
8100
+ return chunk.type === "response.refusal.done";
8101
+ }
7897
8102
  function isOpenAIChatCompletionChunk(value) {
7898
8103
  const chunk = asRecord2(value);
7899
8104
  return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
@@ -7905,7 +8110,7 @@ function createOpenAIResponsesChatCompletionsMismatchError({
7905
8110
  requestBodyValues,
7906
8111
  responseHeaders
7907
8112
  }) {
7908
- return new import_provider10.APICallError({
8113
+ return new import_provider11.APICallError({
7909
8114
  message: "Received a Chat Completions stream while using the OpenAI Responses API. The default OpenAI provider model uses the Responses API. If your custom baseURL targets a Chat Completions-compatible endpoint, use openai.chat('model-id') or createOpenAI(...).chat('model-id') instead. You can also use @ai-sdk/openai-compatible for OpenAI-compatible providers.",
7910
8115
  url,
7911
8116
  requestBodyValues,
@@ -8373,7 +8578,7 @@ var OpenAITranscriptionModel = class {
8373
8578
  };
8374
8579
 
8375
8580
  // src/version.ts
8376
- var VERSION = true ? "3.0.136" : "0.0.0-test";
8581
+ var VERSION = true ? "3.0.138" : "0.0.0-test";
8377
8582
 
8378
8583
  // src/openai-provider.ts
8379
8584
  function createOpenAI(options = {}) {