@ai-sdk/openai 4.0.62 → 4.0.64

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.
@@ -116,6 +116,13 @@ type OpenAIConfig = {
116
116
  fetch?: FetchFunction;
117
117
  webSocket?: WebSocketConstructor;
118
118
  generateId?: () => string;
119
+ /**
120
+ * Whether Responses API message input items must include an explicit
121
+ * `type: 'message'` discriminator.
122
+ *
123
+ * @see https://github.com/vercel/ai/issues/20180
124
+ */
125
+ explicitMessageItemType?: boolean;
119
126
  /**
120
127
  * This is soft-deprecated. Use provider references (e.g. `{ openai: 'file-abc123' }`)
121
128
  * in file part data instead. File ID prefixes used to identify file IDs
@@ -155,7 +162,7 @@ declare class OpenAIEmbeddingModel implements EmbeddingModelV4 {
155
162
  doEmbed({ values, headers, abortSignal, providerOptions, }: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>>;
156
163
  }
157
164
 
158
- type OpenAIImageModelId = 'dall-e-3' | 'dall-e-2' | 'gpt-image-1' | 'gpt-image-1-mini' | 'gpt-image-1.5' | 'gpt-image-2' | 'chatgpt-image-latest' | (string & {});
165
+ type OpenAIImageModelId = 'dall-e-3' | 'dall-e-2' | 'gpt-image-1' | 'gpt-image-1-mini' | 'gpt-image-1.5' | 'gpt-image-2' | 'gpt-image-2.5-flare' | 'gpt-image-2.5-flare-2026-09-08' | 'gpt-image-2.5-sunburst' | 'gpt-image-2.5-sunburst-2026-09-08' | 'chatgpt-image-latest' | (string & {});
159
166
  declare const modelMaxImagesPerCall: Record<OpenAIImageModelId, number>;
160
167
  declare function hasDefaultResponseFormat(modelId: string): boolean;
161
168
  declare function getMaxImagesPerCall(modelId: OpenAIImageModelId): number;
@@ -422,6 +429,7 @@ type OpenAIResponsesInputItem = OpenAIResponsesSystemMessage | OpenAIResponsesUs
422
429
  type OpenAIResponsesIncludeValue = 'web_search_call.action.sources' | 'web_search_call.results' | 'code_interpreter_call.outputs' | 'computer_call_output.output.image_url' | 'file_search_call.results' | 'message.input_image.image_url' | 'message.output_text.logprobs' | 'reasoning.encrypted_content';
423
430
  type OpenAIResponsesIncludeOptions = Array<OpenAIResponsesIncludeValue> | undefined | null;
424
431
  type OpenAIResponsesSystemMessage = {
432
+ type?: 'message';
425
433
  role: 'system' | 'developer';
426
434
  content: string | Array<{
427
435
  type: 'input_text';
@@ -432,6 +440,7 @@ type OpenAIResponsesSystemMessage = {
432
440
  }>;
433
441
  };
434
442
  type OpenAIResponsesUserMessage = {
443
+ type?: 'message';
435
444
  role: 'user';
436
445
  content: Array<{
437
446
  type: 'input_text';
@@ -473,6 +482,7 @@ type OpenAIResponsesUserMessage = {
473
482
  }>;
474
483
  };
475
484
  type OpenAIResponsesAssistantMessage = {
485
+ type?: 'message';
476
486
  role: 'assistant';
477
487
  content: Array<{
478
488
  type: 'output_text';
@@ -2377,8 +2387,9 @@ type ImageGenerationArgs = {
2377
2387
  quality?: 'auto' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
2378
2388
  /**
2379
2389
  * The size of the generated image.
2380
- * One of 1024x1024, 1024x1536, 1536x1024, or auto. gpt-image-2 also accepts
2381
- * arbitrary WIDTHxHEIGHT sizes where both are divisible by 16, e.g. 1536x864.
2390
+ * One of 1024x1024, 1024x1536, 1536x1024, or auto. GPT Image 2 and 2.5
2391
+ * models also accept arbitrary WIDTHxHEIGHT sizes where both are divisible
2392
+ * by 16, e.g. 1536x864.
2382
2393
  * Default: auto.
2383
2394
  */
2384
2395
  size?: 'auto' | '1024x1024' | '1024x1536' | '1536x1024' | (string & {});
@@ -1,4 +1,7 @@
1
1
  // src/chat/openai-chat-language-model.ts
2
+ import {
3
+ InvalidResponseDataError
4
+ } from "@ai-sdk/provider";
2
5
  import {
3
6
  StreamingToolCallTracker,
4
7
  combineHeaders,
@@ -1215,6 +1218,12 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1215
1218
  fetch: this.config.fetch
1216
1219
  });
1217
1220
  const choice = response.choices[0];
1221
+ if (choice == null) {
1222
+ throw new InvalidResponseDataError({
1223
+ data: rawResponse,
1224
+ message: "Response did not contain any choices."
1225
+ });
1226
+ }
1218
1227
  const content = [];
1219
1228
  const text = choice.message.content;
