@ai-sdk/openai 2.0.10 → 2.0.12

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.
@@ -316,7 +316,20 @@ var openaiProviderOptions = z2.object({
316
316
  * Controls the verbosity of the model's responses.
317
317
  * Lower values will result in more concise responses, while higher values will result in more verbose responses.
318
318
  */
319
- textVerbosity: z2.enum(["low", "medium", "high"]).optional()
319
+ textVerbosity: z2.enum(["low", "medium", "high"]).optional(),
320
+ /**
321
+ * A cache key for prompt caching. Allows manual control over prompt caching behavior.
322
+ * Useful for improving cache hit rates and working around automatic caching issues.
323
+ */
324
+ promptCacheKey: z2.string().optional(),
325
+ /**
326
+ * A stable identifier used to help detect users of your application
327
+ * that may be violating OpenAI's usage policies. The IDs should be a
328
+ * string that uniquely identifies each user. We recommend hashing their
329
+ * username or email address, in order to avoid sending us any identifying
330
+ * information.
331
+ */
332
+ safetyIdentifier: z2.string().optional()
320
333
  });
321
334
 
322
335
  // src/chat/openai-chat-prepare-tools.ts
@@ -589,6 +602,8 @@ var OpenAIChatLanguageModel = class {
589
602
  prediction: openaiOptions.prediction,
590
603
  reasoning_effort: openaiOptions.reasoningEffort,
591
604
  service_tier: openaiOptions.serviceTier,
605
+ prompt_cache_key: openaiOptions.promptCacheKey,
606
+ safety_identifier: openaiOptions.safetyIdentifier,
592
607
  // messages:
593
608
  messages
594
609
  };
@@ -1104,13 +1119,13 @@ var openaiChatChunkSchema = z5.union([
1104
1119
  openaiErrorDataSchema
1105
1120
  ]);
1106
1121
  function isReasoningModel(modelId) {
1107
- return modelId.startsWith("o") || modelId.startsWith("gpt-5");
1122
+ return (modelId.startsWith("o") || modelId.startsWith("gpt-5")) && !modelId.startsWith("gpt-5-chat");
1108
1123
  }
1109
1124
  function supportsFlexProcessing(modelId) {
1110
- return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5");
1125
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
1111
1126
  }
1112
1127
  function supportsPriorityProcessing(modelId) {
1113
- return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
1128
+ return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
1114
1129
  }
1115
1130
  function getSystemMessageMode(modelId) {
1116
1131
  var _a, _b;
@@ -1907,6 +1922,8 @@ var OpenAITranscriptionModel = class {
1907
1922
  include: openAIOptions.include,
1908
1923
  language: openAIOptions.language,
1909
1924
  prompt: openAIOptions.prompt,
1925
+ response_format: "verbose_json",
1926
+ // always use verbose_json to get segments
1910
1927
  temperature: openAIOptions.temperature,
1911
1928
  timestamp_granularities: openAIOptions.timestampGranularities
1912
1929
  };
@@ -1922,7 +1939,7 @@ var OpenAITranscriptionModel = class {
1922
1939
  };
1923
1940
  }
1924
1941
  async doGenerate(options) {
1925
- var _a, _b, _c, _d, _e, _f;
1942
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1926
1943
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1927
1944
  const { formData, warnings } = await this.getArgs(options);
1928
1945
  const {
@@ -1946,13 +1963,17 @@ var OpenAITranscriptionModel = class {
1946
1963
  const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1947
1964
  return {
1948
1965
  text: response.text,
1949
- segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1966
+ segments: (_g = (_f = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
1967
+ text: segment.text,
1968
+ startSecond: segment.start,
1969
+ endSecond: segment.end
1970
+ }))) != null ? _f : (_e = response.words) == null ? void 0 : _e.map((word) => ({
1950
1971
  text: word.word,
1951
1972
  startSecond: word.start,
1952
1973
  endSecond: word.end
1953
- }))) != null ? _e : [],
1974
+ }))) != null ? _g : [],
1954
1975
  language,
1955
- durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1976
+ durationInSeconds: (_h = response.duration) != null ? _h : void 0,
1956
1977
  warnings,
1957
1978
  response: {
1958
1979
  timestamp: currentDate,
@@ -1973,6 +1994,20 @@ var openaiTranscriptionResponseSchema = z12.object({
1973
1994
  start: z12.number(),
1974
1995
  end: z12.number()
1975
1996
  })
1997
+ ).nullish(),
1998
+ segments: z12.array(
1999
+ z12.object({
2000
+ id: z12.number(),
2001
+ seek: z12.number(),
2002
+ start: z12.number(),
2003
+ end: z12.number(),
2004
+ text: z12.string(),
2005
+ tokens: z12.array(z12.number()),
2006
+ temperature: z12.number(),
2007
+ avg_logprob: z12.number(),
2008
+ compression_ratio: z12.number(),
2009
+ no_speech_prob: z12.number()
2010
+ })
1976
2011
  ).nullish()
