@ai-sdk/openai 4.0.58 → 4.0.59

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,12 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 4.0.59
4
+
5
+ ### Patch Changes
6
+
7
+ - 4af00d1: feat(openai): add support for the gpt-6-astra
8
+ - abb9ebf: feat(openai): support `gpt-4o-transcribe-diarize`, including chunking and diarized speaker metadata
9
+
3
10
  ## 4.0.58
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { InferSchema, FetchFunction, WebSocketConstructor, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@ai-sdk/provider-utils';
5
5
  import { z } from 'zod/v4';
6
6
 
7
- type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | (string & {});
7
+ type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | (string & {});
8
8
  declare const openaiLanguageModelChatOptions: _ai_sdk_provider_utils.LazySchema<{
9
9
  logitBias?: Record<number, number> | undefined;
10
10
  logprobs?: number | boolean | undefined;
@@ -1365,7 +1365,7 @@ declare const openaiTools: {
1365
1365
  }, {}>;
1366
1366
  };
1367
1367
 
1368
- type OpenAIResponsesModelId = 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini' | 'gpt-4o' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.1-codex-mini' | 'gpt-5.1-codex' | 'gpt-5.1-codex-max' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.2-codex' | 'gpt-5.3-chat-latest' | 'gpt-5.3-codex' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-5-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5-codex' | 'gpt-5-mini-2025-08-07' | 'gpt-5-mini' | 'gpt-5-nano-2025-08-07' | 'gpt-5-nano' | 'gpt-5-pro-2025-10-06' | 'gpt-5-pro' | 'gpt-5' | 'o1-2024-12-17' | 'o1' | 'o3-2025-04-16' | 'o3-mini-2025-01-31' | 'o3-mini' | 'o3' | 'o4-mini' | 'o4-mini-2025-04-16' | (string & {});
1368
+ type OpenAIResponsesModelId = 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini' | 'gpt-4o' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.1-codex-mini' | 'gpt-5.1-codex' | 'gpt-5.1-codex-max' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.2-codex' | 'gpt-5.3-chat-latest' | 'gpt-5.3-codex' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-5-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5-codex' | 'gpt-5-mini-2025-08-07' | 'gpt-5-mini' | 'gpt-5-nano-2025-08-07' | 'gpt-5-nano' | 'gpt-5-pro-2025-10-06' | 'gpt-5-pro' | 'gpt-5' | 'o1-2024-12-17' | 'o1' | 'o3-2025-04-16' | 'o3-mini-2025-01-31' | 'o3-mini' | 'o3' | 'o4-mini' | 'o4-mini-2025-04-16' | (string & {});
1369
1369
  declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
1370
1370
  conversation?: string | null | undefined;
1371
1371
  include?: ("web_search_call.results" | "file_search_call.results" | "message.output_text.logprobs" | "reasoning.encrypted_content")[] | null | undefined;
@@ -1421,6 +1421,13 @@ declare const openAITranscriptionModelOptions: _ai_sdk_provider_utils.LazySchema
1421
1421
  prompt?: string | undefined;
1422
1422
  temperature?: number | undefined;
1423
1423
  timestampGranularities?: ("word" | "segment")[] | undefined;
1424
+ responseFormat?: "json" | "verbose_json" | "diarized_json" | undefined;
1425
+ chunkingStrategy?: "auto" | {
1426
+ type: "server_vad";
1427
+ threshold?: number | undefined;
1428
+ prefixPaddingMs?: number | undefined;
1429
+ silenceDurationMs?: number | undefined;
1430
+ } | undefined;
1424
1431
  streaming?: {
1425
1432
  delay?: "minimal" | "low" | "medium" | "high" | "xhigh" | undefined;
1426
1433
  include?: string[] | undefined;
package/dist/index.js CHANGED
@@ -5950,7 +5950,8 @@ var openaiResponsesReasoningModelIds = [
5950
5950
  "gpt-5.6",
5951
5951
  "gpt-5.6-luna",
5952
5952
  "gpt-5.6-sol",
5953
- "gpt-5.6-terra"
5953
+ "gpt-5.6-terra",
5954
+ "gpt-6-astra"
5954
5955
  ];
5955
5956
  var openaiResponsesModelIds = [
5956
5957
  "gpt-4.1",
@@ -10097,18 +10098,28 @@ var openaiTranscriptionResponseSchema = lazySchema28(
10097
10098
  })
10098
10099
  ).nullish(),
10099
10100
  segments: z30.array(
10100
- z30.object({
10101
- id: z30.number(),
10102
- seek: z30.number(),
10103
- start: z30.number(),
10104
- end: z30.number(),
10105
- text: z30.string(),
10106
- tokens: z30.array(z30.number()),
10107
- temperature: z30.number(),
10108
- avg_logprob: z30.number(),
10109
- compression_ratio: z30.number(),
10110
- no_speech_prob: z30.number()
10111
- })
10101
+ z30.union([
10102
+ z30.object({
10103
+ id: z30.number(),
10104
+ seek: z30.number(),
10105
+ start: z30.number(),
10106
+ end: z30.number(),
10107
+ text: z30.string(),
10108
+ tokens: z30.array(z30.number()),
10109
+ temperature: z30.number(),
10110
+ avg_logprob: z30.number(),
10111
+ compression_ratio: z30.number(),
10112
+ no_speech_prob: z30.number()
10113
+ }),
10114
+ z30.object({
10115
+ type: z30.literal("transcript.text.segment"),
10116
+ id: z30.string(),
10117
+ start: z30.number(),
10118
+ end: z30.number(),
10119
+ text: z30.string(),
10120
+ speaker: z30.string()
10121
+ })
10122
+ ])
10112
10123
  ).nullish()
10113
10124
  })
