@ai-sdk/openai 3.0.81 → 3.0.83

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.
@@ -64,7 +64,7 @@ __export(index_exports, {
64
64
  module.exports = __toCommonJS(index_exports);
65
65
 
66
66
  // src/chat/openai-chat-language-model.ts
67
- var import_provider3 = require("@ai-sdk/provider");
67
+ var import_provider4 = require("@ai-sdk/provider");
68
68
  var import_provider_utils5 = require("@ai-sdk/provider-utils");
69
69
 
70
70
  // src/openai-error.ts
@@ -91,7 +91,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
91
91
  const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
92
92
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") && !modelId.startsWith("gpt-5.4-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
93
93
  const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
94
- const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2") || modelId.startsWith("gpt-5.3") || modelId.startsWith("gpt-5.4") || modelId.startsWith("gpt-5.5");
94
+ const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2") || modelId.startsWith("gpt-5.3") || modelId.startsWith("gpt-5.4") || modelId.startsWith("gpt-5.5") || modelId.startsWith("gpt-5.6");
95
95
  const systemMessageMode = isReasoningModel ? "developer" : "system";
96
96
  return {
97
97
  supportsFlexProcessing,
@@ -102,6 +102,129 @@ function getOpenAILanguageModelCapabilities(modelId) {
102
102
  };
103
103
  }
104
104
 
105
+ // src/openai-stream-error.ts
106
+ var import_provider = require("@ai-sdk/provider");
107
+ async function throwIfOpenAIStreamErrorBeforeOutput({
108
+ stream,
109
+ getError,
110
+ isOutputChunk,
111
+ url,
112
+ requestBodyValues,
113
+ responseHeaders
114
+ }) {
115
+ const [streamForEarlyError, streamForConsumer] = stream.tee();
116
+ const reader = streamForEarlyError.getReader();
117
+ try {
118
+ while (true) {
119
+ const result = await reader.read();
120
+ if (result.done) {
121
+ return streamForConsumer;
122
+ }
123
+ const chunk = result.value;
124
+ if (!chunk.success) {
125
+ return streamForConsumer;
126
+ }
127
+ const errorFrame = getError(chunk.value);
128
+ if (errorFrame != null) {
129
+ streamForConsumer.cancel().catch(() => {
130
+ });
131
+ throw createOpenAIStreamError({
132
+ frame: errorFrame,
133
+ url,
134
+ requestBodyValues,
135
+ responseHeaders
136
+ });
137
+ }
138
+ if (isOutputChunk(chunk.value)) {
139
+ return streamForConsumer;
140
+ }
141
+ }
142
+ } finally {
143
+ reader.cancel().catch(() => {
144
+ });
145
+ reader.releaseLock();
146
+ }
147
+ }
148
+ function createOpenAIStreamError({
149
+ frame,
150
+ url,
151
+ requestBodyValues,
152
+ responseHeaders
153
+ }) {
154
+ var _a;
155
+ const streamError = parseStreamError(frame);
156
+ return new import_provider.APICallError({
157
+ message: (_a = streamError == null ? void 0 : streamError.message) != null ? _a : "OpenAI stream failed before any output was generated",
158
+ url,
159
+ requestBodyValues,
160
+ statusCode: streamError == null ? 500 : getStatusCode(streamError),
161
+ responseHeaders,
162
+ responseBody: JSON.stringify(frame),
163
+ data: frame
164
+ });
165
+ }
166
+ function parseStreamError(frame) {
167
+ var _a;
168
+ const value = asRecord(frame);
169
+ if (value == null) {
170
+ return void 0;
171
+ }
172
+ if (value.type === "response.failed") {
173
+ const response = asRecord(value.response);
174
+ const responseError = asRecord(response == null ? void 0 : response.error);
175
+ return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
176
+ message: responseError.message,
177
+ code: getStringOrNumber(responseError.code),
178
+ type: "response.failed",
179
+ frame
180
+ } : void 0;
181
+ }
182
+ const error = (_a = asRecord(value.error)) != null ? _a : value;
183
+ return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
184
+ message: error.message,
185
+ code: getStringOrNumber(error.code),
186
+ type: typeof error.type === "string" ? error.type : void 0,
187
+ frame
188
+ } : void 0;
189
+ }
190
+ function getStatusCode(error) {
191
+ if (typeof error.code === "number" && isHttpErrorStatusCode(error.code)) {
192
+ return error.code;
193
+ }
194
+ if (typeof error.code === "string" && /^\d{3}$/.test(error.code)) {
195
+ const numericCode = Number(error.code);
196
+ if (isHttpErrorStatusCode(numericCode)) {
197
+ return numericCode;
198
+ }
199
+ }
200
+ const discriminator = [error.code, error.type].filter((value) => typeof value === "string" || typeof value === "number").join(" ").toLowerCase();
201
+ if (["insufficient_quota", "rate_limit"].some(
202
+ (term) => discriminator.includes(term)
203
+ )) {
204
+ return 429;
205
+ }
206
+ if (discriminator.includes("authentication")) return 401;
207
+ if (discriminator.includes("permission")) return 403;
208
+ if (discriminator.includes("not_found")) return 404;
209
+ if (["invalid", "bad_request", "context_length"].some(
210
+ (term) => discriminator.includes(term)
211
+ )) {
212
+ return 400;
213
+ }
214
+ if (discriminator.includes("overload")) return 503;
215
+ if (discriminator.includes("timeout")) return 504;
216
+ return 500;
217
+ }
218
+ function asRecord(value) {
219
+ return typeof value === "object" && value != null ? value : void 0;
220
+ }
221
+ function getStringOrNumber(value) {
222
+ return typeof value === "string" || typeof value === "number" ? value : void 0;
223
+ }
224
+ function isHttpErrorStatusCode(value) {
225
+ return Number.isInteger(value) && value >= 400 && value <= 599;
226
+ }
227
+
105
228
  // src/chat/convert-openai-chat-usage.ts
