@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.
@@ -698,10 +698,13 @@ function getResponseMetadata({
698
698
  }
699
699
 
700
700
  // src/chat/map-openai-finish-reason.ts
701
- function mapOpenAIFinishReason(finishReason) {
701
+ function mapOpenAIFinishReason({
702
+ finishReason,
703
+ hasRefusal = false
704
+ }) {
702
705
  switch (finishReason) {
703
706
  case "stop":
704
- return "stop";
707
+ return hasRefusal ? "content-filter" : "stop";
705
708
  case "length":
706
709
  return "length";
707
710
  case "content_filter":
@@ -728,6 +731,8 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazySchema)(
728
731
  message: import_v42.z.object({
729
732
  role: import_v42.z.literal("assistant").nullish(),
730
733
  content: import_v42.z.string().nullish(),
734
+ // set instead of `content` when the model refuses to answer:
735
+ refusal: import_v42.z.string().nullish(),
731
736
  audio: import_v42.z.object({
732
737
  transcript: import_v42.z.string().nullish()
733
738
  }).nullish(),
@@ -766,6 +771,20 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazySchema)(
766
771
  })
767
772
  )
768
773
  })
774
+ ).nullish(),
775
+ // logprobs of the refusal tokens (set instead of `content` when
776
+ // the model refuses to answer):
777
+ refusal: import_v42.z.array(
778
+ import_v42.z.object({
779
+ token: import_v42.z.string(),
780
+ logprob: import_v42.z.number(),
781
+ top_logprobs: import_v42.z.array(
782
+ import_v42.z.object({
783
+ token: import_v42.z.string(),
784
+ logprob: import_v42.z.number()
785
+ })
786
+ )
787
+ })
769
788
  ).nullish()
770
789
  }).nullish(),
771
790
  finish_reason: import_v42.z.string().nullish()
@@ -800,6 +819,8 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazySchema)(
800
819
  delta: import_v42.z.object({
801
820
  role: import_v42.z.enum(["assistant"]).nullish(),
802
821
  content: import_v42.z.string().nullish(),
822
+ // set instead of `content` when the model refuses to answer:
823
+ refusal: import_v42.z.string().nullish(),
803
824
  tool_calls: import_v42.z.array(
804
825
  import_v42.z.object({
805
826
  index: import_v42.z.number(),
@@ -835,6 +856,20 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazySchema)(
835
856
  })
836
857
  )
837
858
  })
859
+ ).nullish(),
860
+ // logprobs of the refusal tokens (set instead of `content` when
861
+ // the model refuses to answer):
862
+ refusal: import_v42.z.array(
863
+ import_v42.z.object({
864
+ token: import_v42.z.string(),
865
+ logprob: import_v42.z.number(),
866
+ top_logprobs: import_v42.z.array(
867
+ import_v42.z.object({
868
+ token: import_v42.z.string(),
869
+ logprob: import_v42.z.number()
870
+ })
871
+ )
872
+ })
838
873
  ).nullish()
839
874
  }).nullish(),
840
875
  finish_reason: import_v42.z.string().nullish(),
@@ -1271,7 +1306,7 @@ var OpenAIChatLanguageModel = class {
1271
1306
  };
1272
1307
  }