10114
10125
  )
@@ -10145,6 +10156,22 @@ var openAITranscriptionModelOptions = lazySchema29(
10145
10156
  * @default ['segment']
10146
10157
  */
10147
10158
  timestampGranularities: z31.array(z31.enum(["word", "segment"])).default(["segment"]).optional(),
10159
+ /**
10160
+ * The format of the transcription response.
10161
+ */
10162
+ responseFormat: z31.enum(["json", "verbose_json", "diarized_json"]).optional(),
10163
+ /**
10164
+ * Controls how the audio is split into chunks before transcription.
10165
+ */
10166
+ chunkingStrategy: z31.union([
10167
+ z31.literal("auto"),
10168
+ z31.object({
10169
+ type: z31.literal("server_vad"),
10170
+ threshold: z31.number().min(0).max(1).optional(),
10171
+ prefixPaddingMs: z31.number().int().min(0).optional(),
10172
+ silenceDurationMs: z31.number().int().min(0).optional()
10173
+ })
10174
+ ]).optional(),
10148
10175
  /**
10149
10176
  * Options for streaming transcription models such as `gpt-realtime-whisper`.
10150
10177
  */
@@ -10248,6 +10275,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10248
10275
  mediaType,
10249
10276
  providerOptions
10250
10277
  }) {
10278
+ var _a2, _b;
10251
10279
  const warnings = [];
10252
10280
  const openAIOptions = await parseProviderOptions10({
10253
10281
  provider: "openai",
@@ -10266,6 +10294,8 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10266
10294
  if (this.modelId === "whisper-1") {
10267
10295
  formData.append("response_format", "verbose_json");
10268
10296
  }
10297
+ const isDiarizationModel = this.modelId === "gpt-4o-transcribe-diarize";
10298
+ const chunkingStrategy = (_a2 = openAIOptions == null ? void 0 : openAIOptions.chunkingStrategy) != null ? _a2 : isDiarizationModel ? "auto" : void 0;
10269
10299
  if (openAIOptions) {
10270
10300
  const isGpt4oTranscribeModel = [
10271
10301
  "gpt-4o-transcribe",
@@ -10278,7 +10308,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10278
10308
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
10279
10309
  // prefer verbose_json to get segments for models that support it
10280
10310
  ...this.modelId !== "whisper-1" && {
10281
- response_format: isGpt4oTranscribeModel ? "json" : "verbose_json"
10311
+ response_format: (_b = openAIOptions.responseFormat) != null ? _b : isDiarizationModel ? "diarized_json" : isGpt4oTranscribeModel ? "json" : "verbose_json"
10282
10312
  },
10283
10313
  temperature: openAIOptions.temperature,
10284
10314
  timestamp_granularities: openAIOptions.timestampGranularities
@@ -10294,6 +10324,25 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10294
10324
  }
10295
10325
  }
10296
10326
  }
10327
+ } else if (isDiarizationModel) {
10328
+ formData.append("response_format", "diarized_json");
10329
+ }
10330
+ if (chunkingStrategy != null) {
10331
+ formData.append(
10332
+ "chunking_strategy",
10333
+ typeof chunkingStrategy === "string" ? chunkingStrategy : JSON.stringify({
10334
+ type: chunkingStrategy.type,
10335
+ ...chunkingStrategy.threshold != null && {
10336
+ threshold: chunkingStrategy.threshold
10337
+ },
10338
+ ...chunkingStrategy.prefixPaddingMs != null && {
10339
+ prefix_padding_ms: chunkingStrategy.prefixPaddingMs
10340
+ },
10341
+ ...chunkingStrategy.silenceDurationMs != null && {
10342
+ silence_duration_ms: chunkingStrategy.silenceDurationMs
10343
+ }
10344
+ })
10345
+ );
10297
10346
  }
10298
10347
  return {
10299
10348
  formData,
@@ -10301,7 +10350,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10301
10350
  };
10302
10351
  }
