Skip to content
Dashboard

Realtime voice, speech, and transcription now supported on AI Gateway

Link to headingRealtime example

app/api/realtime/token/route.ts
import { gateway } from '@ai-sdk/gateway';
export async function POST() {
const { token, url } = await gateway.experimental_realtime.getToken({
model: 'openai/gpt-realtime-2',
});
return Response.json({ token, url, tools: [] });
}

'use client';
import { experimental_useRealtime as useRealtime } from '@ai-sdk/react';
import { gateway } from '@ai-sdk/gateway';
// Inside a client component:
const { status, connect, startAudioCapture } = useRealtime({
model: gateway.experimental_realtime('openai/gpt-realtime-2'),
api: { token: '/api/realtime/token' },
sessionConfig: { voice: 'alloy', turnDetection: { type: 'server-vad' } },
});
// Call connect(), then startAudioCapture(stream) to start talking.

Link to headingPlayground

Ready to deploy?