Skip to content
Dashboard

xAI Grok audio models now available on Vercel AI Gateway

npm install ai @ai-sdk/react @ai-sdk/gateway

Link to headingAvailable models

Link to headingRealtime

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: 'xai/grok-voice-think-fast-1.0',
});
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('xai/grok-voice-think-fast-1.0'),
api: { token: '/api/realtime/token' },
sessionConfig: { turnDetection: { type: 'server-vad' } },
});
// Call connect(), then startAudioCapture(stream) to start talking.

Link to headingText to speech

import { generateSpeech } from 'ai';
import { writeFile } from 'node:fs/promises';
const result = await generateSpeech({
model: 'xai/grok-tts',
text: 'Thanks for trying out AI Gateway.',
voice: 'eve',
outputFormat: 'mp3',
});
await writeFile('speech.mp3', result.audio.uint8Array);

Link to headingSpeech to text

import { transcribe } from 'ai';
import { readFile } from 'node:fs/promises';
const result = await transcribe({
model: 'xai/grok-stt',
audio: await readFile('audio.mp3'),
});
console.log(result.text);

Link to headingPlayground

Link to headingMore information

Ready to deploy?