@ai-sdk/gateway 4.0.0-beta.111 → 4.0.0-beta.113
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 +16 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +44 -22
- package/package.json +3 -3
- package/src/gateway-language-model-settings.ts +1 -0
- package/src/gateway-realtime-model-settings.ts +6 -1
- package/src/gateway-speech-model-settings.ts +4 -1
- package/src/gateway-transcription-model-settings.ts +5 -1
- package/src/gateway-video-model-settings.ts +0 -2
- package/src/gateway-video-model.ts +2 -0
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -251,30 +251,52 @@ const model = gateway.experimental_realtime('openai/gpt-realtime-2');
|
|
|
251
251
|
|
|
252
252
|
The Gateway normalizes realtime the same way it normalizes every other modality: your client speaks the [normalized AI SDK realtime protocol](/docs/ai-sdk-core/realtime) and the Gateway translates to and from the upstream provider server-side. This means the same client code works regardless of which provider backs the model.
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
Realtime sessions run in the browser and require a short-lived Gateway client secret created on your server with `gateway.experimental_realtime.getToken()`. The method uses your Gateway credential (`apiKey`, `AI_GATEWAY_API_KEY`, or Vercel OIDC token) to mint a `vcst_` client secret and returns the WebSocket URL for the model.
|
|
255
255
|
|
|
256
|
-
```ts
|
|
257
|
-
import { gateway } from '
|
|
256
|
+
```ts filename='app/api/realtime/setup/route.ts'
|
|
257
|
+
import { gateway } from 'ai';
|
|
258
258
|
|
|
259
|
-
|
|
260
|
-
const token = await gateway.experimental_realtime.getToken({
|
|
261
|
-
|
|
262
|
-
|
|
259
|
+
export async function POST() {
|
|
260
|
+
const token = await gateway.experimental_realtime.getToken({
|
|
261
|
+
model: 'openai/gpt-realtime-2',
|
|
262
|
+
expiresAfterSeconds: 60 * 10,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
return Response.json(token);
|
|
266
|
+
}
|
|
263
267
|
```
|
|
264
268
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
269
|
+
Use the matching Gateway realtime model in the browser. Creating the model is
|
|
270
|
+
safe in browser code; only `getToken()` is server-side.
|
|
271
|
+
|
|
272
|
+
```tsx filename='app/realtime/page.tsx'
|
|
273
|
+
'use client';
|
|
274
|
+
|
|
275
|
+
import { experimental_useRealtime } from '@ai-sdk/react';
|
|
276
|
+
import { gateway } from 'ai';
|
|
277
|
+
|
|
278
|
+
export default function RealtimePage() {
|
|
279
|
+
const realtime = experimental_useRealtime({
|
|
280
|
+
model: gateway.experimental_realtime('openai/gpt-realtime-2'),
|
|
281
|
+
api: {
|
|
282
|
+
token: '/api/realtime/setup',
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// ...
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Do not expose your Gateway API key or OIDC token to browser clients. Only return
|
|
291
|
+
the short-lived setup response from `getToken()`.
|
|
270
292
|
|
|
271
293
|
<Note>
|
|
272
|
-
The Gateway WebSocket route transports auth via the
|
|
273
|
-
`Sec-WebSocket-Protocol` subprotocol and the model id via the
|
|
274
|
-
query - the WebSocket transport of the `Authorization` and
|
|
275
|
-
headers the HTTP routes use. Subprotocol values must fit the
|
|
276
|
-
grammar, and the complete `Sec-WebSocket-Protocol` header
|
|
277
|
-
(under an 8 KiB safe header budget).
|
|
294
|
+
The Gateway WebSocket route transports the short-lived auth token via the
|
|
295
|
+
versioned `Sec-WebSocket-Protocol` subprotocol and the model id via the
|
|
296
|
+
`?ai-model-id=` query - the WebSocket transport of the `Authorization` and
|
|
297
|
+
`ai-model-id` headers the HTTP routes use. Subprotocol values must fit the
|
|
298
|
+
WebSocket token grammar, and the complete `Sec-WebSocket-Protocol` header
|
|
299
|
+
should stay compact (under an 8 KiB safe header budget).
|
|
278
300
|
</Note>
|
|
279
301
|
|
|
280
302
|
### Provider Options
|
|
@@ -298,10 +320,10 @@ const sessionConfig = {
|
|
|
298
320
|
The `GatewayProviderOptions` type is exported from `@ai-sdk/gateway` for stable client-facing fields. The type also accepts service-owned option keys so the Gateway service can add or change server-side options without requiring an SDK release for every schema change. Runtime validation is owned by the Gateway service.
|
|
299
321
|
|
|
300
322
|
<Note>
|
|
301
|
-
Provider options are sent in the
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
`
|
|
323
|
+
Provider options are sent in the initial session update after the socket
|
|
324
|
+
opens, so connect-time options such as `byok` and quota selection require a
|
|
325
|
+
Gateway that resolves them from that update. Routing knobs like `order` /
|
|
326
|
+
`only` do not apply to realtime, where the Gateway selects the
|
|
305
327
|
WebSocket-capable provider.
|
|
306
328
|
</Note>
|
|
307
329
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/gateway",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.113",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@vercel/oidc": "3.2.0",
|
|
34
|
-
"@ai-sdk/provider": "4.0.0-beta.
|
|
35
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
34
|
+
"@ai-sdk/provider": "4.0.0-beta.20",
|
|
35
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.50"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "22.19.19",
|
|
@@ -7,8 +7,6 @@ export type GatewayVideoModelId =
|
|
|
7
7
|
| 'alibaba/wan-v2.6-t2v'
|
|
8
8
|
| 'bytedance/seedance-2.0'
|
|
9
9
|
| 'bytedance/seedance-2.0-fast'
|
|
10
|
-
| 'bytedance/seedance-v1.0-lite-i2v'
|
|
11
|
-
| 'bytedance/seedance-v1.0-lite-t2v'
|
|
12
10
|
| 'bytedance/seedance-v1.0-pro'
|
|
13
11
|
| 'bytedance/seedance-v1.0-pro-fast'
|
|
14
12
|
| 'bytedance/seedance-v1.5-pro'
|
|
@@ -46,6 +46,7 @@ export class GatewayVideoModel implements Experimental_VideoModelV4 {
|
|
|
46
46
|
duration,
|
|
47
47
|
fps,
|
|
48
48
|
seed,
|
|
49
|
+
generateAudio,
|
|
49
50
|
image,
|
|
50
51
|
providerOptions,
|
|
51
52
|
headers,
|
|
@@ -81,6 +82,7 @@ export class GatewayVideoModel implements Experimental_VideoModelV4 {
|
|
|
81
82
|
...(duration && { duration }),
|
|
82
83
|
...(fps && { fps }),
|
|
83
84
|
...(seed && { seed }),
|
|
85
|
+
...(generateAudio !== undefined && { generateAudio }),
|
|
84
86
|
...(providerOptions && { providerOptions }),
|
|
85
87
|
...(image && { image: maybeEncodeVideoFile(image) }),
|
|
86
88
|
},
|