@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 +7 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +86 -20
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +9 -2
- package/dist/internal/index.js +85 -19
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +29 -6
- package/package.json +1 -1
- package/src/chat/openai-chat-language-model-options.ts +1 -0
- package/src/responses/openai-responses-language-model-options.ts +2 -0
- package/src/transcription/openai-transcription-api.ts +22 -12
- package/src/transcription/openai-transcription-model-options.ts +22 -0
- package/src/transcription/openai-transcription-model.ts +55 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
|
4
4
|
import { InferSchema, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, FetchFunction, WebSocketConstructor, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL } 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;
|
|
@@ -217,6 +217,13 @@ declare const openAITranscriptionModelOptions: _ai_sdk_provider_utils.LazySchema
|
|
|
217
217
|
prompt?: string | undefined;
|
|
218
218
|
temperature?: number | undefined;
|
|
219
219
|
timestampGranularities?: ("word" | "segment")[] | undefined;
|
|
220
|
+
responseFormat?: "json" | "verbose_json" | "diarized_json" | undefined;
|
|
221
|
+
chunkingStrategy?: "auto" | {
|
|
222
|
+
type: "server_vad";
|
|
223
|
+
threshold?: number | undefined;
|
|
224
|
+
prefixPaddingMs?: number | undefined;
|
|
225
|
+
silenceDurationMs?: number | undefined;
|
|
226
|
+
} | undefined;
|
|
220
227
|
streaming?: {
|
|
221
228
|
delay?: "minimal" | "low" | "medium" | "high" | "xhigh" | undefined;
|
|
222
229
|
include?: string[] | undefined;
|
|
@@ -1803,7 +1810,7 @@ declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) =>
|
|
|
1803
1810
|
}>;
|
|
1804
1811
|
}, {}>;
|
|
1805
1812
|
|
|
1806
|
-
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 & {});
|
|
1813
|
+
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 & {});
|
|
1807
1814
|
|
|
1808
1815
|
declare class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
1809
1816
|
readonly specificationVersion = "v4";
|
package/dist/internal/index.js
CHANGED
|
@@ -2424,18 +2424,28 @@ var openaiTranscriptionResponseSchema = lazySchema9(
|
|
|
2424
2424
|
})
|
|
2425
2425
|
).nullish(),
|
|
2426
2426
|
segments: z10.array(
|
|
2427
|
-
z10.
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2427
|
+
z10.union([
|
|
2428
|
+
z10.object({
|
|
2429
|
+
id: z10.number(),
|
|
2430
|
+
seek: z10.number(),
|
|
2431
|
+
start: z10.number(),
|
|
2432
|
+
end: z10.number(),
|
|
2433
|
+
text: z10.string(),
|
|
2434
|
+
tokens: z10.array(z10.number()),
|
|
2435
|
+
temperature: z10.number(),
|
|
2436
|
+
avg_logprob: z10.number(),
|
|
2437
|
+
compression_ratio: z10.number(),
|
|
2438
|
+
no_speech_prob: z10.number()
|
|
2439
|
+
}),
|
|
2440
|
+
z10.object({
|
|
2441
|
+
type: z10.literal("transcript.text.segment"),
|
|
2442
|
+
id: z10.string(),
|
|
2443
|
+
start: z10.number(),
|
|
2444
|
+
end: z10.number(),
|
|
2445
|
+
text: z10.string(),
|
|
2446
|
+
speaker: z10.string()
|
|
2447
|
+
})
|
|
2448
|
+
])
|
|
2439
2449
|
).nullish()
|
|
2440
2450
|
})
|
|
2441
2451
|
)
|
|
@@ -2472,6 +2482,22 @@ var openAITranscriptionModelOptions = lazySchema10(
|
|
|
2472
2482
|
* @default ['segment']
|
|
2473
2483
|
*/
|
|
2474
2484
|
timestampGranularities: z11.array(z11.enum(["word", "segment"])).default(["segment"]).optional(),
|
|
2485
|
+
/**
|
|
2486
|
+
* The format of the transcription response.
|
|
2487
|
+
*/
|
|
2488
|
+
responseFormat: z11.enum(["json", "verbose_json", "diarized_json"]).optional(),
|
|
2489
|
+
/**
|
|
2490
|
+
* Controls how the audio is split into chunks before transcription.
|
|
2491
|
+
*/
|
|
2492
|
+
chunkingStrategy: z11.union([
|
|
2493
|
+
z11.literal("auto"),
|
|
2494
|
+
z11.object({
|
|
2495
|
+
type: z11.literal("server_vad"),
|
|
2496
|
+
threshold: z11.number().min(0).max(1).optional(),
|
|
2497
|
+
prefixPaddingMs: z11.number().int().min(0).optional(),
|
|
2498
|
+
silenceDurationMs: z11.number().int().min(0).optional()
|
|
2499
|
+
})
|
|
2500
|
+
]).optional(),
|
|
2475
2501
|
/**
|
|
2476
2502
|
* Options for streaming transcription models such as `gpt-realtime-whisper`.
|
|
2477
2503
|
*/
|
|
@@ -2575,6 +2601,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2575
2601
|
mediaType,
|
|
2576
2602
|
providerOptions
|
|
2577
2603
|
}) {
|
|
2604
|
+
var _a2, _b;
|
|
2578
2605
|
const warnings = [];
|
|
2579
2606
|
const openAIOptions = await parseProviderOptions5({
|
|
2580
2607
|
provider: "openai",
|
|
@@ -2593,6 +2620,8 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2593
2620
|
if (this.modelId === "whisper-1") {
|
|
2594
2621
|
formData.append("response_format", "verbose_json");
|
|
2595
2622
|
}
|
|
2623
|
+
const isDiarizationModel = this.modelId === "gpt-4o-transcribe-diarize";
|
|
2624
|
+
const chunkingStrategy = (_a2 = openAIOptions == null ? void 0 : openAIOptions.chunkingStrategy) != null ? _a2 : isDiarizationModel ? "auto" : void 0;
|
|
2596
2625
|
if (openAIOptions) {
|
|
2597
2626
|
const isGpt4oTranscribeModel = [
|
|
2598
2627
|
"gpt-4o-transcribe",
|
|
@@ -2605,7 +2634,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2605
2634
|
// https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
|
|
2606
2635
|
// prefer verbose_json to get segments for models that support it
|
|
2607
2636
|
...this.modelId !== "whisper-1" && {
|
|
2608
|
-
response_format: isGpt4oTranscribeModel ? "json" : "verbose_json"
|
|
2637
|
+
response_format: (_b = openAIOptions.responseFormat) != null ? _b : isDiarizationModel ? "diarized_json" : isGpt4oTranscribeModel ? "json" : "verbose_json"
|
|
2609
2638
|
},
|
|
2610
2639
|
temperature: openAIOptions.temperature,
|
|
2611
2640
|
timestamp_granularities: openAIOptions.timestampGranularities
|
|
@@ -2621,6 +2650,25 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2621
2650
|
}
|
|
2622
2651
|
}
|
|
2623
2652
|
}
|
|
2653
|
+
} else if (isDiarizationModel) {
|
|
2654
|
+
formData.append("response_format", "diarized_json");
|
|
2655
|
+
}
|
|
2656
|
+
if (chunkingStrategy != null) {
|
|
2657
|
+
formData.append(
|
|
2658
|
+
"chunking_strategy",
|
|
2659
|
+
typeof chunkingStrategy === "string" ? chunkingStrategy : JSON.stringify({
|
|
2660
|
+
type: chunkingStrategy.type,
|
|
2661
|
+
...chunkingStrategy.threshold != null && {
|
|
2662
|
+
threshold: chunkingStrategy.threshold
|
|
2663
|
+
},
|
|
2664
|
+
...chunkingStrategy.prefixPaddingMs != null && {
|
|
2665
|
+
prefix_padding_ms: chunkingStrategy.prefixPaddingMs
|
|
2666
|
+
},
|
|
2667
|
+
...chunkingStrategy.silenceDurationMs != null && {
|
|
2668
|
+
silence_duration_ms: chunkingStrategy.silenceDurationMs
|
|
2669
|
+
}
|
|
2670
|
+
})
|
|
2671
|
+
);
|
|
2624
2672
|
}
|
|
2625
2673
|
return {
|
|
2626
2674
|
formData,
|
|
@@ -2628,7 +2676,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2628
2676
|
};
|
|
2629
2677
|
}
|
|
2630
2678
|
async doGenerate(options) {
|
|
2631
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2679
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2632
2680
|
if (isRealtimeTranscriptionModelId(this.modelId)) {
|
|
2633
2681
|
throw new UnsupportedFunctionalityError4({
|
|
2634
2682
|
functionality: `non-streaming transcription with ${this.modelId}`
|
|
@@ -2655,25 +2703,42 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
2655
2703
|
fetch: this.config.fetch
|
|
2656
2704
|
});
|
|
2657
2705
|
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
2706
|
+
const diarizedSegments = (_f = response.segments) == null ? void 0 : _f.flatMap(
|
|
2707
|
+
(segment) => "speaker" in segment ? [
|
|
2708
|
+
{
|
|
2709
|
+
text: segment.text,
|
|
2710
|
+
startSecond: segment.start,
|
|
2711
|
+
endSecond: segment.end,
|
|
2712
|
+
speaker: segment.speaker
|
|
2713
|
+
}
|
|
2714
|
+
] : []
|
|
2715
|
+
);
|
|
2658
2716
|
return {
|
|
2659
2717
|
text: response.text,
|
|
2660
|
-
segments: (
|
|
2718
|
+
segments: (_j = (_i = (_g = response.segments) == null ? void 0 : _g.map((segment) => ({
|
|
2661
2719
|
text: segment.text,
|
|
2662
2720
|
startSecond: segment.start,
|
|
2663
2721
|
endSecond: segment.end
|
|
2664
|
-
}))) != null ?
|
|
2722
|
+
}))) != null ? _i : (_h = response.words) == null ? void 0 : _h.map((word) => ({
|
|
2665
2723
|
text: word.word,
|
|
2666
2724
|
startSecond: word.start,
|
|
2667
2725
|
endSecond: word.end
|
|
2668
|
-
}))) != null ?
|
|
2726
|
+
}))) != null ? _j : [],
|
|
2669
2727
|
language,
|
|
2670
|
-
durationInSeconds: (
|
|
2728
|
+
durationInSeconds: (_k = response.duration) != null ? _k : void 0,
|
|
2671
2729
|
warnings,
|
|
2672
2730
|
response: {
|
|
2673
2731
|
timestamp: currentDate,
|
|
2674
2732
|
modelId: this.modelId,
|
|
2675
2733
|
headers: responseHeaders,
|
|
2676
2734
|
body: rawResponse
|
|
2735
|
+
},
|
|
2736
|
+
...diarizedSegments != null && diarizedSegments.length > 0 && {
|
|
2737
|
+
providerMetadata: {
|
|
2738
|
+
openai: {
|
|
2739
|
+
segments: diarizedSegments
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2677
2742
|
}
|
|
2678
2743
|
};
|
|
2679
2744
|
}
|
|
@@ -5821,7 +5886,8 @@ var openaiResponsesReasoningModelIds = [
|
|
|
5821
5886
|
"gpt-5.6",
|
|
5822
5887
|
"gpt-5.6-luna",
|
|
5823
5888
|
"gpt-5.6-sol",
|
|
5824
|
-
"gpt-5.6-terra"
|
|
5889
|
+
"gpt-5.6-terra",
|
|
5890
|
+
"gpt-6-astra"
|
|
5825
5891
|
];
|
|
5826
5892
|
var openaiResponsesModelIds = [
|
|
5827
5893
|
"gpt-4.1",
|