@ai-sdk/gateway 4.0.151 → 4.0.153
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 +18 -0
- package/dist/index.d.ts +173 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +323 -30
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +66 -0
- package/package.json +1 -1
- package/src/gateway-batch.ts +3 -2
- package/src/gateway-decision-model.ts +3 -2
- package/src/gateway-embedding-model.ts +3 -2
- package/src/gateway-extraction-model.ts +3 -2
- package/src/gateway-image-model.ts +3 -2
- package/src/gateway-language-model.ts +4 -1
- package/src/gateway-model-catalog.ts +3 -3
- package/src/gateway-provider.ts +84 -17
- package/src/gateway-realtime-model-live.ts +385 -0
- package/src/gateway-realtime-model-settings.ts +16 -0
- package/src/gateway-reranking-model.ts +3 -2
- package/src/gateway-speech-model.ts +22 -20
- package/src/gateway-transcription-model.ts +14 -12
- package/src/gateway-video-model.ts +6 -3
- package/src/index.ts +6 -1
- package/src/redact-gateway-request-credentials.ts +88 -0
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -661,6 +661,72 @@ the short-lived setup response from `getToken()`.
|
|
|
661
661
|
should stay compact (under an 8 KiB safe header budget).
|
|
662
662
|
</Note>
|
|
663
663
|
|
|
664
|
+
### Live Models
|
|
665
|
+
|
|
666
|
+
Live models such as `openai/gpt-live-1.1` hold one continuous conversation: a
|
|
667
|
+
`session-start` event opens the session, PCM16 audio streams in both directions,
|
|
668
|
+
and `session-close` ends it with final usage. `gateway.experimental_realtime()`
|
|
669
|
+
returns a Live model for known Live model IDs. It connects to the Gateway Live
|
|
670
|
+
route and speaks the normalized Live protocol. Pass `{ api: 'live' }` for a Live
|
|
671
|
+
model ID the SDK does not know yet, or `{ api: 'realtime' }` to force the
|
|
672
|
+
realtime route.
|
|
673
|
+
|
|
674
|
+
```ts
|
|
675
|
+
import { gateway } from '@ai-sdk/gateway';
|
|
676
|
+
|
|
677
|
+
const live = gateway.experimental_realtime('openai/gpt-live-1.1');
|
|
678
|
+
const newerLive = gateway.experimental_realtime('openai/gpt-live-2', {
|
|
679
|
+
api: 'live',
|
|
680
|
+
});
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
`getToken()` mints a client secret bound to the Live route for Live models, so
|
|
684
|
+
the browser can connect straight to the Gateway:
|
|
685
|
+
|
|
686
|
+
```ts filename='app/api/live/setup/route.ts'
|
|
687
|
+
import { gateway } from '@ai-sdk/gateway';
|
|
688
|
+
|
|
689
|
+
export async function POST() {
|
|
690
|
+
const token = await gateway.experimental_realtime.getToken({
|
|
691
|
+
model: 'openai/gpt-live-1.1',
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
return Response.json(token);
|
|
695
|
+
}
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
```tsx filename='app/live/page.tsx'
|
|
699
|
+
'use client';
|
|
700
|
+
|
|
701
|
+
import { gateway } from '@ai-sdk/gateway';
|
|
702
|
+
import { experimental_useRealtime } from '@ai-sdk/react';
|
|
703
|
+
|
|
704
|
+
const model = gateway.experimental_realtime('openai/gpt-live-1.1');
|
|
705
|
+
|
|
706
|
+
export default function LivePage() {
|
|
707
|
+
const live = experimental_useRealtime({
|
|
708
|
+
model,
|
|
709
|
+
api: { token: '/api/live/setup' },
|
|
710
|
+
sessionConfig: { instructions: 'Keep replies brief.' },
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
// live.connect(), live.close(), live.session?.usage, ...
|
|
714
|
+
}
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
Live sessions accept `instructions`, `voice`, `inputAudioFormat`,
|
|
718
|
+
`outputAudioFormat` and `providerOptions` (`gateway`, and `openai` with
|
|
719
|
+
`delegation`, `input`, `store` and `voice`). Audio is `audio/pcm` at 16000 or
|
|
720
|
+
24000 Hz, with the same format in both directions. Live uses client delegation:
|
|
721
|
+
your application submits context with `context-append` instead of the
|
|
722
|
+
turn-based tool loop, and `sendTextMessage()` and `addToolOutput()` are not
|
|
723
|
+
available. Live model IDs must be fully qualified (`creator/model-name`).
|
|
724
|
+
|
|
725
|
+
<Note>
|
|
726
|
+
Live through the Gateway provider uses WebSocket only. For WebRTC, use
|
|
727
|
+
`@ai-sdk/openai` directly. Responses delegation is not supported.
|
|
728
|
+
</Note>
|
|
729
|
+
|
|
664
730
|
### Provider Options
|
|
665
731
|
|
|
666
732
|
Gateway [provider options](#gateway-provider-options) — `tags`, `user`, `byok`, compliance flags, and so on — are set under `providerOptions.gateway` in the **session configuration**, mirroring how they ride the request body on the non-realtime routes. Include them in the session configuration you send to the Gateway, and the Gateway applies them server-side:
|
package/package.json
CHANGED
package/src/gateway-batch.ts
CHANGED
|
@@ -31,6 +31,7 @@ import type { GatewayChatConfig } from './gateway-language-model';
|
|
|
31
31
|
import type { GatewayModelId } from './gateway-language-model-settings';
|
|
32
32
|
import { asGatewayError } from './errors';
|
|
33
33
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
34
|
+
import { withGatewayRequestTelemetryRedaction } from './redact-gateway-request-credentials';
|
|
34
35
|
|
|
35
36
|
export class GatewayBatch implements BatchV4<{ text: GatewayModelId }> {
|
|
36
37
|
readonly specificationVersion = 'v4' as const;
|
|
@@ -81,7 +82,7 @@ export class GatewayBatch implements BatchV4<{ text: GatewayModelId }> {
|
|
|
81
82
|
? { 'idempotency-key': idempotencyKey }
|
|
82
83
|
: undefined,
|
|
83
84
|
),
|
|
84
|
-
body: {
|
|
85
|
+
body: withGatewayRequestTelemetryRedaction({
|
|
85
86
|
...(webhookUrl != null && { callbackUrl: webhookUrl }),
|
|
86
87
|
requests: requests.map(request => ({
|
|
87
88
|
id: request.id,
|
|
@@ -92,7 +93,7 @@ export class GatewayBatch implements BatchV4<{ text: GatewayModelId }> {
|
|
|
92
93
|
...(forwardedProviderOptions != null && {
|
|
93
94
|
providerOptions: forwardedProviderOptions,
|
|
94
95
|
}),
|
|
95
|
-
},
|
|
96
|
+
}),
|
|
96
97
|
successfulResponseHandler: createJsonResponseHandler(
|
|
97
98
|
gatewayBatchStartResponseSchema,
|
|
98
99
|
),
|
|
@@ -20,6 +20,7 @@ import { parseAuthMethod } from './errors/parse-auth-method';
|
|
|
20
20
|
import type { GatewayConfig } from './gateway-config';
|
|
21
21
|
import { gatewayDecisionProviderOptionsSchema } from './gateway-provider-options';
|
|
22
22
|
import { gatewayWarningSchema } from './gateway-warning-schema';
|
|
23
|
+
import { withGatewayRequestTelemetryRedaction } from './redact-gateway-request-credentials';
|
|
23
24
|
import { toGatewayStateParts } from './to-gateway-state-parts';
|
|
24
25
|
|
|
25
26
|
export class GatewayDecisionModel implements DecisionModelV4 {
|
|
@@ -81,7 +82,7 @@ export class GatewayDecisionModel implements DecisionModelV4 {
|
|
|
81
82
|
this.getModelConfigHeaders(),
|
|
82
83
|
await resolve(this.config.o11yHeaders),
|
|
83
84
|
),
|
|
84
|
-
body: {
|
|
85
|
+
body: withGatewayRequestTelemetryRedaction({
|
|
85
86
|
stateParts,
|
|
86
87
|
questions,
|
|
87
88
|
maxOutputTokens,
|
|
@@ -89,7 +90,7 @@ export class GatewayDecisionModel implements DecisionModelV4 {
|
|
|
89
90
|
...(validatedProviderOptions
|
|
90
91
|
? { providerOptions: validatedProviderOptions }
|
|
91
92
|
: {}),
|
|
92
|
-
},
|
|
93
|
+
}),
|
|
93
94
|
successfulResponseHandler: createJsonResponseHandler(
|
|
94
95
|
gatewayDecisionResponseSchema,
|
|
95
96
|
),
|
|
@@ -20,6 +20,7 @@ import { z } from './zod';
|
|
|
20
20
|
import { asGatewayError } from './errors';
|
|
21
21
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
22
22
|
import type { GatewayConfig } from './gateway-config';
|
|
23
|
+
import { withGatewayRequestTelemetryRedaction } from './redact-gateway-request-credentials';
|
|
23
24
|
|
|
24
25
|
type GatewayEmbeddingConfig = GatewayConfig & {
|
|
25
26
|
provider: string;
|
|
@@ -79,11 +80,11 @@ export class GatewayEmbeddingModel implements EmbeddingModelV4 {
|
|
|
79
80
|
this.getModelConfigHeaders(),
|
|
80
81
|
await resolve(this.config.o11yHeaders),
|
|
81
82
|
),
|
|
82
|
-
body: {
|
|
83
|
+
body: withGatewayRequestTelemetryRedaction({
|
|
83
84
|
values,
|
|
84
85
|
dimensions,
|
|
85
86
|
...(providerOptions ? { providerOptions } : {}),
|
|
86
|
-
},
|
|
87
|
+
}),
|
|
87
88
|
successfulResponseHandler: createJsonResponseHandler(
|
|
88
89
|
gatewayEmbeddingResponseSchema,
|
|
89
90
|
),
|
|
@@ -23,6 +23,7 @@ import { extractApiCallResponse } from './errors/extract-api-call-response';
|
|
|
23
23
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
24
24
|
import type { GatewayConfig } from './gateway-config';
|
|
25
25
|
import { gatewayWarningSchema } from './gateway-warning-schema';
|
|
26
|
+
import { withGatewayRequestTelemetryRedaction } from './redact-gateway-request-credentials';
|
|
26
27
|
import { toGatewayStateParts } from './to-gateway-state-parts';
|
|
27
28
|
|
|
28
29
|
export class GatewayExtractionModel implements ExtractionModelV4 {
|
|
@@ -84,14 +85,14 @@ export class GatewayExtractionModel implements ExtractionModelV4 {
|
|
|
84
85
|
this.getModelConfigHeaders(),
|
|
85
86
|
await resolve(this.config.o11yHeaders),
|
|
86
87
|
),
|
|
87
|
-
body: {
|
|
88
|
+
body: withGatewayRequestTelemetryRedaction({
|
|
88
89
|
stateParts,
|
|
89
90
|
fields,
|
|
90
91
|
referenceDate,
|
|
91
92
|
maxOutputTokens,
|
|
92
93
|
reasoning,
|
|
93
94
|
...(providerOptions ? { providerOptions } : {}),
|
|
94
|
-
},
|
|
95
|
+
}),
|
|
95
96
|
successfulResponseHandler: createJsonResponseHandler(
|
|
96
97
|
gatewayExtractionResponseSchema,
|
|
97
98
|
),
|
|
@@ -23,6 +23,7 @@ import { z } from './zod';
|
|
|
23
23
|
import type { GatewayConfig } from './gateway-config';
|
|
24
24
|
import { asGatewayError } from './errors';
|
|
25
25
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
26
|
+
import { withGatewayRequestTelemetryRedaction } from './redact-gateway-request-credentials';
|
|
26
27
|
|
|
27
28
|
type GatewayImageConfig = GatewayConfig & {
|
|
28
29
|
provider: string;
|
|
@@ -104,7 +105,7 @@ export class GatewayImageModel implements ImageModelV4 {
|
|
|
104
105
|
this.getModelConfigHeaders(),
|
|
105
106
|
await resolve(this.config.o11yHeaders),
|
|
106
107
|
),
|
|
107
|
-
body: {
|
|
108
|
+
body: withGatewayRequestTelemetryRedaction({
|
|
108
109
|
prompt,
|
|
109
110
|
n,
|
|
110
111
|
...(size && { size }),
|
|
@@ -117,7 +118,7 @@ export class GatewayImageModel implements ImageModelV4 {
|
|
|
117
118
|
files: files.map(file => maybeEncodeImageFile(file)),
|
|
118
119
|
}),
|
|
119
120
|
...(mask && { mask: maybeEncodeImageFile(mask) }),
|
|
120
|
-
},
|
|
121
|
+
}),
|
|
121
122
|
successfulResponseHandler: createJsonResponseHandler(
|
|
122
123
|
gatewayImageResponseSchema,
|
|
123
124
|
streamingImageDecoding
|
|
@@ -24,6 +24,7 @@ import type { GatewayConfig } from './gateway-config';
|
|
|
24
24
|
import type { GatewayModelId } from './gateway-language-model-settings';
|
|
25
25
|
import { asGatewayError } from './errors';
|
|
26
26
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
27
|
+
import { withGatewayRequestTelemetryRedaction } from './redact-gateway-request-credentials';
|
|
27
28
|
|
|
28
29
|
export type GatewayChatConfig = GatewayConfig & {
|
|
29
30
|
provider: string;
|
|
@@ -61,7 +62,9 @@ export class GatewayLanguageModel implements LanguageModelV4 {
|
|
|
61
62
|
const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
|
|
62
63
|
|
|
63
64
|
return {
|
|
64
|
-
args:
|
|
65
|
+
args: withGatewayRequestTelemetryRedaction(
|
|
66
|
+
this.maybeEncodeFileParts(optionsWithoutSignal),
|
|
67
|
+
),
|
|
65
68
|
warnings: [],
|
|
66
69
|
};
|
|
67
70
|
}
|
|
@@ -288,7 +288,6 @@ export const gatewayModelIds = {
|
|
|
288
288
|
'spacexai/grok-4.5',
|
|
289
289
|
'spacexai/grok-4.6',
|
|
290
290
|
'spacexai/grok-4.7',
|
|
291
|
-
'spacexai/grok-build-0.1',
|
|
292
291
|
'stealth/glyph-cluster',
|
|
293
292
|
'stepfun/step-3.7-flash',
|
|
294
293
|
'stepfun/step-5-preview',
|
|
@@ -368,6 +367,7 @@ export const gatewayModelIds = {
|
|
|
368
367
|
'liquid/d1.2-ultra',
|
|
369
368
|
'microsoft/decision-1.1',
|
|
370
369
|
'microsoft/microsoft-decision-1',
|
|
370
|
+
'modaic/mo',
|
|
371
371
|
'nace-ai/drex-max-finance',
|
|
372
372
|
'nace-ai/drex-max-v1.1',
|
|
373
373
|
'nace-ai/drex-v2.0',
|
|
@@ -382,7 +382,7 @@ export const gatewayModelIds = {
|
|
|
382
382
|
'typesafe-ai/jev-1.13.0',
|
|
383
383
|
'typesafe-ai/jev-1.14.0',
|
|
384
384
|
],
|
|
385
|
-
extraction: [],
|
|
385
|
+
extraction: ['scaledown/extract-1'],
|
|
386
386
|
image: [
|
|
387
387
|
'bfl/flux-2-flex',
|
|
388
388
|
'bfl/flux-2-klein-4b',
|
|
@@ -415,7 +415,6 @@ export const gatewayModelIds = {
|
|
|
415
415
|
'openai/gpt-image-2.5-sunburst',
|
|
416
416
|
'openai/gpt-image-2.6-flare',
|
|
417
417
|
'openai/gpt-image-2.6-sunburst',
|
|
418
|
-
'prodia/flux-fast-schnell',
|
|
419
418
|
'recraft/recraft-v2',
|
|
420
419
|
'recraft/recraft-v3',
|
|
421
420
|
'recraft/recraft-v4',
|
|
@@ -474,6 +473,7 @@ export const gatewayModelIds = {
|
|
|
474
473
|
'google/gemini-3.8-live',
|
|
475
474
|
'google/gemini-3.8-live-extended-thinking',
|
|
476
475
|
'openai/gpt-live-1',
|
|
476
|
+
'openai/gpt-live-1.1',
|
|
477
477
|
'openai/gpt-realtime-1.5',
|
|
478
478
|
'openai/gpt-realtime-2',
|
|
479
479
|
'openai/gpt-realtime-2.1',
|
package/src/gateway-provider.ts
CHANGED
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
GatewayTranscriptionModel,
|
|
49
49
|
toGatewayTranscriptionUrl,
|
|
50
50
|
} from './gateway-transcription-model';
|
|
51
|
+
import { GatewayRealtimeModelLive } from './gateway-realtime-model-live';
|
|
51
52
|
import { GatewayRealtimeModel } from './gateway-realtime-model';
|
|
52
53
|
import type { GatewayEmbeddingModelId } from './gateway-embedding-model-settings';
|
|
53
54
|
import type { GatewayDecisionModelId } from './gateway-decision-model-settings';
|
|
@@ -56,12 +57,18 @@ import type { GatewayImageModelId } from './gateway-image-model-settings';
|
|
|
56
57
|
import type { GatewayRerankingModelId } from './gateway-reranking-model-settings';
|
|
57
58
|
import type { GatewaySpeechModelId } from './gateway-speech-model-settings';
|
|
58
59
|
import type { GatewayTranscriptionModelId } from './gateway-transcription-model-settings';
|
|
59
|
-
import
|
|
60
|
+
import {
|
|
61
|
+
gatewayLiveModelIds,
|
|
62
|
+
type GatewayKnownLiveModelId,
|
|
63
|
+
type GatewayRealtimeModelId,
|
|
64
|
+
type GatewayRealtimeOptions,
|
|
65
|
+
} from './gateway-realtime-model-settings';
|
|
60
66
|
import type { GatewayVideoModelId } from './gateway-video-model-settings';
|
|
61
67
|
import { gatewayTools } from './gateway-tools';
|
|
62
68
|
import { getVercelOidcToken, getVercelRequestId } from './vercel-environment';
|
|
63
69
|
import type { GatewayModelId } from './gateway-language-model-settings';
|
|
64
70
|
import {
|
|
71
|
+
InvalidArgumentError,
|
|
65
72
|
LoadAPIKeyError,
|
|
66
73
|
type EmbeddingModelV4,
|
|
67
74
|
type Experimental_BatchV4 as BatchV4,
|
|
@@ -75,6 +82,8 @@ import {
|
|
|
75
82
|
type Experimental_StreamingSpeechModelV4,
|
|
76
83
|
type Experimental_RealtimeFactoryV4 as RealtimeFactoryV4,
|
|
77
84
|
type Experimental_RealtimeFactoryV4GetTokenOptions as RealtimeFactoryV4GetTokenOptions,
|
|
85
|
+
type Experimental_RealtimeFactoryV4GetTokenResult as RealtimeFactoryV4GetTokenResult,
|
|
86
|
+
type Experimental_RealtimeModelV4 as RealtimeModelV4,
|
|
78
87
|
type ProviderV4,
|
|
79
88
|
type LanguageModelV4,
|
|
80
89
|
} from '@ai-sdk/provider';
|
|
@@ -223,9 +232,10 @@ export interface GatewayProvider extends ProviderV4 {
|
|
|
223
232
|
|
|
224
233
|
/**
|
|
225
234
|
* Creates an experimental realtime model for bidirectional audio/text
|
|
226
|
-
* communication over WebSocket, normalized through the AI Gateway.
|
|
235
|
+
* communication over WebSocket, normalized through the AI Gateway. Known
|
|
236
|
+
* Live model IDs return a continuous Live model; `{ api }` overrides routing.
|
|
227
237
|
*/
|
|
228
|
-
experimental_realtime:
|
|
238
|
+
experimental_realtime: GatewayRealtimeFactory;
|
|
229
239
|
|
|
230
240
|
/**
|
|
231
241
|
* Experimental streaming-transcription entry point. Callable like
|
|
@@ -249,6 +259,28 @@ export interface GatewayProvider extends ProviderV4 {
|
|
|
249
259
|
tools: typeof gatewayTools;
|
|
250
260
|
}
|
|
251
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Realtime factory: returns a turn-based realtime model or, for Live model IDs
|
|
264
|
+
* or `{ api: 'live' }`, a continuous Live model. `getToken` mints a client
|
|
265
|
+
* secret bound to the matching Gateway WebSocket route.
|
|
266
|
+
*/
|
|
267
|
+
export interface GatewayRealtimeFactory extends RealtimeFactoryV4 {
|
|
268
|
+
(modelId: string, options: { api: 'live' }): GatewayRealtimeModelLive;
|
|
269
|
+
(modelId: string, options: { api: 'realtime' }): GatewayRealtimeModel;
|
|
270
|
+
(
|
|
271
|
+
modelId: GatewayKnownLiveModelId,
|
|
272
|
+
options?: { api?: undefined },
|
|
273
|
+
): GatewayRealtimeModelLive;
|
|
274
|
+
(
|
|
275
|
+
modelId: GatewayRealtimeModelId,
|
|
276
|
+
options?: GatewayRealtimeOptions,
|
|
277
|
+
): RealtimeModelV4;
|
|
278
|
+
|
|
279
|
+
getToken(
|
|
280
|
+
options: RealtimeFactoryV4GetTokenOptions & GatewayRealtimeOptions,
|
|
281
|
+
): Promise<RealtimeFactoryV4GetTokenResult>;
|
|
282
|
+
}
|
|
283
|
+
|
|
252
284
|
export type GatewayTranscriptionFactoryGetTokenOptions = {
|
|
253
285
|
model: GatewayTranscriptionModelId;
|
|
254
286
|
/** Token lifetime in seconds. Gateway default is 60s (max 300s). */
|
|
@@ -461,7 +493,7 @@ export function createGateway(
|
|
|
461
493
|
const mintClientSecret = async (params: {
|
|
462
494
|
modelId: string;
|
|
463
495
|
expiresAfterSeconds?: number;
|
|
464
|
-
routeKind?: 'speech' | 'transcription';
|
|
496
|
+
routeKind?: 'live' | 'speech' | 'transcription';
|
|
465
497
|
}): Promise<{ token: string; expiresAt?: number }> => {
|
|
466
498
|
assertGatewayClientSecretServerEnvironment();
|
|
467
499
|
const auth = await getRealtimeAuthToken();
|
|
@@ -792,20 +824,36 @@ export function createGateway(
|
|
|
792
824
|
// needs to drive the transport with a server-minted client secret. The
|
|
793
825
|
// server-only boundary is enforced on minting itself (`mintClientSecret`),
|
|
794
826
|
// which requires the Gateway credential.
|
|
795
|
-
const createRealtimeModel = (
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
827
|
+
const createRealtimeModel = (
|
|
828
|
+
modelId: GatewayRealtimeModelId,
|
|
829
|
+
realtimeOptions?: GatewayRealtimeOptions,
|
|
830
|
+
) =>
|
|
831
|
+
resolveGatewayRealtimeApi(modelId, realtimeOptions) === 'live'
|
|
832
|
+
? new GatewayRealtimeModelLive(modelId, {
|
|
833
|
+
provider: 'gateway.live',
|
|
834
|
+
baseURL,
|
|
835
|
+
teamIdOrSlug: options.teamIdOrSlug,
|
|
836
|
+
createClientSecret: mintClientSecret,
|
|
837
|
+
getHeaders,
|
|
838
|
+
})
|
|
839
|
+
: new GatewayRealtimeModel(modelId, {
|
|
840
|
+
provider: 'gateway.realtime',
|
|
841
|
+
baseURL,
|
|
842
|
+
teamIdOrSlug: options.teamIdOrSlug,
|
|
843
|
+
createClientSecret: mintClientSecret,
|
|
844
|
+
getHeaders,
|
|
845
|
+
});
|
|
803
846
|
provider.experimental_realtime = Object.assign(
|
|
804
|
-
(
|
|
847
|
+
(
|
|
848
|
+
modelId: GatewayRealtimeModelId,
|
|
849
|
+
realtimeOptions?: GatewayRealtimeOptions,
|
|
850
|
+
) => createRealtimeModel(modelId, realtimeOptions),
|
|
805
851
|
{
|
|
806
|
-
getToken: async (
|
|
807
|
-
|
|
808
|
-
|
|
852
|
+
getToken: async (
|
|
853
|
+
tokenOptions: RealtimeFactoryV4GetTokenOptions & GatewayRealtimeOptions,
|
|
854
|
+
) => {
|
|
855
|
+
const { model: modelId, api, ...secretOptions } = tokenOptions;
|
|
856
|
+
const model = createRealtimeModel(modelId, { api });
|
|
809
857
|
const secret = await model.doCreateClientSecret(secretOptions);
|
|
810
858
|
return {
|
|
811
859
|
token: secret.token,
|
|
@@ -814,7 +862,7 @@ export function createGateway(
|
|
|
814
862
|
};
|
|
815
863
|
},
|
|
816
864
|
},
|
|
817
|
-
) as
|
|
865
|
+
) as GatewayRealtimeFactory;
|
|
818
866
|
|
|
819
867
|
provider.chat = provider.languageModel;
|
|
820
868
|
provider.embedding = provider.embeddingModel;
|
|
@@ -876,6 +924,25 @@ export async function getGatewayAuthToken(
|
|
|
876
924
|
};
|
|
877
925
|
}
|
|
878
926
|
|
|
927
|
+
function resolveGatewayRealtimeApi(
|
|
928
|
+
modelId: string,
|
|
929
|
+
options?: GatewayRealtimeOptions,
|
|
930
|
+
): 'live' | 'realtime' {
|
|
931
|
+
const api = options?.api;
|
|
932
|
+
if (api !== undefined) {
|
|
933
|
+
if (api !== 'live' && api !== 'realtime') {
|
|
934
|
+
throw new InvalidArgumentError({
|
|
935
|
+
argument: 'api',
|
|
936
|
+
message: 'AI Gateway realtime api must be "live" or "realtime".',
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
return api;
|
|
940
|
+
}
|
|
941
|
+
return (gatewayLiveModelIds as readonly string[]).includes(modelId)
|
|
942
|
+
? 'live'
|
|
943
|
+
: 'realtime';
|
|
944
|
+
}
|
|
945
|
+
|
|
879
946
|
function assertGatewayClientSecretServerEnvironment(): void {
|
|
880
947
|
if (typeof globalThis.window !== 'undefined') {
|
|
881
948
|
throw new Error(
|