Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

realtimeToken.md

42 lines1.0 KB

1---
2id: realtimeToken
3title: realtimeToken
4---
5​
6```ts
7function realtimeToken(options): Promise<RealtimeToken>;
8```
9​
10Defined in: [packages/ai/src/realtime/index.ts:29](https://github.com/TanStack/ai/blob/main/packages/ai/src/realtime/index.ts#L29)
11​
12Generate a realtime token using the provided adapter.
13​
14This function is used on the server to generate ephemeral tokens
15that clients can use to establish realtime connections.
16​
17## Parameters
18​
19### options
20​
21[`RealtimeTokenOptions`](../interfaces/RealtimeTokenOptions.md)
22​
23Token generation options including the adapter
24​
25## Returns
26​
27`Promise`\<[`RealtimeToken`](../interfaces/RealtimeToken.md)\>
28​
29Promise resolving to a RealtimeToken
30​
31## Example
32​
33```typescript
34import { realtimeToken } from '@tanstack/ai'
35import { openaiRealtimeToken } from '@tanstack/ai-openai'
36​
37// On the server (e.g. inside a server route or framework server
38// function), mint an ephemeral token for the client:
39const token = await realtimeToken({
40 adapter: openaiRealtimeToken({ model: 'gpt-realtime-2.1' }),
41})
42```