@ai-sdk/openai 2.0.136 → 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,11 @@
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
+
3
9
  ## 2.0.136
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -5015,7 +5015,12 @@ var openaiTranscriptionResponseSchema = (0, import_provider_utils28.lazyValidato
5015
5015
  compression_ratio: import_v420.z.number(),
5016
5016
  no_speech_prob: import_v420.z.number()
5017
5017
  })
5018
- ).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)
5019
5024
  })
5020
5025
  )
5021
5026
  );
@@ -5148,10 +5153,10 @@ var OpenAITranscriptionModel = class {
5148
5153
  prompt: openAIOptions.prompt,
5149
5154
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
5150
5155
  // prefer verbose_json to get segments for models that support it
5151
- response_format: [
5152
- "gpt-4o-transcribe",
5153
- "gpt-4o-mini-transcribe"
5154
- ].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",
5155
5160
  temperature: openAIOptions.temperature,
5156
5161
  timestamp_granularities: openAIOptions.timestampGranularities
5157
5162
  };
@@ -5173,7 +5178,7 @@ var OpenAITranscriptionModel = class {
5173
5178
  };
5174
5179
  }
5175
5180
  async doGenerate(options) {
5176
- var _a2, _b, _c, _d, _e, _f, _g, _h;
5181
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5177
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();
5178
5183
  const { formData, warnings } = await this.getArgs(options);
5179
5184
  const {
@@ -5207,7 +5212,8 @@ var OpenAITranscriptionModel = class {
5207
5212
  endSecond: word.end
5208
5213
  }))) != null ? _g : [],
5209
5214
  language,
5210
- 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,
5211
5217
  warnings,
5212
5218
  response: {
5213
5219
  timestamp: currentDate,
@@ -5220,7 +5226,7 @@ var OpenAITranscriptionModel = class {
5220
5226
  };
5221
5227
 
5222
5228
  // src/version.ts
5223
- var VERSION = true ? "2.0.136" : "0.0.0-test";
5229
+ var VERSION = true ? "2.0.137" : "0.0.0-test";
5224
5230
 
5225
5231
  // src/openai-provider.ts
5226
5232
  function createOpenAI(options = {}) {