106
229
  function convertOpenAIChatUsage(usage) {
107
230
  var _a, _b, _c, _d, _e, _f;
@@ -142,7 +265,7 @@ function convertOpenAIChatUsage(usage) {
142
265
  }
143
266
 
144
267
  // src/chat/convert-to-openai-chat-messages.ts
145
- var import_provider = require("@ai-sdk/provider");
268
+ var import_provider2 = require("@ai-sdk/provider");
146
269
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
147
270
  function serializeToolCallArguments(input) {
148
271
  return JSON.stringify(input === void 0 ? {} : input);
@@ -208,7 +331,7 @@ function convertToOpenAIChatMessages({
208
331
  };
209
332
  } else if (part.mediaType.startsWith("audio/")) {
210
333
  if (part.data instanceof URL) {
211
- throw new import_provider.UnsupportedFunctionalityError({
334
+ throw new import_provider2.UnsupportedFunctionalityError({
212
335
  functionality: "audio file parts with URLs"
213
336
  });
214
337
  }
@@ -233,14 +356,14 @@ function convertToOpenAIChatMessages({
233
356
  };
234
357
  }
235
358
  default: {
236
- throw new import_provider.UnsupportedFunctionalityError({
359
+ throw new import_provider2.UnsupportedFunctionalityError({
237
360
  functionality: `audio content parts with media type ${part.mediaType}`
238
361
  });
239
362
  }
240
363
  }
241
364
  } else if (part.mediaType === "application/pdf") {
242
365
  if (part.data instanceof URL) {
243
- throw new import_provider.UnsupportedFunctionalityError({
366
+ throw new import_provider2.UnsupportedFunctionalityError({
244
367
  functionality: "PDF file parts with URLs"
245
368
  });
246
369
  }
@@ -252,7 +375,7 @@ function convertToOpenAIChatMessages({
252
375
  }
253
376
  };
254
377
  } else {
255
- throw new import_provider.UnsupportedFunctionalityError({
378
+ throw new import_provider2.UnsupportedFunctionalityError({
256
379
  functionality: `file part media type ${part.mediaType}`
257
380
  });
258
381
  }
@@ -304,7 +427,7 @@ function convertToOpenAIChatMessages({
304
427
  contentValue = output.value;
305
428
  break;
306
429
  case "execution-denied":
307
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
430
+ contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
308
431
  break;
309
432
  case "content":
310
433
  case "json":
@@ -621,7 +744,7 @@ var openaiLanguageModelChatOptions = (0, import_provider_utils4.lazySchema)(
621
744
  );
622
745
 
623
746
  // src/chat/openai-chat-prepare-tools.ts
624
- var import_provider2 = require("@ai-sdk/provider");
747
+ var import_provider3 = require("@ai-sdk/provider");
625
748
  function prepareChatTools({
626
749
  tools,
627
750
  toolChoice
@@ -675,7 +798,7 @@ function prepareChatTools({
675
798
  };
676
799
  default: {
677
800
  const _exhaustiveCheck = type;
678
- throw new import_provider2.UnsupportedFunctionalityError({
801
+ throw new import_provider3.UnsupportedFunctionalityError({
679
802
  functionality: `tool choice type: ${_exhaustiveCheck}`
680
803
  });
681
804
  }
@@ -958,11 +1081,12 @@ var OpenAIChatLanguageModel = class {
958
1081
  include_usage: true
959
1082
  }
960
1083
  };
1084
+ const url = this.config.url({
1085
+ path: "/chat/completions",
1086
+ modelId: this.modelId
1087
+ });
961
1088
  const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
962
- url: this.config.url({
963
- path: "/chat/completions",
964
- modelId: this.modelId
965
- }),
1089
+ url,
966
1090
  headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
967
1091
  body,
968
1092
  failedResponseHandler: openaiFailedResponseHandler,
@@ -972,6 +1096,14 @@ var OpenAIChatLanguageModel = class {
972
1096
  abortSignal: options.abortSignal,
973
1097
  fetch: this.config.fetch
974
1098
  });
1099
+ const checkedResponse = await throwIfOpenAIStreamErrorBeforeOutput({
1100
+ stream: response,
1101
+ getError: (chunk) => "error" in chunk ? chunk.error : void 0,
1102
+ isOutputChunk: isOpenAIChatOutputChunk,
1103
+ url,
1104
+ requestBodyValues: body,
1105
+ responseHeaders
1106
+ });
975
1107
  const toolCalls = [];
976
1108
  let finishReason = {
977
1109
  unified: "other",
@@ -981,14 +1113,14 @@ var OpenAIChatLanguageModel = class {
981
1113
  let metadataExtracted = false;
982
1114
  let isActiveText = false;
983
1115
  const providerMetadata = { openai: {} };
984
- return {
985
- stream: response.pipeThrough(
1116
+ const result = {
1117
+ stream: checkedResponse.pipeThrough(
986
1118
  new TransformStream({
987
1119
  start(controller) {
988
1120
  controller.enqueue({ type: "stream-start", warnings });
989
1121
  },
990
1122
  transform(chunk, controller) {
991
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1123
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
992
1124
  if (options.includeRawChunks) {
993
1125
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
994
1126
  }
@@ -1052,19 +1184,19 @@ var OpenAIChatLanguageModel = class {
1052
1184
  const index = toolCallDelta.index;
1053
1185
  if (toolCalls[index] == null) {
1054
1186
  if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
1055
- throw new import_provider3.InvalidResponseDataError({
1187
+ throw new import_provider4.InvalidResponseDataError({
1056
1188
  data: toolCallDelta,
1057
1189
  message: `Expected 'function' type.`
1058
1190
  });
1059
1191
  }
1060
1192
  if (toolCallDelta.id == null) {
1061
- throw new import_provider3.InvalidResponseDataError({
1193
+ throw new import_provider4.InvalidResponseDataError({
1062
1194
  data: toolCallDelta,
1063
1195
  message: `Expected 'id' to be a string.`
1064
1196
  });
1065
1197
  }
1066
1198
  if (((_f = toolCallDelta.function) == null ? void 0 : _f.name) == null) {
1067
- throw new import_provider3.InvalidResponseDataError({
1199
+ throw new import_provider4.InvalidResponseDataError({
1068
1200
  data: toolCallDelta,
1069
1201
  message: `Expected 'function.name' to be a string.`
1070
1202
  });
@@ -1092,19 +1224,6 @@ var OpenAIChatLanguageModel = class {
1092
1224
  delta: toolCall2.function.arguments
1093
1225
  });
1094
1226
  }
1095
- if ((0, import_provider_utils5.isParsableJson)(toolCall2.function.arguments)) {
1096
- controller.enqueue({
1097
- type: "tool-input-end",
1098
- id: toolCall2.id
1099
- });
1100
- controller.enqueue({
1101
- type: "tool-call",
1102
- toolCallId: (_j = toolCall2.id) != null ? _j : (0, import_provider_utils5.generateId)(),
1103
- toolName: toolCall2.function.name,
1104
- input: toolCall2.function.arguments
1105
- });
1106
- toolCall2.hasFinished = true;
1107
- }
1108
1227
  }
1109
1228
  continue;
1110
1229
  }
@@ -1112,27 +1231,14 @@ var OpenAIChatLanguageModel = class {
1112
1231
  if (toolCall.hasFinished) {
1113
1232
  continue;
1114
1233
  }
1115
- if (((_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null) {
1116
- toolCall.function.arguments += (_m = (_l = toolCallDelta.function) == null ? void 0 : _l.arguments) != null ? _m : "";
1234
+ if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
1235
+ toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
1117
1236
  }
1118
1237
  controller.enqueue({
1119
1238
  type: "tool-input-delta",
1120
1239
  id: toolCall.id,
1121
- delta: (_n = toolCallDelta.function.arguments) != null ? _n : ""
1240
+ delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
1122
1241
  });
1123
- if (((_o = toolCall.function) == null ? void 0 : _o.name) != null && ((_p = toolCall.function) == null ? void 0 : _p.arguments) != null && (0, import_provider_utils5.isParsableJson)(toolCall.function.arguments)) {
1124
- controller.enqueue({
1125
- type: "tool-input-end",
1126
- id: toolCall.id
1127
- });
1128
- controller.enqueue({
1129
- type: "tool-call",
1130
- toolCallId: (_q = toolCall.id) != null ? _q : (0, import_provider_utils5.generateId)(),
1131
- toolName: toolCall.function.name,
1132
- input: toolCall.function.arguments
1133
- });
1134
- toolCall.hasFinished = true;
1135
- }
1136
1242
  }
1137
1243
  }
1138
1244
  if (delta.annotations != null) {
@@ -1148,9 +1254,25 @@ var OpenAIChatLanguageModel = class {
1148
1254
  }
1149
1255
  },
1150
1256
  flush(controller) {
1257
+ var _a;
1151
1258
  if (isActiveText) {
1152
1259
  controller.enqueue({ type: "text-end", id: "0" });
1153
1260
  }
1261
+ for (const toolCall of toolCalls) {
1262
+ if (!toolCall.hasFinished) {
1263
+ controller.enqueue({
1264
+ type: "tool-input-end",
1265
+ id: toolCall.id
1266
+ });
1267
+ controller.enqueue({
1268
+ type: "tool-call",
1269
+ toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils5.generateId)(),
1270
+ toolName: toolCall.function.name,
1271
+ input: toolCall.function.arguments
1272
+ });
1273
+ toolCall.hasFinished = true;
1274
+ }
1275
+ }
1154
1276
  controller.enqueue({
1155
1277
  type: "finish",
1156
1278
  finishReason,
@@ -1163,8 +1285,18 @@ var OpenAIChatLanguageModel = class {
1163
1285
  request: { body },
1164
1286
  response: { headers: responseHeaders }
1165
1287
  };
1288
+ return result;
1166
1289
  }
1167
1290
  };
1291
+ function isOpenAIChatOutputChunk(chunk) {
1292
+ if ("error" in chunk) {
1293
+ return false;
1294
+ }
1295
+ return chunk.choices.some((choice) => {
1296
+ const delta = choice.delta;
1297
+ 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;
1298
+ });
1299
+ }
1168
1300
 
1169
1301
  // src/completion/openai-completion-language-model.ts
1170
1302
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
@@ -1207,7 +1339,7 @@ function convertOpenAICompletionUsage(usage) {
1207
1339
  }
1208
1340
 
1209
1341
  // src/completion/convert-to-openai-completion-prompt.ts
1210
- var import_provider4 = require("@ai-sdk/provider");
1342
+ var import_provider5 = require("@ai-sdk/provider");
1211
1343
  function convertToOpenAICompletionPrompt({
1212
1344
  prompt,
1213
1345
  user = "user",
@@ -1223,7 +1355,7 @@ function convertToOpenAICompletionPrompt({
1223
1355
  for (const { role, content } of prompt) {
1224
1356
  switch (role) {
1225
1357
  case "system": {
1226
- throw new import_provider4.InvalidPromptError({
1358
+ throw new import_provider5.InvalidPromptError({
1227
1359
  message: "Unexpected system message in prompt: ${content}",
1228
1360
  prompt
1229
1361
  });
@@ -1249,7 +1381,7 @@ ${userMessage}
1249
1381
  return part.text;
1250
1382
  }
1251
1383
  case "tool-call": {
1252
- throw new import_provider4.UnsupportedFunctionalityError({
1384
+ throw new import_provider5.UnsupportedFunctionalityError({
1253
1385
  functionality: "tool-call messages"
1254
1386
  });
1255
1387
  }
@@ -1262,7 +1394,7 @@ ${assistantMessage}
1262
1394
  break;
1263
1395
  }
1264
1396
  case "tool": {
1265
- throw new import_provider4.UnsupportedFunctionalityError({
1397
+ throw new import_provider5.UnsupportedFunctionalityError({
1266
1398
  functionality: "tool messages"
1267
1399
  });
1268
1400
  }
@@ -1556,11 +1688,12 @@ var OpenAICompletionLanguageModel = class {
1556
1688
  include_usage: true
1557
1689
  }
1558
1690
  };
1691
+ const url = this.config.url({
1692
+ path: "/completions",
1693
+ modelId: this.modelId
1694
+ });
1559
1695
  const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
1560
- url: this.config.url({
1561
- path: "/completions",
1562
- modelId: this.modelId
1563
- }),
1696
+ url,
1564
1697
  headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
1565
1698
  body,
1566
1699
  failedResponseHandler: openaiFailedResponseHandler,
@@ -1570,6 +1703,14 @@ var OpenAICompletionLanguageModel = class {
1570
1703
  abortSignal: options.abortSignal,
1571
1704
  fetch: this.config.fetch
1572
1705
  });
1706
+ const checkedResponse = await throwIfOpenAIStreamErrorBeforeOutput({
1707
+ stream: response,
1708
+ getError: (chunk) => "error" in chunk ? chunk.error : void 0,
1709
+ isOutputChunk: isOpenAICompletionOutputChunk,
1710
+ url,
1711
+ requestBodyValues: body,
1712
+ responseHeaders
1713
+ });
1573
1714
  let finishReason = {
1574
1715
  unified: "other",
1575
1716
  raw: void 0
@@ -1577,8 +1718,8 @@ var OpenAICompletionLanguageModel = class {
1577
1718
  const providerMetadata = { openai: {} };
1578
1719
  let usage = void 0;
1579
1720
  let isFirstChunk = true;
1580
- return {
1581
- stream: response.pipeThrough(
1721
+ const result = {
1722
+ stream: checkedResponse.pipeThrough(
1582
1723
  new TransformStream({
1583
1724
  start(controller) {
1584
1725
  controller.enqueue({ type: "stream-start", warnings });
@@ -1643,11 +1784,15 @@ var OpenAICompletionLanguageModel = class {
1643
1784
  request: { body },
1644
1785
  response: { headers: responseHeaders }
1645
1786
  };
1787
+ return result;
1646
1788
  }
1647
1789
  };
1790
+ function isOpenAICompletionOutputChunk(chunk) {
1791
+ return !("error" in chunk) && chunk.choices.some((choice) => choice.text.length > 0);
1792
+ }
1648
1793
 
1649
1794
  // src/embedding/openai-embedding-model.ts
1650
- var import_provider5 = require("@ai-sdk/provider");
1795
+ var import_provider6 = require("@ai-sdk/provider");
1651
1796
  var import_provider_utils11 = require("@ai-sdk/provider-utils");
1652
1797
 
1653
1798
  // src/embedding/openai-embedding-options.ts
@@ -1702,7 +1847,7 @@ var OpenAIEmbeddingModel = class {
1702
1847
  }) {
1703
1848
  var _a;
1704
1849
  if (values.length > this.maxEmbeddingsPerCall) {
1705
- throw new import_provider5.TooManyEmbeddingValuesForCallError({
1850
+ throw new import_provider6.TooManyEmbeddingValuesForCallError({
1706
1851
  provider: this.provider,
1707
1852
  modelId: this.modelId,
1708
1853
  maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
@@ -2431,7 +2576,7 @@ var OpenAISpeechModel = class {
2431
2576
  };
2432
2577
 
2433
2578
  // src/responses/openai-responses-language-model.ts
2434
- var import_provider8 = require("@ai-sdk/provider");
2579
+ var import_provider9 = require("@ai-sdk/provider");
2435
2580
  var import_provider_utils35 = require("@ai-sdk/provider-utils");
2436
2581
 
2437
2582
  // src/responses/convert-openai-responses-usage.ts
@@ -2474,7 +2619,7 @@ function convertOpenAIResponsesUsage(usage) {
2474
2619
  }
2475
2620
 
2476
2621
  // src/responses/convert-to-openai-responses-input.ts
2477
- var import_provider6 = require("@ai-sdk/provider");
2622
+ var import_provider7 = require("@ai-sdk/provider");
2478
2623
  var import_provider_utils24 = require("@ai-sdk/provider-utils");
2479
2624
  var import_v417 = require("zod/v4");
2480
2625
 
@@ -2758,7 +2903,7 @@ async function convertToOpenAIResponsesInput({
2758
2903
  };
2759
2904
  }
2760
2905
  if (mediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
2761
- throw new import_provider6.UnsupportedFunctionalityError({
2906
+ throw new import_provider7.UnsupportedFunctionalityError({
2762
2907
  functionality: `file part media type ${mediaType}`
2763
2908
  });
2764
2909
  }
@@ -3152,7 +3297,7 @@ async function convertToOpenAIResponsesInput({
3152
3297
  outputValue = output.value;
3153
3298
  break;
3154
3299
  case "execution-denied":
3155
- outputValue = (_v = output.reason) != null ? _v : "Tool execution denied.";
3300
+ outputValue = (_v = output.reason) != null ? _v : "Tool call execution denied.";
3156
3301
  break;
3157
3302
  case "json":
3158
3303
  case "error-json":
@@ -3213,7 +3358,7 @@ async function convertToOpenAIResponsesInput({
3213
3358
  contentValue = output.value;
3214
3359
  break;
3215
3360
  case "execution-denied":
3216
- contentValue = (_w = output.reason) != null ? _w : "Tool execution denied.";
3361
+ contentValue = (_w = output.reason) != null ? _w : "Tool call execution denied.";
3217
3362
  break;
3218
3363
  case "json":
3219
3364
  case "error-json":
@@ -3327,6 +3472,23 @@ var jsonValueSchema = import_v418.z.lazy(
3327
3472
  import_v418.z.record(import_v418.z.string(), jsonValueSchema.optional())
3328
3473
  ])
3329
3474
  );
3475
+ var openaiResponsesNestedErrorChunkSchema = import_v418.z.object({
3476
+ type: import_v418.z.literal("error"),
3477
+ sequence_number: import_v418.z.number(),
3478
+ error: import_v418.z.object({
3479
+ type: import_v418.z.string(),
3480
+ code: import_v418.z.string(),
3481
+ message: import_v418.z.string(),
3482
+ param: import_v418.z.string().nullish()
3483
+ })
3484
+ });
3485
+ var openaiResponsesErrorChunkSchema = import_v418.z.object({
3486
+ type: import_v418.z.literal("error"),
3487
+ sequence_number: import_v418.z.number(),
3488
+ code: import_v418.z.string().nullish(),
3489
+ message: import_v418.z.string(),
3490
+ param: import_v418.z.string().nullish()
3491
+ });
3330
3492
  var openaiResponsesChunkSchema = (0, import_provider_utils25.lazySchema)(
3331
3493
  () => (0, import_provider_utils25.zodSchema)(
3332
3494
  import_v418.z.union([
@@ -3369,6 +3531,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils25.lazySchema)(
3369
3531
  }),
3370
3532
  import_v418.z.object({
3371
3533
  type: import_v418.z.literal("response.failed"),
3534
+ sequence_number: import_v418.z.number(),
3372
3535
  response: import_v418.z.object({
3373
3536
  error: import_v418.z.object({
3374
3537
  code: import_v418.z.string().nullish(),
@@ -3857,16 +4020,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils25.lazySchema)(
3857
4020
  output_index: import_v418.z.number(),
3858
4021
  diff: import_v418.z.string()
3859
4022
  }),
3860
- import_v418.z.object({
3861
- type: import_v418.z.literal("error"),
3862
- sequence_number: import_v418.z.number(),
3863
- error: import_v418.z.object({
3864
- type: import_v418.z.string(),
3865
- code: import_v418.z.string(),
3866
- message: import_v418.z.string(),
3867
- param: import_v418.z.string().nullish()
3868
- })
3869
- }),
4023
+ openaiResponsesNestedErrorChunkSchema,
4024
+ openaiResponsesErrorChunkSchema,
3870
4025
  import_v418.z.object({ type: import_v418.z.string() }).loose().transform((value) => ({
3871
4026
  type: "unknown_chunk",
3872
4027
  message: value.type
@@ -4227,7 +4382,11 @@ var openaiResponsesReasoningModelIds = [
4227
4382
  "gpt-5.4-pro",
4228
4383
  "gpt-5.4-pro-2026-03-05",
4229
4384
  "gpt-5.5",
4230
- "gpt-5.5-2026-04-23"
4385
+ "gpt-5.5-2026-04-23",
4386
+ "gpt-5.6",
4387
+ "gpt-5.6-luna",
4388
+ "gpt-5.6-sol",
4389
+ "gpt-5.6-terra"
4231
4390
  ];
4232
4391
  var openaiResponsesModelIds = [
4233
4392
  "gpt-4.1",
@@ -4433,7 +4592,7 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils26.lazy
4433
4592
  );
4434
4593
 
4435
4594
  // src/responses/openai-responses-prepare-tools.ts
4436
- var import_provider7 = require("@ai-sdk/provider");
4595
+ var import_provider8 = require("@ai-sdk/provider");
4437
4596
  var import_provider_utils34 = require("@ai-sdk/provider-utils");
4438
4597
 
4439
4598
  // src/tool/code-interpreter.ts
@@ -4795,7 +4954,7 @@ async function prepareResponsesTools({
4795
4954
  namespaceTools.set(namespace.name, namespaceTool);
4796
4955
  openaiTools.push(namespaceTool);
4797
4956
  } else if (namespaceTool.description !== namespace.description) {
4798
- throw new import_provider7.UnsupportedFunctionalityError({
4957
+ throw new import_provider8.UnsupportedFunctionalityError({
4799
4958
  functionality: `conflicting descriptions for OpenAI tool namespace "${namespace.name}"`
4800
4959
  });
4801
4960
  }
@@ -5007,7 +5166,7 @@ async function prepareResponsesTools({
5007
5166
  }
5008
5167
  default: {
5009
5168
  const _exhaustiveCheck = type;
5010
- throw new import_provider7.UnsupportedFunctionalityError({
5169
+ throw new import_provider8.UnsupportedFunctionalityError({
5011
5170
  functionality: `tool choice type: ${_exhaustiveCheck}`
5012
5171
  });
5013
5172
  }
@@ -5380,7 +5539,7 @@ var OpenAIResponsesLanguageModel = class {
5380
5539
  fetch: this.config.fetch
5381
5540
  });
5382
5541
  if (response.error) {
5383
- throw new import_provider8.APICallError({
5542
+ throw new import_provider9.APICallError({
5384
5543
  message: response.error.message,
5385
5544
  url,
5386
5545
  requestBodyValues: body,
@@ -5853,6 +6012,14 @@ var OpenAIResponsesLanguageModel = class {
5853
6012
  abortSignal: options.abortSignal,
5854
6013
  fetch: this.config.fetch
5855
6014
  });
6015
+ const checkedResponse = await throwIfOpenAIStreamErrorBeforeOutput({
6016
+ stream: response,
6017
+ getError: (chunk) => isErrorChunk(chunk) || isResponseFailedChunk(chunk) && chunk.response.error != null ? chunk : void 0,
6018
+ isOutputChunk: isResponseOutputChunk,
6019
+ url,
6020
+ requestBodyValues: body,
6021
+ responseHeaders
6022
+ });
5856
6023
  const self = this;
5857
6024
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
5858
6025
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
@@ -5870,8 +6037,9 @@ var OpenAIResponsesLanguageModel = class {
5870
6037
  const activeReasoning = {};
5871
6038
  let serviceTier;
5872
6039
  const hostedToolSearchCallIds = [];
5873
- return {
5874
- stream: response.pipeThrough(
6040
+ let encounteredStreamError = false;
6041
+ const result = {
6042
+ stream: checkedResponse.pipeThrough(
5875
6043
  new TransformStream({
5876
6044
  start(controller) {
5877
6045
  controller.enqueue({ type: "stream-start", warnings });
@@ -6191,12 +6359,12 @@ var OpenAIResponsesLanguageModel = class {
6191
6359
  toolName: toolNameMapping.toCustomToolName("file_search"),
6192
6360
  result: {
6193
6361
  queries: value.item.queries,
6194
- results: (_f = (_e = value.item.results) == null ? void 0 : _e.map((result) => ({
6195
- attributes: result.attributes,
6196
- fileId: result.file_id,
6197
- filename: result.filename,
6198
- score: result.score,
6199
- text: result.text
6362
+ results: (_f = (_e = value.item.results) == null ? void 0 : _e.map((result2) => ({
6363
+ attributes: result2.attributes,
6364
+ fileId: result2.file_id,
6365
+ filename: result2.filename,
6366
+ score: result2.score,
6367
+ text: result2.text
6200
6368
  }))) != null ? _f : null
6201
6369
  }
6202
6370
  });
@@ -6629,6 +6797,21 @@ var OpenAIResponsesLanguageModel = class {
6629
6797
  raw: incompleteReason != null ? incompleteReason : "error"
6630
6798
  };
6631
6799
  usage = (_z = value.response.usage) != null ? _z : void 0;
6800
+ if (!encounteredStreamError && value.response.error != null) {
6801
+ encounteredStreamError = true;
6802
+ controller.enqueue({
6803
+ type: "error",
6804
+ error: {
6805
+ type: "response.failed",
6806
+ sequence_number: value.sequence_number,
6807
+ response: {
6808
+ error: value.response.error,
6809
+ incomplete_details: value.response.incomplete_details,
6810
+ service_tier: value.response.service_tier
6811
+ }
6812
+ }
6813
+ });
6814
+ }
6632
6815
  } else if (isResponseAnnotationAddedChunk(value)) {
6633
6816
  ongoingAnnotations.push(value.annotation);
6634
6817
  if (value.annotation.type === "url_citation") {
@@ -6689,6 +6872,8 @@ var OpenAIResponsesLanguageModel = class {
6689
6872
  });
6690
6873
  }
6691
6874
  } else if (isErrorChunk(value)) {
6875
+ encounteredStreamError = true;
6876
+ finishReason = { unified: "error", raw: "error" };
6692
6877
  controller.enqueue({ type: "error", error: value });
6693
6878
  }
6694
6879
  },
@@ -6712,13 +6897,14 @@ var OpenAIResponsesLanguageModel = class {
6712
6897
  request: { body },
6713
6898
  response: { headers: responseHeaders }
6714
6899
  };
6900
+ return result;
6715
6901
  }
6716
6902
  };
6717
6903
  function isTextDeltaChunk(chunk) {
6718
6904
  return chunk.type === "response.output_text.delta";
6719
6905
  }
6720
6906
  function isOpenAIChatCompletionChunk(value) {
6721
- const chunk = asRecord(value);
6907
+ const chunk = asRecord2(value);
6722
6908
  return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
6723
6909
  }
6724
6910
  function createOpenAIResponsesChatCompletionsMismatchError({
@@ -6728,7 +6914,7 @@ function createOpenAIResponsesChatCompletionsMismatchError({
6728
6914
  requestBodyValues,
6729
6915
  responseHeaders
6730
6916
  }) {
6731
- return new import_provider8.APICallError({
6917
+ return new import_provider9.APICallError({
6732
6918
  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.",
6733
6919
  url,
6734
6920
  requestBodyValues,
@@ -6739,7 +6925,7 @@ function createOpenAIResponsesChatCompletionsMismatchError({
6739
6925
  isRetryable: false
6740
6926
  });
6741
6927
  }
6742
- function asRecord(value) {
6928
+ function asRecord2(value) {
6743
6929
  return typeof value === "object" && value != null ? value : void 0;
6744
6930
  }
6745
6931
  function isResponseOutputItemDoneChunk(chunk) {
@@ -6784,6 +6970,9 @@ function isResponseAnnotationAddedChunk(chunk) {
6784
6970
  function isErrorChunk(chunk) {
6785
6971
  return chunk.type === "error";
6786
6972
  }
6973
+ function isResponseOutputChunk(chunk) {
6974
+ return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
6975
+ }
6787
6976
  function mapWebSearchOutput(action) {
6788
6977
  var _a;
6789
6978
  if (action == null) {