10303
10352
  async doGenerate(options) {
10304
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10353
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
10305
10354
  if (isRealtimeTranscriptionModelId(this.modelId)) {
10306
10355
  throw new UnsupportedFunctionalityError6({
10307
10356
  functionality: `non-streaming transcription with ${this.modelId}`
@@ -10328,25 +10377,42 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10328
10377
  fetch: this.config.fetch
10329
10378
  });
10330
10379
  const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
10380
+ const diarizedSegments = (_f = response.segments) == null ? void 0 : _f.flatMap(
10381
+ (segment) => "speaker" in segment ? [
10382
+ {
10383
+ text: segment.text,
10384
+ startSecond: segment.start,
10385
+ endSecond: segment.end,
10386
+ speaker: segment.speaker
10387
+ }
10388
+ ] : []
10389
+ );
10331
10390
  return {
10332
10391
  text: response.text,
10333
- segments: (_i = (_h = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
10392
+ segments: (_j = (_i = (_g = response.segments) == null ? void 0 : _g.map((segment) => ({
10334
10393
  text: segment.text,
10335
10394
  startSecond: segment.start,
10336
10395
  endSecond: segment.end
10337
- }))) != null ? _h : (_g = response.words) == null ? void 0 : _g.map((word) => ({
10396
+ }))) != null ? _i : (_h = response.words) == null ? void 0 : _h.map((word) => ({
10338
10397
  text: word.word,
10339
10398
  startSecond: word.start,
10340
10399
  endSecond: word.end
10341
- }))) != null ? _i : [],
10400
+ }))) != null ? _j : [],
10342
10401
  language,
10343
- durationInSeconds: (_j = response.duration) != null ? _j : void 0,
10402
+ durationInSeconds: (_k = response.duration) != null ? _k : void 0,
10344
10403
  warnings,
10345
10404
  response: {
10346
10405
  timestamp: currentDate,
10347
10406
  modelId: this.modelId,
10348
10407
  headers: responseHeaders,
10349
10408
  body: rawResponse
10409
+ },
10410
+ ...diarizedSegments != null && diarizedSegments.length > 0 && {
10411
+ providerMetadata: {
10412
+ openai: {
10413
+ segments: diarizedSegments
10414
+ }
10415
+ }
10350
10416
  }
10351
10417
  };
10352
10418
  }
@@ -10994,7 +11060,7 @@ var OpenAISkills = class {
10994
11060
  };
10995
11061
 
10996
11062
  // src/version.ts
10997
- var VERSION = true ? "4.0.58" : "0.0.0-test";
11063
+ var VERSION = true ? "4.0.59" : "0.0.0-test";
10998
11064
 
10999
11065
  // src/openai-provider.ts
11000
11066
  function createOpenAI(options = {}) {