@ai-sdk/openai 2.0.135 → 2.0.137

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.137
4
+
5
+ ### Patch Changes
6
+
7
+ - 6a87db5: Fix `gpt-transcribe` REST transcription. Requests with OpenAI provider options now use `response_format: 'json'` for `gpt-transcribe` and dated `gpt-4o-mini-transcribe` snapshots, which reject `verbose_json`. `durationInSeconds` is read from `usage.seconds` when a duration-billed response has no top-level `duration`.
8
+
9
+ ## 2.0.136
10
+
11
+ ### Patch Changes
12
+
13
+ - 2d22edb: Defer validation schema construction until first use to reduce provider import time.
14
+ - Updated dependencies [d7b0ffa]
15
+ - Updated dependencies [4146790]
16
+ - @ai-sdk/provider-utils@3.0.42
17
+
3
18
  ## 2.0.135
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
36
36
  // src/openai-error.ts
37
37
  var import_v4 = require("zod/v4");
38
38
  var import_provider_utils = require("@ai-sdk/provider-utils");
39
- var openaiErrorDataSchema = import_v4.z.object({
39
+ var openaiErrorDataSchema = () => import_v4.z.object({
40
40
  error: import_v4.z.object({
41
41
  message: import_v4.z.string(),
42
42
  // The additional information below is handled loosely to support
@@ -47,8 +47,11 @@ var openaiErrorDataSchema = import_v4.z.object({
47
47
  code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).nullish()
48
48
  })
49
49
  });
50
+ var openaiErrorDataSchemaValidator = (0, import_provider_utils.lazySchema)(
51
+ () => (0, import_provider_utils.zodSchema)(openaiErrorDataSchema())
52
+ );
50
53
  var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
51
- errorSchema: openaiErrorDataSchema,
54
+ errorSchema: openaiErrorDataSchemaValidator,
52
55
  errorToMessage: (data) => data.error.message
53
56
  });
54
57
 
@@ -518,7 +521,7 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazyValidator)(
518
521
  }).nullish()
519
522
  }).nullish()
520
523
  }),
521
- openaiErrorDataSchema
524
+ openaiErrorDataSchema()
522
525
  ])
523
526
  )
524
527
  );
@@ -1321,7 +1324,7 @@ var openaiCompletionChunkSchema = (0, import_provider_utils6.lazyValidator)(
1321
1324
  total_tokens: import_v44.z.number()
1322
1325
  }).nullish()
1323
1326
  }),
1324
- openaiErrorDataSchema
1327
+ openaiErrorDataSchema()
1325
1328
  ])
1326
1329
  )
1327
1330
  );
@@ -1761,7 +1764,7 @@ function getMaxImagesPerCall(modelId) {
1761
1764
  var _a2;
1762
1765
  return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
1763
1766
  }