1977
2012
  });
1978
2013
 
@@ -2109,9 +2144,14 @@ import {
2109
2144
  import { parseProviderOptions as parseProviderOptions6 } from "@ai-sdk/provider-utils";
2110
2145
  import { z as z14 } from "zod/v4";
2111
2146
  import { convertToBase64 as convertToBase642 } from "@ai-sdk/provider-utils";
2147
+ function isFileId(data, prefixes) {
2148
+ if (!prefixes) return false;
2149
+ return prefixes.some((prefix) => data.startsWith(prefix));
2150
+ }
2112
2151
  async function convertToOpenAIResponsesMessages({
2113
2152
  prompt,
2114
- systemMessageMode
2153
+ systemMessageMode,
2154
+ fileIdPrefixes
2115
2155
  }) {
2116
2156
  var _a, _b, _c, _d, _e, _f;
2117
2157
  const messages = [];
@@ -2158,7 +2198,7 @@ async function convertToOpenAIResponsesMessages({
2158
2198
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
2159
2199
  return {
2160
2200
  type: "input_image",
2161
- ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
2201
+ ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2162
2202
  image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
2163
2203
  },
2164
2204
  detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
@@ -2171,7 +2211,7 @@ async function convertToOpenAIResponsesMessages({
2171
2211
  }
2172
2212
  return {
2173
2213
  type: "input_file",
2174
- ...typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
2214
+ ...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
2175
2215
  filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
2176
2216
  file_data: `data:application/pdf;base64,${convertToBase642(part.data)}`
2177
2217
  }
@@ -2479,7 +2519,8 @@ var OpenAIResponsesLanguageModel = class {
2479
2519
  }
2480
2520
  const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
2481
2521
  prompt,
2482
- systemMessageMode: modelConfig.systemMessageMode
2522
+ systemMessageMode: modelConfig.systemMessageMode,
2523
+ fileIdPrefixes: this.config.fileIdPrefixes
2483
2524
  });
2484
2525
  warnings.push(...messageWarnings);
2485
2526
  const openaiOptions = await parseProviderOptions7({
@@ -2519,6 +2560,8 @@ var OpenAIResponsesLanguageModel = class {
2519
2560
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2520
2561
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2521
2562
  include: openaiOptions == null ? void 0 : openaiOptions.include,
2563
+ prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
2564
+ safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
2522
2565
  // model-specific settings:
2523
2566
  ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2524
2567
  reasoning: {
@@ -2668,7 +2711,18 @@ var OpenAIResponsesLanguageModel = class {
2668
2711
  z16.object({
2669
2712
  type: z16.literal("file_search_call"),
2670
2713
  id: z16.string(),
2671
- status: z16.string().optional()
2714
+ status: z16.string().optional(),
2715
+ queries: z16.array(z16.string()).nullish(),
2716
+ results: z16.array(
2717
+ z16.object({
2718
+ attributes: z16.object({
2719
+ file_id: z16.string(),
2720
+ filename: z16.string(),
2721
+ score: z16.number(),
2722
+ text: z16.string()
2723
+ })
2724
+ })
2725
+ ).nullish()
2672
2726
  }),
2673
2727
  z16.object({
2674
2728
  type: z16.literal("reasoning"),
@@ -2810,7 +2864,9 @@ var OpenAIResponsesLanguageModel = class {
2810
2864
  toolName: "file_search",
2811
2865
  result: {
2812
2866
  type: "file_search_tool_result",
2813
- status: part.status || "completed"
2867
+ status: part.status || "completed",
2868
+ ...part.queries && { queries: part.queries },
2869
+ ...part.results && { results: part.results }
2814
2870
  },
2815
2871
  providerExecuted: true
2816
2872
  });
@@ -2925,6 +2981,16 @@ var OpenAIResponsesLanguageModel = class {
2925
2981
  id: value.item.id,
2926
2982
  toolName: "computer_use"
2927
2983
  });
2984
+ } else if (value.item.type === "file_search_call") {
2985
+ ongoingToolCalls[value.output_index] = {
2986
+ toolName: "file_search",
2987
+ toolCallId: value.item.id
2988
+ };
2989
+ controller.enqueue({
2990
+ type: "tool-input-start",
2991
+ id: value.item.id,
2992
+ toolName: "file_search"
2993
+ });
2928
2994
  } else if (value.item.type === "message") {
2929
2995
  controller.enqueue({
2930
2996
  type: "text-start",
@@ -3018,6 +3084,32 @@ var OpenAIResponsesLanguageModel = class {
3018
3084
  },
3019
3085
  providerExecuted: true
3020
3086
  });
3087
+ } else if (value.item.type === "file_search_call") {
3088
+ ongoingToolCalls[value.output_index] = void 0;
3089
+ hasToolCalls = true;
3090
+ controller.enqueue({
3091
+ type: "tool-input-end",
3092
+ id: value.item.id
3093
+ });
3094
+ controller.enqueue({
3095
+ type: "tool-call",
3096
+ toolCallId: value.item.id,
3097
+ toolName: "file_search",
3098
+ input: "",
3099
+ providerExecuted: true
3100
+ });
3101
+ controller.enqueue({
3102
+ type: "tool-result",
3103
+ toolCallId: value.item.id,
3104
+ toolName: "file_search",
3105
+ result: {
3106
+ type: "file_search_tool_result",
3107
+ status: value.item.status || "completed",
3108
+ ...value.item.queries && { queries: value.item.queries },
3109
+ ...value.item.results && { results: value.item.results }
3110
+ },
3111
+ providerExecuted: true
3112
+ });
3021
3113
  } else if (value.item.type === "message") {
3022
3114
  controller.enqueue({
3023
3115
  type: "text-end",
@@ -3196,7 +3288,18 @@ var responseOutputItemAddedSchema = z16.object({
3196
3288
  z16.object({
3197
3289
  type: z16.literal("file_search_call"),
3198
3290
  id: z16.string(),
3199
- status: z16.string()
3291
+ status: z16.string(),
3292
+ queries: z16.array(z16.string()).nullish(),
3293
+ results: z16.array(
3294
+ z16.object({
3295
+ attributes: z16.object({
3296
+ file_id: z16.string(),
3297
+ filename: z16.string(),
3298
+ score: z16.number(),
3299
+ text: z16.string()
3300
+ })
3301
+ })
3302
+ ).optional()
3200
3303
  })
3201
3304
  ])
3202
3305
  });
@@ -3234,7 +3337,18 @@ var responseOutputItemDoneSchema = z16.object({
3234
3337
  z16.object({
3235
3338
  type: z16.literal("file_search_call"),
3236
3339
  id: z16.string(),
3237
- status: z16.literal("completed")
3340
+ status: z16.literal("completed"),
3341
+ queries: z16.array(z16.string()).nullish(),
3342
+ results: z16.array(
3343
+ z16.object({
3344
+ attributes: z16.object({
3345
+ file_id: z16.string(),
3346
+ filename: z16.string(),
3347
+ score: z16.number(),
3348
+ text: z16.string()
3349
+ })
3350
+ })
3351
+ ).nullish()
3238
3352
  })
3239
3353
  ])
3240
3354
  });
@@ -3314,6 +3428,13 @@ function isErrorChunk(chunk) {
3314
3428
  return chunk.type === "error";
3315
3429
  }
3316
3430
  function getResponsesModelConfig(modelId) {
3431
+ if (modelId.startsWith("gpt-5-chat")) {
3432
+ return {
3433
+ isReasoningModel: false,
3434
+ systemMessageMode: "system",
3435
+ requiredAutoTruncation: false
3436
+ };
3437
+ }
3317
3438
  if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
3318
3439
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
3319
3440
  return {
@@ -3335,10 +3456,10 @@ function getResponsesModelConfig(modelId) {
3335
3456
  };
3336
3457
  }
3337
3458
  function supportsFlexProcessing2(modelId) {
3338
- return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5");
3459
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
3339
3460
  }
3340
3461
  function supportsPriorityProcessing2(modelId) {
3341
- return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3462
+ return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3342
3463
  }
3343
3464
  var openaiResponsesProviderOptionsSchema = z16.object({
3344
3465
  metadata: z16.any().nullish(),
@@ -3352,7 +3473,9 @@ var openaiResponsesProviderOptionsSchema = z16.object({
3352
3473
  reasoningSummary: z16.string().nullish(),
3353
3474
  serviceTier: z16.enum(["auto", "flex", "priority"]).nullish(),
3354
3475
  include: z16.array(z16.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish(),
3355
- textVerbosity: z16.enum(["low", "medium", "high"]).nullish()
3476
+ textVerbosity: z16.enum(["low", "medium", "high"]).nullish(),
3477
+ promptCacheKey: z16.string().nullish(),
3478
+ safetyIdentifier: z16.string().nullish()
3356
3479
  });
3357
3480
  export {
3358
3481
  OpenAIChatLanguageModel,