@ai-sdk/openai 4.0.66 → 4.0.67

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/dist/index.js CHANGED
@@ -9898,9 +9898,486 @@ async function convertOpenAIBatchResult(body) {
9898
9898
  };
9899
9899
  }
9900
9900
 
9901
+ // src/realtime/openai-realtime-factory.ts
9902
+ import {
9903
+ InvalidArgumentError as InvalidArgumentError4,
9904
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError10
9905
+ } from "@ai-sdk/provider";
9906
+
9907
+ // src/live/openai-realtime-model-live.ts
9908
+ import {
9909
+ createJsonResponseHandler as createJsonResponseHandler8,
9910
+ postJsonToApi as postJsonToApi7
9911
+ } from "@ai-sdk/provider-utils";
9912
+ import { z as z32 } from "zod/v4";
9913
+
9914
+ // src/live/openai-live-event-mapper.ts
9915
+ import {
9916
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError9
9917
+ } from "@ai-sdk/provider";
9918
+ import { z as z31 } from "zod/v4";
9919
+
9920
+ // src/live/openai-live-session-config.ts
9921
+ import {
9922
+ InvalidArgumentError as InvalidArgumentError3,
9923
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError8
9924
+ } from "@ai-sdk/provider";
9925
+ import { z as z30 } from "zod/v4";
9926
+
9927
+ // src/live/openai-realtime-model-live-options.ts
9928
+ import { z as z29 } from "zod/v4";
9929
+ var serverEventSelectorSchema = z29.strictObject({
9930
+ type: z29.string(),
9931
+ responseEvent: z29.string().optional()
9932
+ }).refine(
9933
+ (selector) => selector.type === "response.event" === (selector.responseEvent !== void 0),
9934
+ "responseEvent is required for response.event and forbidden for other event types."
9935
+ );
9936
+ var openaiRealtimeModelLiveOptionsSchema = z29.strictObject({
9937
+ client: z29.strictObject({
9938
+ dataChannel: z29.strictObject({
9939
+ allowedClientEvents: z29.union([z29.literal("all"), z29.array(z29.string())]).optional(),
9940
+ allowedServerEvents: z29.union([z29.literal("all"), z29.array(serverEventSelectorSchema)]).optional()
9941
+ })
9942
+ }).optional(),
9943
+ delegation: z29.strictObject({ type: z29.literal("client") }).nullable().optional(),
9944
+ input: z29.array(
9945
+ z29.discriminatedUnion("role", [
9946
+ z29.strictObject({
9947
+ type: z29.literal("message"),
9948
+ role: z29.enum(["developer", "user"]),
9949
+ content: z29.tuple([
9950
+ z29.strictObject({ type: z29.literal("input_text"), text: z29.string() })
9951
+ ])
9952
+ }),
9953
+ z29.strictObject({
9954
+ type: z29.literal("message"),
9955
+ role: z29.literal("assistant"),
9956
+ content: z29.tuple([
9957
+ z29.strictObject({
9958
+ type: z29.enum(["text", "output_text"]),
9959
+ text: z29.string()
9960
+ })
9961
+ ])
9962
+ })
9963
+ ])
9964
+ ).max(128).optional(),
9965
+ store: z29.boolean().optional(),
9966
+ voice: z29.strictObject({ id: z29.string().min(1) }).optional()
9967
+ });
9968
+
9969
+ // src/live/openai-live-session-config.ts
9970
+ var audioFormatSchema = z30.union([
9971
+ z30.strictObject({
9972
+ type: z30.literal("audio/pcm"),
9973
+ rate: z30.union([z30.literal(16e3), z30.literal(24e3)])
9974
+ }),
9975
+ z30.strictObject({
9976
+ type: z30.enum(["audio/pcma", "audio/pcmu"]),
9977
+ rate: z30.literal(8e3)
9978
+ })
9979
+ ]);
9980
+ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket") {
9981
+ var _a2, _b, _c, _d, _e, _f;
9982
+ for (const key of Object.keys(config)) {
9983
+ if (![
9984
+ "instructions",
9985
+ "voice",
9986
+ "inputAudioFormat",
9987
+ "outputAudioFormat",
9988
+ "providerOptions"
9989
+ ].includes(key)) {
9990
+ throw new UnsupportedFunctionalityError8({
9991
+ functionality: `OpenAI Live session setting: ${key}`
9992
+ });
9993
+ }
9994
+ }
9995
+ if (z30.object({ delegation: z30.object({ type: z30.literal("responses") }) }).safeParse((_a2 = config.providerOptions) == null ? void 0 : _a2.openai).success) {
9996
+ throw new UnsupportedFunctionalityError8({
9997
+ functionality: "OpenAI Live Responses delegation; only client delegation is supported"
9998
+ });
9999
+ }
10000
+ const options = openaiRealtimeModelLiveOptionsSchema.parse(
10001
+ (_c = (_b = config.providerOptions) == null ? void 0 : _b.openai) != null ? _c : {}
10002
+ );
10003
+ if (options.client !== void 0 && transport !== "webrtc") {
10004
+ throw new UnsupportedFunctionalityError8({
10005
+ functionality: "OpenAI Live client permissions outside WebRTC startup"
10006
+ });
10007
+ }
10008
+ if (options.voice != null && config.voice != null) {
10009
+ throw new InvalidArgumentError3({
10010
+ argument: "voice",
10011
+ message: "Choose either voice or providerOptions.openai.voice."
10012
+ });
10013
+ }
10014
+ if (transport === "webrtc" && (config.inputAudioFormat !== void 0 || config.outputAudioFormat !== void 0)) {
10015
+ throw new UnsupportedFunctionalityError8({
10016
+ functionality: "Fixed audio formats for OpenAI Live WebRTC; audio is negotiated through SDP"
10017
+ });
10018
+ }
10019
+ const inputFormat = config.inputAudioFormat == null ? void 0 : audioFormatSchema.parse(config.inputAudioFormat);
10020
+ const outputFormat = config.outputAudioFormat == null ? void 0 : audioFormatSchema.parse(config.outputAudioFormat);
10021
+ if (inputFormat != null && outputFormat != null && (inputFormat.type !== outputFormat.type || inputFormat.rate !== outputFormat.rate)) {
10022
+ throw new InvalidArgumentError3({
10023
+ argument: "outputAudioFormat",
10024
+ message: "OpenAI Live requires the same input and output audio format."
10025
+ });
10026
+ }
10027
+ return {
10028
+ model: modelId,
10029
+ ...config.instructions !== void 0 ? { instructions: config.instructions } : {},
10030
+ audio: {
10031
+ ...transport === "websocket" ? {
10032
+ format: (_d = inputFormat != null ? inputFormat : outputFormat) != null ? _d : { type: "audio/pcm", rate: 24e3 }
10033
+ } : {},
10034
+ output: { voice: (_f = (_e = options.voice) != null ? _e : config.voice) != null ? _f : "marin" }
10035
+ },
10036
+ ...options.delegation !== void 0 ? { delegation: options.delegation } : {},
10037
+ ...options.client !== void 0 ? {
10038
+ client: {
10039
+ data_channel: {
10040
+ ...options.client.dataChannel.allowedClientEvents !== void 0 ? {
10041
+ allowed_client_events: options.client.dataChannel.allowedClientEvents
10042
+ } : {},
10043
+ ...options.client.dataChannel.allowedServerEvents !== void 0 ? {
10044
+ allowed_server_events: options.client.dataChannel.allowedServerEvents === "all" ? "all" : options.client.dataChannel.allowedServerEvents.map(
10045
+ (selector) => ({
10046
+ type: selector.type,
10047
+ ...selector.responseEvent !== void 0 ? { response_event: selector.responseEvent } : {}
10048
+ })
10049
+ )
10050
+ } : {}
10051
+ }
10052
+ }
10053
+ } : {},
10054
+ ...options.input !== void 0 ? { input: options.input } : {},
10055
+ ...options.store !== void 0 ? { store: options.store } : {}
10056
+ };
10057
+ }
10058
+
10059
+ // src/live/openai-live-event-mapper.ts
10060
+ var sessionSchema = z31.object({ id: z31.string().min(1) });
10061
+ var startedSessionSchema = sessionSchema.extend({
10062
+ delegation: z31.object({ type: z31.enum(["client", "responses"]) }).nullish()
10063
+ });
10064
+ var usageSchema = z31.object({ seconds: z31.number().nonnegative() });
10065
+ var transcriptFields = {
10066
+ delta: z31.string(),
10067
+ start_ms: z31.number().nonnegative(),
10068
+ end_ms: z31.number().nonnegative()
10069
+ };
10070
+ var acknowledgmentFields = { client_event_id: z31.string().nullish() };
10071
+ var appendAcknowledgmentFields = {
10072
+ ...acknowledgmentFields,
10073
+ start_ms: z31.number().nonnegative(),
10074
+ end_ms: z31.number().nonnegative()
10075
+ };
10076
+ var serverEventSchema = z31.discriminatedUnion("type", [
10077
+ z31.object({
10078
+ type: z31.literal("session.started"),
10079
+ session: startedSessionSchema
10080
+ }),
10081
+ z31.object({
10082
+ type: z31.literal("session.closed"),
10083
+ session: sessionSchema.nullish(),
10084
+ usage: usageSchema,
10085
+ reason: z31.string()
10086
+ }),
10087
+ z31.object({
10088
+ type: z31.literal("session.usage.updated"),
10089
+ usage: usageSchema,
10090
+ context_window: z31.object({ usage_ratio: z31.number().min(0).max(1) }).nullish()
10091
+ }),
10092
+ z31.object({
10093
+ type: z31.literal("session.output_audio.delta"),
10094
+ delta: z31.string()
10095
+ }),
10096
+ z31.object({
10097
+ type: z31.literal("session.input_transcript.delta"),
10098
+ ...transcriptFields
10099
+ }),
10100
+ z31.object({
10101
+ type: z31.literal("session.output_transcript.delta"),
10102
+ ...transcriptFields
10103
+ }),
10104
+ z31.object({
10105
+ type: z31.literal("session.delegation.created"),
10106
+ offset_ms: z31.number().nonnegative().nullish(),
10107
+ delegation: z31.object({
10108
+ id: z31.string().min(1),
10109
+ target: z31.enum(["client", "responses"]).nullish(),
10110
+ response_id: z31.string().min(1).nullish()
10111
+ })
10112
+ }),
10113
+ z31.object({
10114
+ type: z31.literal("session.updated"),
10115
+ session: sessionSchema,
10116
+ ...acknowledgmentFields
10117
+ }),
10118
+ z31.object({
10119
+ type: z31.literal("session.input_audio.muted"),
10120
+ ...acknowledgmentFields
10121
+ }),
10122
+ z31.object({
10123
+ type: z31.literal("session.input_audio.unmuted"),
10124
+ ...acknowledgmentFields
10125
+ }),
10126
+ z31.object({
10127
+ type: z31.literal("session.instructions.appended"),
10128
+ ...appendAcknowledgmentFields
10129
+ }),
10130
+ z31.object({
10131
+ type: z31.literal("session.thinking.appended"),
10132
+ ...appendAcknowledgmentFields
10133
+ }),
10134
+ z31.object({
10135
+ type: z31.literal("session.commentary.appended"),
10136
+ ...appendAcknowledgmentFields
10137
+ }),
10138
+ z31.object({
10139
+ type: z31.literal("error"),
10140
+ error: z31.object({
10141
+ message: z31.string(),
10142
+ code: z31.string().nullish(),
10143
+ client_event_id: z31.string().nullish()
10144
+ })
10145
+ })
10146
+ ]);
10147
+ var knownTypes = new Set(
10148
+ serverEventSchema.options.map((schema) => schema.shape.type.value)
10149
+ );
10150
+ var envelopeSchema = z31.object({ type: z31.string() });
10151
+ function createOpenAILiveServerEventParser() {
10152
+ return (raw) => parseOpenAILiveServerEvent(raw);
10153
+ }
10154
+ function parseOpenAILiveServerEvent(raw) {
10155
+ return [parseServerEvent(raw)];
10156
+ }
10157
+ function parseServerEvent(raw) {
10158
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10159
+ const envelope = envelopeSchema.safeParse(raw);
10160
+ if (envelope.success && !knownTypes.has(envelope.data.type)) {
10161
+ return { type: "custom", rawType: envelope.data.type, raw };
10162
+ }
10163
+ const parsed = serverEventSchema.safeParse(raw);
10164
+ if (!parsed.success) {
10165
+ return {
10166
+ type: "error",
10167
+ code: "invalid_server_event",
10168
+ message: "Invalid OpenAI Live server event.",
10169
+ raw
10170
+ };
10171
+ }
10172
+ const event = parsed.data;
10173
+ if ("start_ms" in event && event.end_ms < event.start_ms) {
10174
+ return {
10175
+ type: "error",
10176
+ code: "invalid_server_event",
10177
+ message: "Invalid OpenAI Live event time interval.",
10178
+ raw
10179
+ };
10180
+ }
10181
+ switch (event.type) {
10182
+ case "session.started":
10183
+ return {
10184
+ type: "session-started",
10185
+ sessionId: event.session.id,
10186
+ delegationMode: ((_a2 = event.session.delegation) == null ? void 0 : _a2.type) === "responses" ? "provider" : "client",
10187
+ raw
10188
+ };
10189
+ case "session.closed":
10190
+ return {
10191
+ type: "session-closed",
10192
+ sessionId: (_b = event.session) == null ? void 0 : _b.id,
10193
+ usage: event.usage,
10194
+ reason: event.reason,
10195
+ raw
10196
+ };
10197
+ case "session.usage.updated":
10198
+ return {
10199
+ type: "session-usage",
10200
+ usage: event.usage,
10201
+ contextWindowUsageRatio: (_c = event.context_window) == null ? void 0 : _c.usage_ratio,
10202
+ raw
10203
+ };
10204
+ case "session.output_audio.delta":
10205
+ return { type: "audio-chunk", delta: event.delta, raw };
10206
+ case "session.input_transcript.delta":
10207
+ case "session.output_transcript.delta":
10208
+ return {
10209
+ type: "transcript-fragment",
10210
+ speaker: event.type === "session.input_transcript.delta" ? "user" : "assistant",
10211
+ delta: event.delta,
10212
+ startMs: event.start_ms,
10213
+ endMs: event.end_ms,
10214
+ raw
10215
+ };
10216
+ case "session.delegation.created":
10217
+ return {
10218
+ type: "delegation-created",
10219
+ delegationId: event.delegation.id,
10220
+ target: event.delegation.target === "responses" ? "provider" : (_d = event.delegation.target) != null ? _d : void 0,
10221
+ offsetMs: (_e = event.offset_ms) != null ? _e : void 0,
10222
+ ...event.delegation.response_id != null ? { responseId: event.delegation.response_id } : {},
10223
+ raw
10224
+ };
10225
+ case "error":
10226
+ return {
10227
+ type: "error",
10228
+ message: event.error.message,
10229
+ code: (_f = event.error.code) != null ? _f : void 0,
10230
+ clientEventId: (_g = event.error.client_event_id) != null ? _g : void 0,
10231
+ raw
10232
+ };
10233
+ case "session.updated":
10234
+ return {
10235
+ type: "command-acknowledged",
10236
+ command: "session.update",
10237
+ clientEventId: (_h = event.client_event_id) != null ? _h : void 0,
10238
+ raw
10239
+ };
10240
+ case "session.input_audio.muted":
10241
+ case "session.input_audio.unmuted":
10242
+ return {
10243
+ type: "command-acknowledged",
10244
+ command: event.type.slice(0, -1),
10245
+ clientEventId: (_i = event.client_event_id) != null ? _i : void 0,
10246
+ raw
10247
+ };
10248
+ case "session.instructions.appended":
10249
+ case "session.thinking.appended":
10250
+ case "session.commentary.appended":
10251
+ return {
10252
+ type: "command-acknowledged",
10253
+ command: event.type.slice(0, -2),
10254
+ clientEventId: (_j = event.client_event_id) != null ? _j : void 0,
10255
+ raw
10256
+ };
10257
+ }
10258
+ }
10259
+ function serializeOpenAILiveClientEvent(event, modelId) {
10260
+ var _a2, _b, _c;
10261
+ const eventId = "eventId" in event && event.eventId !== void 0 ? { event_id: event.eventId } : {};
10262
+ switch (event.type) {
10263
+ case "session-start":
10264
+ return {
10265
+ type: "session.start",
10266
+ session: buildOpenAILiveSessionConfig(event.config, modelId),
10267
+ ...eventId
10268
+ };
10269
+ case "session-update":
10270
+ throw new UnsupportedFunctionalityError9({
10271
+ functionality: "OpenAI Live session-update; startup settings are immutable; use context-append or input-audio-mute/input-audio-unmute"
10272
+ });
10273
+ case "session-close":
10274
+ return { type: "session.close", ...eventId };
10275
+ case "input-audio-append":
10276
+ return {
10277
+ type: "session.input_audio.append",
10278
+ audio: event.audio,
10279
+ ...eventId
10280
+ };
10281
+ case "input-audio-mute":
10282
+ return { type: "session.input_audio.mute", ...eventId };
10283
+ case "input-audio-unmute":
10284
+ return { type: "session.input_audio.unmute", ...eventId };
10285
+ case "context-append": {
10286
+ const context = z31.object({
10287
+ content: z31.string(),
10288
+ delegationId: z31.string().min(1).nullable()
10289
+ }).parse(event);
10290
+ const options = z31.strictObject({
10291
+ channel: z31.enum(["instructions", "thinking", "commentary"]).optional()
10292
+ }).parse((_b = (_a2 = event.providerOptions) == null ? void 0 : _a2.openai) != null ? _b : {});
10293
+ return {
10294
+ type: `session.${(_c = options.channel) != null ? _c : "thinking"}.append`,
10295
+ content: context.content,
10296
+ delegation_id: context.delegationId,
10297
+ ...eventId
10298
+ };
10299
+ }
10300
+ default:
10301
+ throw new UnsupportedFunctionalityError9({
10302
+ functionality: `OpenAI Live command: ${event.type}; use continuous audio and context-append instead of voice-turn commands`
10303
+ });
10304
+ }
10305
+ }
10306
+
10307
+ // src/live/openai-realtime-model-live.ts
10308
+ var webRTCSessionSchema = z32.object({
10309
+ session: z32.object({ id: z32.string().min(1) }),
10310
+ transport: z32.object({ type: z32.literal("webrtc"), sdp: z32.string().min(1) })
10311
+ });
10312
+ var OpenAIRealtimeModelLive = class {
10313
+ constructor(modelId, config) {
10314
+ this.modelId = modelId;
10315
+ this.config = config;
10316
+ this.specificationVersion = "v4";
10317
+ this.capabilities = {
10318
+ conversation: "continuous",
10319
+ transports: ["websocket", "webrtc"],
10320
+ connections: ["server-websocket", "webrtc"],
10321
+ startup: "session-start",
10322
+ finalization: "session-close"
10323
+ };
10324
+ }
10325
+ get provider() {
10326
+ return this.config.provider;
10327
+ }
10328
+ getWebRTCConfig() {
10329
+ return { dataChannelLabel: "oai-events" };
10330
+ }
10331
+ getServerWebSocketConfig() {
10332
+ const url = new URL(`${this.config.baseURL}/live/sessions`);
10333
+ url.protocol = url.protocol === "http:" ? "ws:" : "wss:";
10334
+ const headers = {};
10335
+ for (const [key, value] of Object.entries(this.config.headers())) {
10336
+ if (value !== void 0) headers[key] = value;
10337
+ }
10338
+ return { url: url.toString(), headers };
10339
+ }
10340
+ async doCreateWebRTCSession({
10341
+ sdp,
10342
+ sessionConfig = {},
10343
+ abortSignal
10344
+ }) {
10345
+ const session = buildOpenAILiveSessionConfig(
10346
+ sessionConfig,
10347
+ this.modelId,
10348
+ "webrtc"
10349
+ );
10350
+ const { value } = await postJsonToApi7({
10351
+ url: `${this.config.baseURL}/live/sessions`,
10352
+ headers: this.config.headers(),
10353
+ body: {
10354
+ session,
10355
+ transport: { type: "webrtc", sdp: z32.string().min(1).parse(sdp) }
10356
+ },
10357
+ failedResponseHandler: openaiFailedResponseHandler,
10358
+ successfulResponseHandler: createJsonResponseHandler8(webRTCSessionSchema),
10359
+ abortSignal,
10360
+ fetch: this.config.fetch
10361
+ });
10362
+ return { sessionId: value.session.id, sdp: value.transport.sdp };
10363
+ }
10364
+ parseServerEvent(raw) {
10365
+ return parseOpenAILiveServerEvent(raw);
10366
+ }
10367
+ createServerEventParser() {
10368
+ return createOpenAILiveServerEventParser();
10369
+ }
10370
+ serializeClientEvent(event) {
10371
+ return serializeOpenAILiveClientEvent(event, this.modelId);
10372
+ }
10373
+ buildSessionConfig(config) {
10374
+ return buildOpenAILiveSessionConfig(config, this.modelId);
10375
+ }
10376
+ };
10377
+
9901
10378
  // src/realtime/openai-realtime-event-mapper.ts
