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

realtimeToken.md

50 lines1.2 KB

1---
2id: realtimeToken
3title: realtimeToken
4---
5​
6# Function: realtimeToken()
7​
8```ts
9function realtimeToken(options): Promise<RealtimeToken>;
10```
11​
12Defined in: [packages/typescript/ai/src/realtime/index.ts:33](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/realtime/index.ts#L33)
13​
14Generate a realtime token using the provided adapter.
15​
16This function is used on the server to generate ephemeral tokens
17that clients can use to establish realtime connections.
18​
19## Parameters
20​
21### options
22​
23[`RealtimeTokenOptions`](../interfaces/RealtimeTokenOptions.md)
24​
25Token generation options including the adapter
26​
27## Returns
28​
29`Promise`\<[`RealtimeToken`](../interfaces/RealtimeToken.md)\>
30​
31Promise resolving to a RealtimeToken
32​
33## Example
34​
35```typescript
36import { realtimeToken } from '@tanstack/ai'
37import { openaiRealtimeToken } from '@tanstack/ai-openai'
38​
39// Server function (TanStack Start example)
40export const getRealtimeToken = createServerFn()
41 .handler(async () => {
42 return realtimeToken({
43 adapter: openaiRealtimeToken({
44 model: 'gpt-4o-realtime-preview',
45 voice: 'alloy',
46 instructions: 'You are a helpful assistant...',
47 }),
48 })
49 })
50```