1220
1229
  if (text != null && text.length > 0) {
@@ -2114,6 +2123,10 @@ var modelMaxImagesPerCall = {
2114
2123
  "gpt-image-1-mini": 10,
2115
2124
  "gpt-image-1.5": 10,
2116
2125
  "gpt-image-2": 10,
2126
+ "gpt-image-2.5-flare": 10,
2127
+ "gpt-image-2.5-flare-2026-09-08": 10,
2128
+ "gpt-image-2.5-sunburst": 10,
2129
+ "gpt-image-2.5-sunburst-2026-09-08": 10,
2117
2130
  "chatgpt-image-latest": 10
2118
2131
  };
2119
2132
  var defaultResponseFormatPrefixes = ["chatgpt-image-", "gpt-image-"];
@@ -3862,6 +3875,7 @@ async function convertToOpenAIResponsesInput({
3862
3875
  toolNameMapping,
3863
3876
  systemMessageMode,
3864
3877
  providerOptionsName,
3878
+ explicitMessageItemType = false,
3865
3879
  fileIdPrefixes,
3866
3880
  passThroughUnsupportedFiles = false,
3867
3881
  store,
@@ -3879,6 +3893,7 @@ async function convertToOpenAIResponsesInput({
3879
3893
  let input = [];
3880
3894
  const warnings = [];
3881
3895
  const processedApprovalIds = /* @__PURE__ */ new Set();
3896
+ const programmaticToolCallIds = /* @__PURE__ */ new Set();
3882
3897
  const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
3883
3898
  prompt,
3884
3899
  providerOptionsName
@@ -3895,6 +3910,7 @@ async function convertToOpenAIResponsesInput({
3895
3910
  providerOptionsName
3896
3911
  );
3897
3912
  input.push({
3913
+ ...explicitMessageItemType && { type: "message" },
3898
3914
  role: "system",
3899
3915
  content: promptCacheBreakpoint == null ? content : [
3900
3916
  {
@@ -3912,6 +3928,7 @@ async function convertToOpenAIResponsesInput({
3912
3928
  providerOptionsName
3913
3929
  );
3914
3930
  input.push({
3931
+ ...explicitMessageItemType && { type: "message" },
3915
3932
  role: "developer",
3916
3933
  content: promptCacheBreakpoint == null ? content : [
3917
3934
  {
@@ -3941,6 +3958,7 @@ async function convertToOpenAIResponsesInput({
3941
3958
  }
3942
3959
  case "user": {
3943
3960
  input.push({
3961
+ ...explicitMessageItemType && { type: "message" },
3944
3962
  role: "user",
3945
3963
  content: content.map((part, index) => {
3946
3964
  var _a3, _b2, _c2, _d2, _e2;
@@ -4057,6 +4075,7 @@ async function convertToOpenAIResponsesInput({
4057
4075
  break;
4058
4076
  }
4059
4077
  input.push({
4078
+ ...explicitMessageItemType && { type: "message" },
4060
4079
  role: "assistant",
4061
4080
  content: [{ type: "output_text", text: part.text }],
4062
4081
  id,
@@ -4097,6 +4116,9 @@ async function convertToOpenAIResponsesInput({
4097
4116
  const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
4098
4117
  const isAsync = (_p = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.async) != null ? _p : (_o = (_n = part.providerMetadata) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.async;
4099
4118
  const caller = (_r = (_q = part.providerOptions) == null ? void 0 : _q[providerOptionsName]) == null ? void 0 : _r.caller;
4119
+ if ((caller == null ? void 0 : caller.type) === "program") {
4120
+ programmaticToolCallIds.add(part.toolCallId);
4121
+ }
4100
4122
  if (hasConversation && id != null) {
4101
4123
  break;
4102
4124
  }
@@ -4748,6 +4770,12 @@ ${text}`,
4748
4770
  });
4749
4771
  continue;
4750
4772
  }
4773
+ const resultCaller = (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller;
4774
+ if (output.type === "execution-denied" && ((resultCaller == null ? void 0 : resultCaller.type) === "program" || programmaticToolCallIds.has(part.toolCallId))) {
4775
+ throw new UnsupportedFunctionalityError5({
4776
+ functionality: "execution-denied results for programmatic tool calls"
4777
+ });
4778
+ }
4751
4779
  const contentValue = await convertFunctionToolResultOutput({
4752
4780
  output,
4753
4781
  toolName: part.toolName,
@@ -4760,9 +4788,7 @@ ${text}`,
4760
4788
  providerOptionsName,
4761
4789
  warnings
4762
4790
  });
4763
- const caller = mapToolCaller(
4764
- (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller
4765
- );
4791
+ const caller = mapToolCaller(resultCaller);
4766
4792
  input.push({
4767
4793
  type: "function_call_output",
4768
4794
  call_id: part.toolCallId,
@@ -7255,6 +7281,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7255
7281
  toolNameMapping,
7256
7282
  systemMessageMode: (_d = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
7257
7283
  providerOptionsName,
7284
+ explicitMessageItemType: config.explicitMessageItemType,
7258
7285
  fileIdPrefixes: config.fileIdPrefixes,
7259
7286
  passThroughUnsupportedFiles: (_e = openaiOptions == null ? void 0 : openaiOptions.passThroughUnsupportedFiles) != null ? _e : false,
7260
7287
  store: (_f = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _f : true,
@@ -8013,6 +8040,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8013
8040
  break;
8014
8041
  }
8015
8042
  case "apply_patch_call": {
8043
+ hasFunctionCall = true;
8016
8044
  content.push({
8017
8045
  type: "tool-call",
8018
8046
  toolCallId: part.call_id,
@@ -8756,6 +8784,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8756
8784
  toolCall.applyPatch.endEmitted = true;
8757
8785
  }
8758
8786
  if (toolCall && value.item.status === "completed") {
8787
+ hasFunctionCall = true;
8759
8788
  controller.enqueue({
8760
8789
  type: "tool-call",
8761
8790
  toolCallId: toolCall.toolCallId,