1273
1308
  async doGenerate(options) {
1274
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1309
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
1275
1310
  const { args: body, warnings } = await this.getArgs(options);
1276
1311
  const {
1277
1312
  responseHeaders,
@@ -1303,6 +1338,11 @@ var OpenAIChatLanguageModel = class {
1303
1338
  if (text != null && text.length > 0) {
1304
1339
  content.push({ type: "text", text });
1305
1340
  }
1341
+ const refusal = choice.message.refusal;
1342
+ const hasRefusal = refusal != null && refusal.length > 0;
1343
+ if (hasRefusal) {
1344
+ content.push({ type: "text", text: refusal });
1345
+ }
1306
1346
  for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
1307
1347
  content.push({
1308
1348
  type: "tool-call",
@@ -1329,14 +1369,22 @@ var OpenAIChatLanguageModel = class {
1329
1369
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
1330
1370
  providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
1331
1371
  }
1332
- if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
1333
- providerMetadata.openai.logprobs = choice.logprobs.content;
1372
+ const contentLogprobs = (_g = choice.logprobs) == null ? void 0 : _g.content;
1373
+ const refusalLogprobs = (_h = choice.logprobs) == null ? void 0 : _h.refusal;
1374
+ if (contentLogprobs != null || refusalLogprobs != null) {
1375
+ providerMetadata.openai.logprobs = [
1376
+ ...contentLogprobs != null ? contentLogprobs : [],
1377
+ ...refusalLogprobs != null ? refusalLogprobs : []
1378
+ ];
1334
1379
  }
1335
1380
  return {
1336
1381
  content,
1337
1382
  finishReason: {
1338
- unified: mapOpenAIFinishReason(choice.finish_reason),
1339
- raw: (_h = choice.finish_reason) != null ? _h : void 0
1383
+ unified: mapOpenAIFinishReason({
1384
+ finishReason: choice.finish_reason,
1385
+ hasRefusal
1386
+ }),
1387
+ raw: (_i = choice.finish_reason) != null ? _i : void 0
1340
1388
  },
1341
1389
  usage: convertOpenAIChatUsage(response.usage),
1342
1390
  request: { body },
@@ -1389,6 +1437,10 @@ var OpenAIChatLanguageModel = class {
1389
1437
  let usage = void 0;
1390
1438
  let metadataExtracted = false;
1391
1439
  let isActiveText = false;
1440
+ let hasRefusal = false;
1441
+ let rawFinishReason = void 0;
1442
+ let hasLogprobs = false;
1443
+ const streamedLogprobs = [];
1392
1444
  const providerMetadata = { openai: {} };
1393
1445
  const result = {
1394
1446
  stream: checkedResponse.pipeThrough(
@@ -1401,18 +1453,20 @@ var OpenAIChatLanguageModel = class {
1401
1453
  controller.enqueue({ type: "stream-start", warnings });
1402
1454
  },
1403
1455
  transform(chunk, controller) {
1404
- var _a2, _b, _c, _d, _e;
1456
+ var _a2, _b, _c, _d;
1405
1457
  if (options.includeRawChunks) {
1406
1458
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1407
1459
  }
1408
1460
  if (!chunk.success) {
1409
1461
  finishReason = { unified: "error", raw: void 0 };
1462
+ rawFinishReason = void 0;
1410
1463
  controller.enqueue({ type: "error", error: chunk.error });
1411
1464
  return;
1412
1465
  }
1413
1466
  const value = chunk.value;
1414
1467
  if ("error" in value) {
1415
1468
  finishReason = { unified: "error", raw: void 0 };
1469
+ rawFinishReason = void 0;
1416
1470
  controller.enqueue({ type: "error", error: value.error });
1417
1471
  return;
1418
1472
  }
@@ -1437,19 +1491,35 @@ var OpenAIChatLanguageModel = class {
1437
1491
  }
1438
1492
  const choice = value.choices[0];
1439
1493
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1440
- finishReason = {
1441
- unified: mapOpenAIFinishReason(choice.finish_reason),
1442
- raw: choice.finish_reason
1443
- };
1494
+ rawFinishReason = choice.finish_reason;
1444
1495
  }
1445
- if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
1446
- providerMetadata.openai.logprobs = choice.logprobs.content;
1496
+ if ((choice == null ? void 0 : choice.logprobs) != null) {
1497
+ const contentLogprobs = choice.logprobs.content;
1498
+ const refusalLogprobs = choice.logprobs.refusal;
1499
+ if (contentLogprobs != null || refusalLogprobs != null) {
1500
+ hasLogprobs = true;
1501
+ streamedLogprobs.push(
1502
+ ...contentLogprobs != null ? contentLogprobs : [],
1503
+ ...refusalLogprobs != null ? refusalLogprobs : []
1504
+ );
1505
+ }
1447
1506
  }
1448
1507
  if ((choice == null ? void 0 : choice.delta) == null) {
1449
1508
  return;
1450
1509
  }
1451
1510
  const delta = choice.delta;
1452
- if (delta.content != null) {
1511
+ const textDeltas = [];
1512
+ if (delta.content != null && delta.content.length > 0) {
1513
+ textDeltas.push(delta.content);
1514
+ }
1515
+ if (delta.refusal != null && delta.refusal.length > 0) {
1516
+ hasRefusal = true;
1517
+ textDeltas.push(delta.refusal);
1518
+ }
1519
+ if (textDeltas.length === 0 && delta.content === "") {
1520
+ textDeltas.push(delta.content);
1521
+ }
1522
+ for (const textDelta of textDeltas) {
1453
1523
  if (!isActiveText) {
1454
1524
  controller.enqueue({ type: "text-start", id: "0" });
1455
1525
  isActiveText = true;
@@ -1457,7 +1527,7 @@ var OpenAIChatLanguageModel = class {
1457
1527
  controller.enqueue({
1458
1528
  type: "text-delta",
1459
1529
  id: "0",
1460
- delta: delta.content
1530
+ delta: textDelta
1461
1531
  });
1462
1532
  }
1463
1533
  if (delta.tool_calls != null) {
@@ -1482,6 +1552,18 @@ var OpenAIChatLanguageModel = class {
1482
1552
  controller.enqueue({ type: "text-end", id: "0" });
1483
1553
  }
1484
1554
  toolCallTracker.flush();
1555
+ if (rawFinishReason != null) {
1556
+ finishReason = {
1557
+ unified: mapOpenAIFinishReason({
1558
+ finishReason: rawFinishReason,
1559
+ hasRefusal
1560
+ }),
1561
+ raw: rawFinishReason
1562
+ };
1563
+ }
1564
+ if (hasLogprobs) {
1565
+ providerMetadata.openai.logprobs = streamedLogprobs;
1566
+ }
1485
1567
  controller.enqueue({
1486
1568
  type: "finish",
1487
1569
  finishReason,
@@ -1503,7 +1585,7 @@ function isOpenAIChatOutputChunk(chunk) {
1503
1585
  }
1504
1586
  return chunk.choices.some((choice) => {
1505
1587
  const delta = choice.delta;
1506
- 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;
1588
+ 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;
1507
1589
  });
1508
1590
  }
1509
1591
 
@@ -2105,6 +2187,7 @@ var OpenAIEmbeddingModel = class {
2105
2187
  };
2106
2188
 
2107
2189
  // src/image/openai-image-model.ts
2190
+ var import_provider7 = require("@ai-sdk/provider");
2108
2191
  var import_provider_utils14 = require("@ai-sdk/provider-utils");
2109
2192
 
2110
2193
  // src/image/openai-image-api.ts
@@ -2147,6 +2230,8 @@ var modelMaxImagesPerCall = {
2147
2230
  "gpt-image-1-mini": 10,
2148
2231
  "gpt-image-1.5": 10,
2149
2232
  "gpt-image-2": 10,
2233
+ "gpt-image-2.6-flare": 10,
2234
+ "gpt-image-2.6-sunburst": 10,
2150
2235
  "gpt-image-2.5-flare": 10,
2151
2236
  "gpt-image-2.5-flare-2026-09-08": 10,
2152
2237
  "gpt-image-2.5-sunburst": 10,
@@ -2182,6 +2267,11 @@ var baseImageModelOptionsObject = () => import_v49.z.object({
2182
2267
  * Format in which the generated image(s) are returned.
2183
2268
  */
2184
2269
  outputFormat: import_v49.z.enum(["png", "jpeg", "webp"]).optional(),
2270
+ /**
2271
+ * How much detail the model puts into the image. Supported by GPT Image
2272
+ * 2.6 models. The API defaults to `high`.
2273
+ */
2274
+ complexity: import_v49.z.enum(["low", "medium", "high"]).optional(),
2185
2275
  /**
2186
2276
  * Compression level (0-100) for the generated image(s). Applies to the
2187
2277
  * `jpeg` and `webp` output formats.
@@ -2191,7 +2281,13 @@ var baseImageModelOptionsObject = () => import_v49.z.object({
2191
2281
  * A unique identifier representing your end-user, which can help OpenAI
2192
2282
  * to monitor and detect abuse.
2193
2283
  */
2194
- user: import_v49.z.string().optional()
2284
+ user: import_v49.z.string().optional(),
2285
+ /**
2286
+ * A stable identifier used to help detect users of your application that
2287
+ * may be violating OpenAI's usage policies. Should be a hashed username
2288
+ * or email address.
2289
+ */
2290
+ safetyIdentifier: import_v49.z.string().max(128).optional()
2195
2291
  });
2196
2292
  var openaiImageModelOptions = (0, import_provider_utils13.lazySchema)(
2197
2293
  () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject())
@@ -2205,6 +2301,22 @@ var openaiImageModelGenerationOptions = (0, import_provider_utils13.lazySchema)(
2205
2301
  * looking images.
2206
2302
  */
2207
2303
  style: import_v49.z.enum(["vivid", "natural"]).optional(),
2304
+ /**
2305
+ * Format in which the generated image(s) are returned. `gif` produces
2306
+ * an animated GIF and is supported by GPT Image 2.6 models.
2307
+ */
2308
+ outputFormat: import_v49.z.enum(["png", "jpeg", "webp", "gif"]).optional(),
2309
+ /**
2310
+ * Number of frames (2-64) of an animated GIF. Only applies to the `gif`
2311
+ * output format. The API defaults to 9.
2312
+ */
2313
+ frameCount: import_v49.z.number().int().min(2).max(64).optional(),
2314
+ /**
2315
+ * Duration of each frame in milliseconds (20-2000) of an animated GIF.
2316
+ * The API rounds it to the nearest 10 ms. Only applies to the `gif`
2317
+ * output format. The API defaults to 200.
2318
+ */
2319
+ frameDurationMs: import_v49.z.number().int().min(20).max(2e3).optional(),
2208
2320
  /**
2209
2321
  * Content moderation level for the generated image(s). `low` applies
2210
2322
  * less restrictive filtering.
@@ -2219,7 +2331,14 @@ var openaiImageModelEditOptions = (0, import_provider_utils13.lazySchema)(
2219
2331
  /**
2220
2332
  * Fidelity of the output image(s) to the input image(s).
2221
2333
  */
2222
- inputFidelity: import_v49.z.enum(["high", "low"]).optional()
2334
+ inputFidelity: import_v49.z.enum(["high", "low"]).optional(),
2335
+ /**
2336
+ * A transparent PNG overlaid on the first input image to mark up the
2337
+ * regions to change, as an HTTPS URL or a base64 data URL. It must match
2338
+ * the dimensions of the first image. Supported by GPT Image 2.5 and 2.6
2339
+ * models. Cannot be combined with a `mask`.
2340
+ */
2341
+ markup: import_v49.z.string().optional()
2223
2342
  })
2224
2343
  )
2225
2344
  );
@@ -2268,6 +2387,12 @@ var OpenAIImageModel = class {
2268
2387
  providerOptions,
2269
2388
  schema: openaiImageModelEditOptions
2270
2389
  })) != null ? _d : {};
2390
+ if (mask != null && openaiOptions2.markup != null) {
2391
+ throw new import_provider7.InvalidArgumentError({
2392
+ argument: "providerOptions.openai.markup",
2393
+ message: "`markup` cannot be combined with `mask`."
2394
+ });
2395
+ }
2271
2396
  const { value: response2, responseHeaders: responseHeaders2 } = await (0, import_provider_utils14.postFormDataToApi)({
2272
2397
  url: this.config.url({
2273
2398
  path: "/images/edits",
@@ -2292,14 +2417,17 @@ var OpenAIImageModel = class {
2292
2417
  )
2293
2418
  ),
2294
2419
  mask: mask != null ? await fileToBlob(mask) : void 0,
2420
+ markup: openaiOptions2.markup != null ? await markupToBlob(openaiOptions2.markup) : void 0,
2295
2421
  n,
2296
2422
  size,
2297
2423
  quality: openaiOptions2.quality,
2298
2424
  background: openaiOptions2.background,
2299
2425
  output_format: openaiOptions2.outputFormat,
2300
2426
  output_compression: openaiOptions2.outputCompression,
2427
+ complexity: openaiOptions2.complexity,
2301
2428
  input_fidelity: openaiOptions2.inputFidelity,
2302
- user: openaiOptions2.user
2429
+ user: openaiOptions2.user,
2430
+ safety_identifier: openaiOptions2.safetyIdentifier
2303
2431
  }),
2304
2432
  failedResponseHandler: openaiFailedResponseHandler,
2305
2433
  successfulResponseHandler: (0, import_provider_utils14.createJsonResponseHandler)(
@@ -2365,7 +2493,11 @@ var OpenAIImageModel = class {
2365
2493
  moderation: openaiOptions.moderation,
2366
2494
  output_format: openaiOptions.outputFormat,
2367
2495
  output_compression: openaiOptions.outputCompression,
2496
+ complexity: openaiOptions.complexity,
2497
+ frame_count: openaiOptions.frameCount,
2498
+ frame_duration_ms: openaiOptions.frameDurationMs,
2368
2499
  user: openaiOptions.user,
2500
+ safety_identifier: openaiOptions.safetyIdentifier,
2369
2501
  ...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
2370
2502
  },
2371
2503
  failedResponseHandler: openaiFailedResponseHandler,
@@ -2428,6 +2560,21 @@ function distributeTokenDetails(details, index, total) {
2428
2560
  }
2429
2561
  return result;
2430
2562
  }
2563
+ async function markupToBlob(markup) {
2564
+ const dataUrl = /^data:([^;,]*)(;base64)?,(.*)$/s.exec(markup);
2565
+ if (dataUrl == null) {
2566
+ return (0, import_provider_utils14.downloadBlob)(markup);
2567
+ }
2568
+ if (dataUrl[2] == null) {
2569
+ throw new import_provider7.InvalidArgumentError({
2570
+ argument: "providerOptions.openai.markup",
2571
+ message: "`markup` data URLs must be base64 encoded."
2572
+ });
2573
+ }
2574
+ return new Blob([(0, import_provider_utils14.convertBase64ToUint8Array)(dataUrl[3])], {
2575
+ type: dataUrl[1] || "image/png"
2576
+ });
2577
+ }
2431
2578
  async function fileToBlob(file) {
2432
2579
  if (!file) return void 0;
2433
2580
  if (file.type === "url") {
@@ -2808,7 +2955,7 @@ var OpenAISpeechModel = class {
2808
2955
  };
2809
2956
 
2810
2957
  // src/responses/openai-responses-language-model.ts
2811
- var import_provider10 = require("@ai-sdk/provider");
2958
+ var import_provider11 = require("@ai-sdk/provider");
2812
2959
  var import_provider_utils36 = require("@ai-sdk/provider-utils");
2813
2960
 
2814
2961
  // src/responses/convert-openai-responses-usage.ts
@@ -2852,7 +2999,7 @@ function convertOpenAIResponsesUsage(usage) {
2852
2999
  }
2853
3000
 
2854
3001
  // src/responses/convert-to-openai-responses-input.ts
2855
- var import_provider8 = require("@ai-sdk/provider");
3002
+ var import_provider9 = require("@ai-sdk/provider");
2856
3003
  var import_provider_utils27 = require("@ai-sdk/provider-utils");
2857
3004
  var import_v419 = require("zod/v4");
2858
3005
 
@@ -3417,7 +3564,7 @@ var webSearchToolFactory = (0, import_provider_utils25.createProviderToolFactory
3417
3564
  var webSearch = (args = {}) => webSearchToolFactory(args);
3418
3565
 
3419
3566
  // src/responses/expand-parallel-tool-call.ts
3420
- var import_provider7 = require("@ai-sdk/provider");
3567
+ var import_provider8 = require("@ai-sdk/provider");
3421
3568
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
3422
3569
  var parallelToolName = "parallel";
3423
3570
  var recipientNamePrefix = "functions.";
@@ -3427,7 +3574,7 @@ function getParallelToolCallMetadata({
3427
3574
  }) {
3428
3575
  var _a2;
3429
3576
  const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
3430
- 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) {
3577
+ 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) {
3431
3578
  return void 0;
3432
3579
  }
3433
3580
  return metadata;
@@ -3448,7 +3595,7 @@ async function expandParallelToolCall({
3448
3595
  return void 0;
3449
3596
  }
3450
3597
  const parsedInput = await (0, import_provider_utils26.safeParseJSON)({ text: toolCall.input });
3451
- if (!parsedInput.success || !(0, import_provider7.isJSONObject)(parsedInput.value)) {
3598
+ if (!parsedInput.success || !(0, import_provider8.isJSONObject)(parsedInput.value)) {
3452
3599
  return void 0;
3453
3600
  }
3454
3601
  const toolUses = parsedInput.value.tool_uses;
@@ -3458,12 +3605,12 @@ async function expandParallelToolCall({
3458
3605
  const availableToolNames = new Set(tools.map((tool) => tool.name));
3459
3606
  const expandedToolCalls = [];
3460
3607
  for (const [index, toolUse] of toolUses.entries()) {
3461
- if (!(0, import_provider7.isJSONObject)(toolUse)) {
3608
+ if (!(0, import_provider8.isJSONObject)(toolUse)) {
3462
3609
  return void 0;
3463
3610
  }
3464
3611
  const recipientName = toolUse.recipient_name;
3465
3612
  const parameters = toolUse.parameters;
3466
- if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !(0, import_provider7.isJSONObject)(parameters)) {
3613
+ if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !(0, import_provider8.isJSONObject)(parameters)) {
3467
3614
  return void 0;
3468
3615
  }
3469
3616
  const toolName = recipientName.slice(recipientNamePrefix.length);
@@ -3791,7 +3938,7 @@ async function convertToOpenAIResponsesInput({
3791
3938
  if (effort != null) {
3792
3939
  const unsupportedReason = content !== "" ? "Message-level reasoningEffortUpdate requires empty system message content." : configurationUpdateUnsupportedReason;
3793
3940
  if (unsupportedReason != null) {
3794
- throw new import_provider8.UnsupportedFunctionalityError({
3941
+ throw new import_provider9.UnsupportedFunctionalityError({
3795
3942
  functionality: "Message-level reasoningEffortUpdate",
3796
3943
  message: unsupportedReason
3797
3944
  });
@@ -3903,7 +4050,7 @@ async function convertToOpenAIResponsesInput({
3903
4050
  };
3904
4051
  }
3905
4052
  if (mediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
3906
- throw new import_provider8.UnsupportedFunctionalityError({
4053
+ throw new import_provider9.UnsupportedFunctionalityError({
3907
4054
  functionality: `file part media type ${mediaType}`
3908
4055
  });
3909
4056
  }
@@ -4550,12 +4697,14 @@ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils27.
4550
4697
  // src/responses/map-openai-responses-finish-reason.ts
4551
4698
  function mapOpenAIResponseFinishReason({
4552
4699
  finishReason,
4553
- hasFunctionCall
4700
+ hasFunctionCall,
4701
+ hasRefusal = false
4554
4702
  }) {
4555
4703
  switch (finishReason) {
4556
4704
  case void 0:
4557
4705
  case null:
4558
- return hasFunctionCall ? "tool-calls" : "stop";
4706
+ if (hasFunctionCall) return "tool-calls";
4707
+ return hasRefusal ? "content-filter" : "stop";
4559
4708
  case "max_output_tokens":
4560
4709
  return "length";
4561
4710
  case "content_filter":
@@ -4662,6 +4811,8 @@ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
4662
4811
  "response.output_item.done",
4663
4812
  "response.output_text.annotation.added",
4664
4813
  "response.output_text.delta",
4814
+ "response.refusal.delta",
4815
+ "response.refusal.done",
4665
4816
  "response.reasoning_summary_part.added",
4666
4817
  "response.reasoning_summary_part.done",
4667
4818
  "response.reasoning_summary_text.delta"
@@ -4718,6 +4869,20 @@ var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
4718
4869
  })
4719
4870
  ).nullish()
4720
4871
  }),
4872
+ import_v420.z.object({
4873
+ type: import_v420.z.literal("response.refusal.delta"),
4874
+ item_id: import_v420.z.string(),
4875
+ output_index: import_v420.z.number().nullish(),
4876
+ content_index: import_v420.z.number().nullish(),
4877
+ delta: import_v420.z.string()
4878
+ }),
4879
+ import_v420.z.object({
4880
+ type: import_v420.z.literal("response.refusal.done"),
4881
+ item_id: import_v420.z.string(),
4882
+ output_index: import_v420.z.number().nullish(),
4883
+ content_index: import_v420.z.number().nullish(),
4884
+ refusal: import_v420.z.string()
4885
+ }),
4721
4886
  import_v420.z.object({
4722
4887
  type: import_v420.z.enum(["response.completed", "response.incomplete"]),
4723
4888
  response: import_v420.z.object({
@@ -5243,53 +5408,60 @@ var openaiResponsesResponseSchema = (0, import_provider_utils28.lazySchema)(
5243
5408
  role: import_v420.z.literal("assistant"),
5244
5409
  id: import_v420.z.string(),
5245
5410
  phase: import_v420.z.enum(["commentary", "final_answer"]).nullish(),
5411
+ // the API returns either text or a refusal as content parts:
5246
5412
  content: import_v420.z.array(
5247
- import_v420.z.object({
5248
- type: import_v420.z.literal("output_text"),
5249
- text: import_v420.z.string(),
5250
- logprobs: import_v420.z.array(
5251
- import_v420.z.object({
5252
- token: import_v420.z.string(),
5253
- logprob: import_v420.z.number(),
5254
- top_logprobs: import_v420.z.array(
5255
- import_v420.z.object({
5256
- token: import_v420.z.string(),
5257
- logprob: import_v420.z.number()
5258
- })
5259
- )
5260
- })
5261
- ).nullish(),
5262
- annotations: import_v420.z.array(
5263
- import_v420.z.discriminatedUnion("type", [
5264
- import_v420.z.object({
5265
- type: import_v420.z.literal("url_citation"),
5266
- start_index: import_v420.z.number(),
5267
- end_index: import_v420.z.number(),
5268
- url: import_v420.z.string(),
5269
- title: import_v420.z.string()
5270
- }),
5271
- import_v420.z.object({
5272
- type: import_v420.z.literal("file_citation"),
5273
- file_id: import_v420.z.string(),
5274
- filename: import_v420.z.string(),
5275
- index: import_v420.z.number()
5276
- }),
5277
- import_v420.z.object({
5278
- type: import_v420.z.literal("container_file_citation"),
5279
- container_id: import_v420.z.string(),
5280
- file_id: import_v420.z.string(),
5281
- filename: import_v420.z.string(),
5282
- start_index: import_v420.z.number(),
5283
- end_index: import_v420.z.number()
5284
- }),
5413
+ import_v420.z.discriminatedUnion("type", [
5414
+ import_v420.z.object({
5415
+ type: import_v420.z.literal("output_text"),
5416
+ text: import_v420.z.string(),
5417
+ logprobs: import_v420.z.array(
5285
5418
  import_v420.z.object({
5286
- type: import_v420.z.literal("file_path"),
5287
- file_id: import_v420.z.string(),
5288
- index: import_v420.z.number()
5419
+ token: import_v420.z.string(),
5420
+ logprob: import_v420.z.number(),
5421
+ top_logprobs: import_v420.z.array(
5422
+ import_v420.z.object({
5423
+ token: import_v420.z.string(),
5424
+ logprob: import_v420.z.number()
5425
+ })
5426
+ )
5289
5427
  })
5290
- ])
5291
- )
5292
- })
5428
+ ).nullish(),
5429
+ annotations: import_v420.z.array(
5430
+ import_v420.z.discriminatedUnion("type", [
5431
+ import_v420.z.object({
5432
+ type: import_v420.z.literal("url_citation"),
5433
+ start_index: import_v420.z.number(),
5434
+ end_index: import_v420.z.number(),
5435
+ url: import_v420.z.string(),
5436
+ title: import_v420.z.string()
5437
+ }),
5438
+ import_v420.z.object({
5439
+ type: import_v420.z.literal("file_citation"),
5440
+ file_id: import_v420.z.string(),
5441
+ filename: import_v420.z.string(),
5442
+ index: import_v420.z.number()
5443
+ }),
5444
+ import_v420.z.object({
5445
+ type: import_v420.z.literal("container_file_citation"),
5446
+ container_id: import_v420.z.string(),
5447
+ file_id: import_v420.z.string(),
5448
+ filename: import_v420.z.string(),
5449
+ start_index: import_v420.z.number(),
5450
+ end_index: import_v420.z.number()
5451
+ }),
5452
+ import_v420.z.object({
5453
+ type: import_v420.z.literal("file_path"),
5454
+ file_id: import_v420.z.string(),
5455
+ index: import_v420.z.number()
5456
+ })
5457
+ ])
5458
+ )
5459
+ }),
5460
+ import_v420.z.object({
5461
+ type: import_v420.z.literal("refusal"),
5462
+ refusal: import_v420.z.string()
5463
+ })
5464
+ ])
5293
5465
  )
5294
5466
  }),
5295
5467
  import_v420.z.object({
@@ -5518,7 +5690,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils28.lazySchema)(
5518
5690
  );
5519
5691
 
5520
5692
  // src/responses/openai-responses-prepare-tools.ts
5521
- var import_provider9 = require("@ai-sdk/provider");
5693
+ var import_provider10 = require("@ai-sdk/provider");
5522
5694
  var import_provider_utils35 = require("@ai-sdk/provider-utils");
5523
5695
 
5524
5696
  // src/tool/code-interpreter.ts
@@ -5850,7 +6022,7 @@ async function prepareResponsesTools({
5850
6022
  namespaceTools.set(namespace.name, namespaceTool);
5851
6023
  openaiTools.push(namespaceTool);
5852
6024
  } else if (namespaceTool.description !== namespace.description) {
5853
- throw new import_provider9.UnsupportedFunctionalityError({
6025
+ throw new import_provider10.UnsupportedFunctionalityError({
5854
6026
  functionality: `conflicting descriptions for OpenAI tool namespace "${namespace.name}"`
5855
6027
  });
5856
6028
  }
@@ -6104,7 +6276,7 @@ async function prepareResponsesTools({
6104
6276
  allowedToolEntries.push(resolution.entry);
6105
6277
  }
6106
6278
  if (allowedToolEntries.length === 0) {
6107
- throw new import_provider9.UnsupportedFunctionalityError({
6279
+ throw new import_provider10.UnsupportedFunctionalityError({
6108
6280
  functionality: `allowedTools with only tools that cannot be allow-listed (${droppedToolNames.join(
6109
6281
  ", "
6110
6282
  )})`
@@ -6139,7 +6311,7 @@ async function prepareResponsesTools({
6139
6311
  }
6140
6312
  default: {
6141
6313
  const _exhaustiveCheck = type;
6142
- throw new import_provider9.UnsupportedFunctionalityError({
6314
+ throw new import_provider10.UnsupportedFunctionalityError({
6143
6315
  functionality: `tool choice type: ${_exhaustiveCheck}`
6144
6316
  });
6145
6317
  }
@@ -6447,7 +6619,7 @@ var OpenAIResponsesLanguageModel = class {
6447
6619
  }
6448
6620
  for (let i = 1; i < input.length; i++) {
6449
6621
  if (input[i - 1].type === "configuration_update" && input[i].type === "configuration_update") {
6450
- throw new import_provider10.UnsupportedFunctionalityError({
6622
+ throw new import_provider11.UnsupportedFunctionalityError({
6451
6623
  functionality: "Adjacent reasoning effort configuration updates"
6452
6624
  });
6453
6625
  }
@@ -6676,7 +6848,7 @@ var OpenAIResponsesLanguageModel = class {
6676
6848
  fetch: this.config.fetch
6677
6849
  });
6678
6850
  if (response.error) {
6679
- throw new import_provider10.APICallError({
6851
+ throw new import_provider11.APICallError({
6680
6852
  message: response.error.message,
6681
6853
  url,
6682
6854
  requestBodyValues: body,
@@ -6693,6 +6865,7 @@ var OpenAIResponsesLanguageModel = class {
6693
6865
  )) != null ? _b : [];
6694
6866
  let hasFunctionCall = false;
6695
6867
  const hostedToolSearchCallIds = [];
6868
+ let hasRefusal = false;
6696
6869
  for (const part of response.output) {
6697
6870
  switch (part.type) {
6698
6871
  case "reasoning": {
@@ -6826,6 +6999,20 @@ var OpenAIResponsesLanguageModel = class {
6826
6999
  }
6827
7000
  case "message": {
6828
7001
  for (const contentPart of part.content) {
7002
+ if (contentPart.type === "refusal") {
7003
+ hasRefusal = true;
7004
+ content.push({
7005
+ type: "text",
7006
+ text: contentPart.refusal,
7007
+ providerMetadata: {
7008
+ [providerOptionsName]: {
7009
+ itemId: part.id,
7010
+ ...part.phase != null && { phase: part.phase }
7011
+ }
7012
+ }
7013
+ });
7014
+ continue;
7015
+ }
6829
7016
  if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
6830
7017
  logprobs.push(contentPart.logprobs);
6831
7018
  }
@@ -7125,7 +7312,8 @@ var OpenAIResponsesLanguageModel = class {
7125
7312
  finishReason: {
7126
7313
  unified: mapOpenAIResponseFinishReason({
7127
7314
  finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
7128
- hasFunctionCall
7315
+ hasFunctionCall,
7316
+ hasRefusal
7129
7317
  }),
7130
7318
  raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
7131
7319
  },
@@ -7196,6 +7384,7 @@ var OpenAIResponsesLanguageModel = class {
7196
7384
  const ongoingAnnotations = [];
7197
7385
  let activeMessagePhase;
7198
7386
  let hasFunctionCall = false;
7387
+ let hasRefusal = false;
7199
7388
  const activeReasoning = {};
7200
7389
  let serviceTier;
7201
7390
  let reasoningContext;
@@ -7969,6 +8158,15 @@ var OpenAIResponsesLanguageModel = class {
7969
8158
  if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
7970
8159
  logprobs.push(value.logprobs);
7971
8160
  }
8161
+ } else if (isRefusalDeltaChunk(value)) {
8162
+ hasRefusal = true;
8163
+ controller.enqueue({
8164
+ type: "text-delta",
8165
+ id: value.item_id,
8166
+ delta: value.delta
8167
+ });
8168
+ } else if (isRefusalDoneChunk(value)) {
8169
+ hasRefusal = true;
7972
8170
  } else if (value.type === "response.reasoning_summary_part.added") {
7973
8171
  if (value.summary_index > 0) {
7974
8172
  const activeReasoningPart = activeReasoning[value.item_id];
@@ -8031,7 +8229,8 @@ var OpenAIResponsesLanguageModel = class {
8031
8229
  finishReason = {
8032
8230
  unified: mapOpenAIResponseFinishReason({
8033
8231
  finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
8034
- hasFunctionCall
8232
+ hasFunctionCall,
8233
+ hasRefusal
8035
8234
  }),
8036
8235
  raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
8037
8236
  };
@@ -8185,6 +8384,12 @@ var OpenAIResponsesLanguageModel = class {
8185
8384
  function isTextDeltaChunk(chunk) {
8186
8385
  return chunk.type === "response.output_text.delta";
8187
8386
  }
8387
+ function isRefusalDeltaChunk(chunk) {
8388
+ return chunk.type === "response.refusal.delta";
8389
+ }
8390
+ function isRefusalDoneChunk(chunk) {
8391
+ return chunk.type === "response.refusal.done";
8392
+ }
8188
8393
  function isOpenAIChatCompletionChunk(value) {
8189
8394
  const chunk = asRecord2(value);
8190
8395
  return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
@@ -8196,7 +8401,7 @@ function createOpenAIResponsesChatCompletionsMismatchError({
8196
8401
  requestBodyValues,
8197
8402
  responseHeaders
8198
8403
  }) {
8199
- return new import_provider10.APICallError({
8404
+ return new import_provider11.APICallError({
8200
8405
  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.",
8201
8406
  url,
8202
8407
  requestBodyValues,