9902
10379
  function parseOpenAIRealtimeServerEvent(raw) {
9903
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
10380
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
9904
10381
  const event = raw;
9905
10382
  const type = event.type;
9906
10383
  switch (type) {
@@ -10067,6 +10544,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
10067
10544
  type: "error",
10068
10545
  message: (_q = (_p = (_o = event.error) == null ? void 0 : _o.message) != null ? _p : event.message) != null ? _q : "Unknown error",
10069
10546
  code: (_s = (_r = event.error) == null ? void 0 : _r.code) != null ? _s : event.code,
10547
+ clientEventId: (_u = (_t = event.error) == null ? void 0 : _t.event_id) != null ? _u : void 0,
10070
10548
  raw
10071
10549
  };
10072
10550
  // ── Pass-through ────────────────────────────────────────────────
@@ -10079,12 +10557,14 @@ function serializeOpenAIRealtimeClientEvent(event, modelId) {
10079
10557
  case "session-update":
10080
10558
  return {
10081
10559
  type: "session.update",
10082
- session: buildOpenAISessionConfig(event.config, modelId)
10560
+ session: buildOpenAISessionConfig(event.config, modelId),
10561
+ ...event.eventId != null ? { event_id: event.eventId } : {}
10083
10562
  };
10084
10563
  case "input-audio-append":
10085
10564
  return {
10086
10565
  type: "input_audio_buffer.append",
10087
- audio: event.audio
10566
+ audio: event.audio,
10567
+ ...event.eventId != null ? { event_id: event.eventId } : {}
10088
10568
  };
10089
10569
  case "input-audio-commit":
10090
10570
  return { type: "input_audio_buffer.commit" };
@@ -10287,12 +10767,53 @@ var OpenAIRealtimeModel = class {
10287
10767
  }
10288
10768
  };
10289
10769
 
10770
+ // src/realtime/openai-realtime-factory.ts
10771
+ var knownLiveModelIds = ["gpt-live-1"];
10772
+ function resolveRealtimeApi(modelId, { api } = {}) {
10773
+ if (api !== void 0) {
10774
+ if (api !== "live" && api !== "realtime") {
10775
+ throw new InvalidArgumentError4({
10776
+ argument: "api",
10777
+ message: 'OpenAI realtime api must be "live" or "realtime".'
10778
+ });
10779
+ }
10780
+ return api;
10781
+ }
10782
+ return knownLiveModelIds.some((knownModelId) => knownModelId === modelId) ? "live" : "realtime";
10783
+ }
10784
+ function createOpenAIRealtimeFactory(config) {
10785
+ const createModel = (modelId, options) => {
10786
+ const api = resolveRealtimeApi(modelId, options);
10787
+ const modelConfig = { ...config, provider: `${config.provider}.${api}` };
10788
+ return api === "live" ? new OpenAIRealtimeModelLive(modelId, modelConfig) : new OpenAIRealtimeModel(modelId, modelConfig);
10789
+ };
10790
+ return Object.assign(createModel, {
10791
+ getToken: async (options) => {
10792
+ const model = createModel(options.model, options);
10793
+ if (model instanceof OpenAIRealtimeModelLive) {
10794
+ throw new UnsupportedFunctionalityError10({
10795
+ functionality: "Short-lived OpenAI credentials for the Live API. Use server WebSocket setup via getServerWebSocketConfig() with a server-side API key instead."
10796
+ });
10797
+ }
10798
+ const secret = await model.doCreateClientSecret({
10799
+ sessionConfig: options.sessionConfig,
10800
+ expiresAfterSeconds: options.expiresAfterSeconds
10801
+ });
10802
+ return {
10803
+ token: secret.token,
10804
+ url: secret.url,
10805
+ expiresAt: secret.expiresAt
10806
+ };
10807
+ }
10808
+ });
10809
+ }
10810
+
10290
10811
  // src/speech/openai-speech-model.ts
10291
10812
  import {
10292
10813
  combineHeaders as combineHeaders8,
10293
10814
  createBinaryResponseHandler,
10294
10815
  parseProviderOptions as parseProviderOptions9,
10295
- postJsonToApi as postJsonToApi7,
10816
+ postJsonToApi as postJsonToApi8,
10296
10817
  serializeModelOptions as serializeModelOptions6,
10297
10818
  WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
10298
10819
  WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
@@ -10303,12 +10824,12 @@ import {
10303
10824
  lazySchema as lazySchema27,
10304
10825
  zodSchema as zodSchema27
10305
10826
  } from "@ai-sdk/provider-utils";
10306
- import { z as z29 } from "zod/v4";
10827
+ import { z as z33 } from "zod/v4";
10307
10828
  var openaiSpeechModelOptionsSchema = lazySchema27(
10308
10829
  () => zodSchema27(
10309
- z29.object({
10310
- instructions: z29.string().nullish(),
10311
- speed: z29.number().min(0.25).max(4).default(1).nullish()
10830
+ z33.object({
10831
+ instructions: z33.string().nullish(),
10832
+ speed: z33.number().min(0.25).max(4).default(1).nullish()
10312
10833
  })
10313
10834
  )
10314
10835
  );
@@ -10395,7 +10916,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
10395
10916
  value: audio,
10396
10917
  responseHeaders,
10397
10918
  rawValue: rawResponse
10398
- } = await postJsonToApi7({
10919
+ } = await postJsonToApi8({
10399
10920
  url: this.config.url({
10400
10921
  path: "/audio/speech",
10401
10922
  modelId: this.modelId
@@ -10425,13 +10946,13 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
10425
10946
 
10426
10947
  // src/transcription/openai-transcription-model.ts
10427
10948
  import {
10428
- UnsupportedFunctionalityError as UnsupportedFunctionalityError8
10949
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError11
10429
10950
  } from "@ai-sdk/provider";
10430
10951
  import {
10431
10952
  combineHeaders as combineHeaders9,
10432
10953
  convertBase64ToUint8Array as convertBase64ToUint8Array2,
10433
10954
  convertToBase64 as convertToBase643,
10434
- createJsonResponseHandler as createJsonResponseHandler8,
10955
+ createJsonResponseHandler as createJsonResponseHandler9,
10435
10956
  connectToWebSocket,
10436
10957
  mediaTypeToExtension,
10437
10958
  parseProviderOptions as parseProviderOptions10,
@@ -10446,41 +10967,41 @@ import {
10446
10967
 
10447
10968
  // src/transcription/openai-transcription-api.ts
10448
10969
  import { lazySchema as lazySchema28, zodSchema as zodSchema28 } from "@ai-sdk/provider-utils";
10449
- import { z as z30 } from "zod/v4";
10970
+ import { z as z34 } from "zod/v4";
10450
10971
  var openaiTranscriptionResponseSchema = lazySchema28(
10451
10972
  () => zodSchema28(
10452
- z30.object({
10453
- text: z30.string(),
10454
- language: z30.string().nullish(),
10455
- duration: z30.number().nullish(),
10456
- words: z30.array(
10457
- z30.object({
10458
- word: z30.string(),
10459
- start: z30.number(),
10460
- end: z30.number()
10973
+ z34.object({
10974
+ text: z34.string(),
10975
+ language: z34.string().nullish(),
10976
+ duration: z34.number().nullish(),
10977
+ words: z34.array(
10978
+ z34.object({
10979
+ word: z34.string(),
10980
+ start: z34.number(),
10981
+ end: z34.number()
10461
10982
  })
10462
10983
  ).nullish(),
10463
- segments: z30.array(
10464
- z30.union([
10465
- z30.object({
10466
- id: z30.number(),
10467
- seek: z30.number(),
10468
- start: z30.number(),
10469
- end: z30.number(),
10470
- text: z30.string(),
10471
- tokens: z30.array(z30.number()),
10472
- temperature: z30.number(),
10473
- avg_logprob: z30.number(),
10474
- compression_ratio: z30.number(),
10475
- no_speech_prob: z30.number()
10984
+ segments: z34.array(
10985
+ z34.union([
10986
+ z34.object({
10987
+ id: z34.number(),
10988
+ seek: z34.number(),
10989
+ start: z34.number(),
10990
+ end: z34.number(),
10991
+ text: z34.string(),
10992
+ tokens: z34.array(z34.number()),
10993
+ temperature: z34.number(),
10994
+ avg_logprob: z34.number(),
10995
+ compression_ratio: z34.number(),
10996
+ no_speech_prob: z34.number()
10476
10997
  }),
10477
- z30.object({
10478
- type: z30.literal("transcript.text.segment"),
10479
- id: z30.string(),
10480
- start: z30.number(),
10481
- end: z30.number(),
10482
- text: z30.string(),
10483
- speaker: z30.string()
10998
+ z34.object({
10999
+ type: z34.literal("transcript.text.segment"),
11000
+ id: z34.string(),
11001
+ start: z34.number(),
11002
+ end: z34.number(),
11003
+ text: z34.string(),
11004
+ speaker: z34.string()
10484
11005
  })
10485
11006
  ])
10486
11007
  ).nullish()
@@ -10493,60 +11014,60 @@ import {
10493
11014
  lazySchema as lazySchema29,
10494
11015
  zodSchema as zodSchema29
10495
11016
  } from "@ai-sdk/provider-utils";
10496
- import { z as z31 } from "zod/v4";
11017
+ import { z as z35 } from "zod/v4";
10497
11018
  var openAITranscriptionModelOptions = lazySchema29(
10498
11019
  () => zodSchema29(
10499
- z31.object({
11020
+ z35.object({
10500
11021
  /**
10501
11022
  * Additional information to include in the transcription response.
10502
11023
  */
10503
- include: z31.array(z31.string()).optional(),
11024
+ include: z35.array(z35.string()).optional(),
10504
11025
  /**
10505
11026
  * The language of the input audio in ISO-639-1 format.
10506
11027
  */
10507
- language: z31.string().optional(),
11028
+ language: z35.string().optional(),
10508
11029
  /**
10509
11030
  * An optional text to guide the model's style or continue a previous audio segment.
10510
11031
  */
10511
- prompt: z31.string().optional(),
11032
+ prompt: z35.string().optional(),
10512
11033
  /**
10513
11034
  * The sampling temperature, between 0 and 1.
10514
11035
  * @default 0
10515
11036
  */
10516
- temperature: z31.number().min(0).max(1).default(0).optional(),
11037
+ temperature: z35.number().min(0).max(1).default(0).optional(),
10517
11038
  /**
10518
11039
  * The timestamp granularities to populate for this transcription.
10519
11040
  * @default ['segment']
10520
11041
  */
10521
- timestampGranularities: z31.array(z31.enum(["word", "segment"])).default(["segment"]).optional(),
11042
+ timestampGranularities: z35.array(z35.enum(["word", "segment"])).default(["segment"]).optional(),
10522
11043
  /**
10523
11044
  * The format of the transcription response.
10524
11045
  */
10525
- responseFormat: z31.enum(["json", "verbose_json", "diarized_json"]).optional(),
11046
+ responseFormat: z35.enum(["json", "verbose_json", "diarized_json"]).optional(),
10526
11047
  /**
10527
11048
  * Controls how the audio is split into chunks before transcription.
10528
11049
  */
10529
- chunkingStrategy: z31.union([
10530
- z31.literal("auto"),
10531
- z31.object({
10532
- type: z31.literal("server_vad"),
10533
- threshold: z31.number().min(0).max(1).optional(),
10534
- prefixPaddingMs: z31.number().int().min(0).optional(),
10535
- silenceDurationMs: z31.number().int().min(0).optional()
11050
+ chunkingStrategy: z35.union([
11051
+ z35.literal("auto"),
11052
+ z35.object({
11053
+ type: z35.literal("server_vad"),
11054
+ threshold: z35.number().min(0).max(1).optional(),
11055
+ prefixPaddingMs: z35.number().int().min(0).optional(),
11056
+ silenceDurationMs: z35.number().int().min(0).optional()
10536
11057
  })
10537
11058
  ]).optional(),
10538
11059
  /**
10539
11060
  * Options for streaming transcription models such as `gpt-realtime-whisper`.
10540
11061
  */
10541
- streaming: z31.object({
11062
+ streaming: z35.object({
10542
11063
  /**
10543
11064
  * Latency/accuracy tradeoff for realtime transcription.
10544
11065
  */
10545
- delay: z31.enum(["minimal", "low", "medium", "high", "xhigh"]).optional(),
11066
+ delay: z35.enum(["minimal", "low", "medium", "high", "xhigh"]).optional(),
10546
11067
  /**
10547
11068
  * Additional fields to include in realtime transcription events.
10548
11069
  */
10549
- include: z31.array(z31.string()).optional()
11070
+ include: z35.array(z35.string()).optional()
10550
11071
  }).optional()
10551
11072
  })
10552
11073
  )
@@ -10715,7 +11236,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10715
11236
  async doGenerate(options) {
10716
11237
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
10717
11238
  if (isRealtimeTranscriptionModelId(this.modelId)) {
10718
- throw new UnsupportedFunctionalityError8({
11239
+ throw new UnsupportedFunctionalityError11({
10719
11240
  functionality: `non-streaming transcription with ${this.modelId}`
10720
11241
  });
10721
11242
  }
@@ -10733,7 +11254,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10733
11254
  headers: combineHeaders9((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
10734
11255
  formData,
10735
11256
  failedResponseHandler: openaiFailedResponseHandler,
10736
- successfulResponseHandler: createJsonResponseHandler8(
11257
+ successfulResponseHandler: createJsonResponseHandler9(
10737
11258
  openaiTranscriptionResponseSchema
10738
11259
  ),
10739
11260
  abortSignal: options.abortSignal,
@@ -10782,7 +11303,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
10782
11303
  async doStream(options) {
10783
11304
  var _a2, _b, _c, _d, _e, _f, _g;
10784
11305
  if (!isRealtimeTranscriptionModelId(this.modelId)) {
10785
- throw new UnsupportedFunctionalityError8({
11306
+ throw new UnsupportedFunctionalityError11({
10786
11307
  functionality: `streaming transcription with ${this.modelId}`
10787
11308
  });
10788
11309
  }
@@ -11023,7 +11544,7 @@ function getOpenAIRealtimeConnection(headers) {
11023
11544
 
11024
11545
  // src/speech-translation/openai-speech-translation-model.ts
11025
11546
  import {
11026
- InvalidArgumentError as InvalidArgumentError3
11547
+ InvalidArgumentError as InvalidArgumentError5
11027
11548
  } from "@ai-sdk/provider";
11028
11549
  import {
11029
11550
  combineHeaders as combineHeaders10,
@@ -11043,9 +11564,9 @@ import {
11043
11564
  lazySchema as lazySchema30,
11044
11565
  zodSchema as zodSchema30
11045
11566
  } from "@ai-sdk/provider-utils";
11046
- import { z as z32 } from "zod/v4";
11567
+ import { z as z36 } from "zod/v4";
11047
11568
  var openAISpeechTranslationModelOptions = lazySchema30(
11048
- () => zodSchema30(z32.object({}))
11569
+ () => zodSchema30(z36.object({}))
11049
11570
  );
11050
11571
 
11051
11572
  // src/speech-translation/openai-speech-translation-model.ts
@@ -11070,7 +11591,7 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
11070
11591
  async doStream(options) {
11071
11592
  var _a2, _b, _c, _d, _e;
11072
11593
  if (options.targetLanguage == null) {
11073
- throw new InvalidArgumentError3({
11594
+ throw new InvalidArgumentError5({
11074
11595
  argument: "targetLanguage",
11075
11596
  message: `targetLanguage is required for translation model '${this.modelId}'.`
11076
11597
  });
@@ -11310,7 +11831,7 @@ function buildOpenAIRealtimeSpeechTranslationSession({
11310
11831
  }
11311
11832
  function validateOpenAISpeechTranslationInputAudioFormat(inputAudioFormat) {
11312
11833
  if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 24e3) {
11313
- throw new InvalidArgumentError3({
11834
+ throw new InvalidArgumentError5({
11314
11835
  argument: "inputAudioFormat",
11315
11836
  message: "The OpenAI Realtime translation API only supports 24kHz 16-bit PCM input audio."
11316
11837
  });
@@ -11342,33 +11863,33 @@ function getOpenAIRealtimeConnection2(headers) {
11342
11863
  import {
11343
11864
  combineHeaders as combineHeaders11,
11344
11865
  convertInlineFileDataToUint8Array as convertInlineFileDataToUint8Array2,
11345
- createJsonResponseHandler as createJsonResponseHandler9,
11866
+ createJsonResponseHandler as createJsonResponseHandler10,
11346
11867
  postFormDataToApi as postFormDataToApi4
11347
11868
  } from "@ai-sdk/provider-utils";
11348
11869
 
11349
11870
  // src/skills/openai-skills-api.ts
11350
11871
  import { lazySchema as lazySchema31, zodSchema as zodSchema31 } from "@ai-sdk/provider-utils";
11351
- import { z as z33 } from "zod/v4";
11872
+ import { z as z37 } from "zod/v4";
11352
11873
  var openaiSkillResponseSchema = lazySchema31(
11353
11874
  () => zodSchema31(
11354
- z33.object({
11355
- id: z33.string(),
11356
- name: z33.string().nullish(),
11357
- description: z33.string().nullish(),
11358
- default_version: z33.string().nullish(),
11359
- latest_version: z33.string().nullish(),
11360
- created_at: z33.number(),
11361
- updated_at: z33.number().nullish()
11875
+ z37.object({
11876
+ id: z37.string(),
11877
+ name: z37.string().nullish(),
11878
+ description: z37.string().nullish(),
11879
+ default_version: z37.string().nullish(),
11880
+ latest_version: z37.string().nullish(),
11881
+ created_at: z37.number(),
11882
+ updated_at: z37.number().nullish()
11362
11883
  })
11363
11884
  )
11364
11885
  );
11365
11886
  var openaiSkillVersionResponseSchema = lazySchema31(
11366
11887
  () => zodSchema31(
11367
- z33.object({
11368
- id: z33.string(),
11369
- version: z33.string().nullish(),
11370
- name: z33.string().nullish(),
11371
- description: z33.string().nullish()
11888
+ z37.object({
11889
+ id: z37.string(),
11890
+ version: z37.string().nullish(),
11891
+ name: z37.string().nullish(),
11892
+ description: z37.string().nullish()
11372
11893
  })
11373
11894
  )
11374
11895
  );
@@ -11400,7 +11921,7 @@ var OpenAISkills = class {
11400
11921
  headers: combineHeaders11(this.config.headers()),
11401
11922
  formData,
11402
11923
  failedResponseHandler: openaiFailedResponseHandler,
11403
- successfulResponseHandler: createJsonResponseHandler9(
11924
+ successfulResponseHandler: createJsonResponseHandler10(
11404
11925
  openaiSkillResponseSchema
11405
11926
  ),
11406
11927
  fetch: this.config.fetch
@@ -11423,7 +11944,7 @@ var OpenAISkills = class {
11423
11944
  };
11424
11945
 
11425
11946
  // src/version.ts
11426
- var VERSION = true ? "4.0.66" : "0.0.0-test";
11947
+ var VERSION = true ? "4.0.67" : "0.0.0-test";
11427
11948
 
11428
11949
  // src/openai-provider.ts
11429
11950
  function createOpenAI(options = {}) {
@@ -11537,29 +12058,6 @@ function createOpenAI(options = {}) {
11537
12058
  fileIdPrefixes: ["file-"]
11538
12059
  }
11539
12060
  });
11540
- const createRealtimeModel = (modelId) => new OpenAIRealtimeModel(modelId, {
11541
- provider: `${providerName}.realtime`,
11542
- baseURL,
11543
- headers: getHeaders,
11544
- fetch: options.fetch
11545
- });
11546
- const experimentalRealtimeFactory = Object.assign(
11547
- (modelId) => createRealtimeModel(modelId),
11548
- {
11549
- getToken: async (tokenOptions) => {
11550
- const model = createRealtimeModel(tokenOptions.model);
11551
- const secret = await model.doCreateClientSecret({
11552
- sessionConfig: tokenOptions.sessionConfig,
11553
- expiresAfterSeconds: tokenOptions.expiresAfterSeconds
11554
- });
11555
- return {
11556
- token: secret.token,
11557
- url: secret.url,
11558
- expiresAt: secret.expiresAt
11559
- };
11560
- }
11561
- }
11562
- );
11563
12061
  const provider = function(modelId) {
11564
12062
  return createLanguageModel(modelId);
11565
12063
  };
@@ -11583,13 +12081,19 @@ function createOpenAI(options = {}) {
11583
12081
  provider.files = createFiles;
11584
12082
  provider.skills = createSkills;
11585
12083
  provider.experimental_batch = createBatch;
11586
- provider.experimental_realtime = experimentalRealtimeFactory;
12084
+ provider.experimental_realtime = createOpenAIRealtimeFactory({
12085
+ provider: providerName,
12086
+ baseURL,
12087
+ headers: getHeaders,
12088
+ fetch: options.fetch
12089
+ });
11587
12090
  provider.tools = openaiTools;
11588
12091
  return provider;
11589
12092
  }
11590
12093
  var openai = createOpenAI();
11591
12094
  export {
11592
12095
  OpenAIRealtimeModel as Experimental_OpenAIRealtimeModel,
12096
+ OpenAIRealtimeModelLive as Experimental_OpenAIRealtimeModelLive,
11593
12097
  OpenAISpeechTranslationModel as Experimental_OpenAISpeechTranslationModel,
11594
12098
  OpenAISpeechTranslationModel as Experimental_OpenAITranslationModel,
11595
12099
  VERSION,