1764
- var baseImageModelOptionsObject = import_v49.z.object({
1767
+ var baseImageModelOptionsObject = () => import_v49.z.object({
1765
1768
  /**
1766
1769
  * Quality of the generated image(s).
1767
1770
  *
@@ -1791,11 +1794,11 @@ var baseImageModelOptionsObject = import_v49.z.object({
1791
1794
  user: import_v49.z.string().optional()
1792
1795
  });
1793
1796
  var openaiImageModelOptions = (0, import_provider_utils13.lazyValidator)(
1794
- () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject)
1797
+ () => (0, import_provider_utils13.zodSchema)(baseImageModelOptionsObject())
1795
1798
  );
1796
1799
  var openaiImageModelGenerationOptions = (0, import_provider_utils13.lazyValidator)(
1797
1800
  () => (0, import_provider_utils13.zodSchema)(
1798
- baseImageModelOptionsObject.extend({
1801
+ baseImageModelOptionsObject().extend({
1799
1802
  /**
1800
1803
  * Style of the generated image. `vivid` produces hyper-real and
1801
1804
  * dramatic images; `natural` produces more subdued, less hyper-real
@@ -1984,15 +1987,16 @@ var codeInterpreter = (args = {}) => {
1984
1987
  // src/tool/file-search.ts
1985
1988
  var import_provider_utils16 = require("@ai-sdk/provider-utils");
1986
1989
  var import_v411 = require("zod/v4");
1987
- var comparisonFilterSchema = import_v411.z.object({
1990
+ var comparisonFilterSchema = () => import_v411.z.object({
1988
1991
  key: import_v411.z.string(),
1989
1992
  type: import_v411.z.enum(["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin"]),
1990
1993
  value: import_v411.z.union([import_v411.z.string(), import_v411.z.number(), import_v411.z.boolean(), import_v411.z.array(import_v411.z.string())])
1991
1994
  });
1992
- var compoundFilterSchema = import_v411.z.object({
1995
+ var cachedCompoundFilterSchema;
1996
+ var compoundFilterSchema = () => cachedCompoundFilterSchema != null ? cachedCompoundFilterSchema : cachedCompoundFilterSchema = import_v411.z.object({
1993
1997
  type: import_v411.z.enum(["and", "or"]),
1994
1998
  filters: import_v411.z.array(
1995
- import_v411.z.union([comparisonFilterSchema, import_v411.z.lazy(() => compoundFilterSchema)])
1999
+ import_v411.z.union([comparisonFilterSchema(), import_v411.z.lazy(() => compoundFilterSchema())])
1996
2000
  )
1997
2001
  });
1998
2002
  var fileSearchArgsSchema = (0, import_provider_utils16.lazySchema)(
@@ -2004,7 +2008,7 @@ var fileSearchArgsSchema = (0, import_provider_utils16.lazySchema)(
2004
2008
  ranker: import_v411.z.string().optional(),
2005
2009
  scoreThreshold: import_v411.z.number().optional()
2006
2010
  }).optional(),
2007
- filters: import_v411.z.union([comparisonFilterSchema, compoundFilterSchema]).optional()
2011
+ filters: import_v411.z.union([comparisonFilterSchema(), compoundFilterSchema()]).optional()
2008
2012
  })
2009
2013
  )
2010
2014
  );
@@ -2952,10 +2956,14 @@ async function convertToOpenAIResponsesInput({
2952
2956
  }
2953
2957
  return { input, warnings };
2954
2958
  }
2955
- var openaiResponsesReasoningProviderOptionsSchema = import_v417.z.object({
2956
- itemId: import_v417.z.string().nullish(),
2957
- reasoningEncryptedContent: import_v417.z.string().nullish()
2958
- });
2959
+ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils22.lazySchema)(
2960
+ () => (0, import_provider_utils22.zodSchema)(
2961
+ import_v417.z.object({
2962
+ itemId: import_v417.z.string().nullish(),
2963
+ reasoningEncryptedContent: import_v417.z.string().nullish()
2964
+ })
2965
+ )
2966
+ );
2959
2967
 
2960
2968
  // src/responses/map-openai-responses-finish-reason.ts
2961
2969
  function mapOpenAIResponseFinishReason({
@@ -5007,7 +5015,12 @@ var openaiTranscriptionResponseSchema = (0, import_provider_utils28.lazyValidato
5007
5015
  compression_ratio: import_v420.z.number(),
5008
5016
  no_speech_prob: import_v420.z.number()
5009
5017
  })
5010
- ).nullish()
5018
+ ).nullish(),
5019
+ // Lenient: an unexpected usage shape must not fail the transcription.
5020
+ usage: import_v420.z.object({
5021
+ type: import_v420.z.string().nullish(),
5022
+ seconds: import_v420.z.number().nullish()
5023
+ }).nullish().catch(void 0)
5011
5024
  })
5012
5025
  )
5013
5026
  );
@@ -5140,10 +5153,10 @@ var OpenAITranscriptionModel = class {
5140
5153
  prompt: openAIOptions.prompt,
5141
5154
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
5142
5155
  // prefer verbose_json to get segments for models that support it
5143
- response_format: [
5144
- "gpt-4o-transcribe",
5145
- "gpt-4o-mini-transcribe"
5146
- ].includes(this.modelId) ? "json" : "verbose_json",
5156
+ // gpt-4o(-mini)-transcribe (incl. snapshots) and gpt-transcribe reject verbose_json:
5157
+ response_format: ["gpt-4o-transcribe", "gpt-4o-mini-transcribe"].includes(
5158
+ this.modelId
5159
+ ) || this.modelId.startsWith("gpt-4o-mini-transcribe-") || this.modelId === "gpt-transcribe" || this.modelId.startsWith("gpt-transcribe-") ? "json" : "verbose_json",
5147
5160
  temperature: openAIOptions.temperature,
5148
5161
  timestamp_granularities: openAIOptions.timestampGranularities
5149
5162
  };
@@ -5165,7 +5178,7 @@ var OpenAITranscriptionModel = class {
5165
5178
  };
5166
5179
  }
5167
5180
  async doGenerate(options) {
5168
- var _a2, _b, _c, _d, _e, _f, _g, _h;
5181
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5169
5182
  const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
5170
5183
  const { formData, warnings } = await this.getArgs(options);
5171
5184
  const {
@@ -5199,7 +5212,8 @@ var OpenAITranscriptionModel = class {
5199
5212
  endSecond: word.end
5200
5213
  }))) != null ? _g : [],
5201
5214
  language,
5202
- durationInSeconds: (_h = response.duration) != null ? _h : void 0,
5215
+ // Duration-billed json responses report the duration only in `usage`:
5216
+ durationInSeconds: (_j = response.duration) != null ? _j : ((_h = response.usage) == null ? void 0 : _h.type) === "duration" ? (_i = response.usage.seconds) != null ? _i : void 0 : void 0,
5203
5217
  warnings,
5204
5218
  response: {
5205
5219
  timestamp: currentDate,
@@ -5212,7 +5226,7 @@ var OpenAITranscriptionModel = class {
5212
5226
  };
5213
5227
 
5214
5228
  // src/version.ts
5215
- var VERSION = true ? "2.0.135" : "0.0.0-test";
5229
+ var VERSION = true ? "2.0.137" : "0.0.0-test";
5216
5230
 
5217
5231
  // src/openai-provider.ts
5218
5232
  function createOpenAI(options = {}) {