function realtimeToken(options): Promise<RealtimeToken>;
Defined in: realtime/index.ts:33
Generate a realtime token using the provided adapter.
This function is used on the server to generate ephemeral tokens that clients can use to establish realtime connections. The token contains authentication credentials and session configuration, and is typically short-lived (e.g., 10 minutes for OpenAI, 30 minutes for ElevenLabs).
Token generation options including the provider-specific adapter.
Promise<RealtimeToken>
A token containing the provider credentials, expiration, and session config.
import { realtimeToken } from '@tanstack/ai'
import { openaiRealtimeToken } from '@tanstack/ai-openai'
const token = await realtimeToken({
adapter: openaiRealtimeToken({
model: 'gpt-4o-realtime-preview',
}),
})
import { realtimeToken } from '@tanstack/ai'
import { elevenlabsRealtimeToken } from '@tanstack/ai-elevenlabs'
const token = await realtimeToken({
adapter: elevenlabsRealtimeToken({
agentId: 'your-agent-id',
}),
})
import { createServerFn } from '@tanstack/react-start'
import { realtimeToken } from '@tanstack/ai'
import { openaiRealtimeToken } from '@tanstack/ai-openai'
export const getRealtimeToken = createServerFn({ method: 'POST' })
.handler(async () => {
return realtimeToken({
adapter: openaiRealtimeToken({
model: 'gpt-4o-realtime-preview',
}),
})
})