Docs
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
Persistence (Advanced)
Embeddings
Reranking
Evaluate
Sandboxes (Advanced)
Class References
Function References
Interface References
Type Alias References
Variable References
Function References

realtimeToken

ts
function realtimeToken(options): Promise<RealtimeToken>;
function realtimeToken(options): Promise<RealtimeToken>;

Defined in: packages/ai/src/realtime/index.ts:29

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.

Parameters

options

RealtimeTokenOptions

Token generation options including the adapter

Returns

Promise<RealtimeToken>

Promise resolving to a RealtimeToken

Example

typescript
import { realtimeToken } from '@tanstack/ai'
import { openaiRealtimeToken } from '@tanstack/ai-openai'

// On the server (e.g. inside a server route or framework server
// function), mint an ephemeral token for the client:
const token = await realtimeToken({
  adapter: openaiRealtimeToken({ model: 'gpt-realtime-2.1' }),
})
import { realtimeToken } from '@tanstack/ai'
import { openaiRealtimeToken } from '@tanstack/ai-openai'

// On the server (e.g. inside a server route or framework server
// function), mint an ephemeral token for the client:
const token = await realtimeToken({
  adapter: openaiRealtimeToken({ model: 'gpt-realtime-2.1' }),
})