Grok Voice
websocket • xAIxAI's real-time voice conversation model with low-latency audio input and output streaming.
| Model Info | |
|---|---|
| Terms and License | link ↗ |
| More information | link ↗ |
| Pricing | View pricing in the Cloudflare dashboard ↗ |
Usage
// Establish WebSocket connectionconst response = await fetch( `https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run?model=xai/grok-voice`, { method: 'GET', headers: { 'Authorization': `Bearer $CLOUDFLARE_API_TOKEN`, 'Upgrade': 'websocket' } })
const ws = response.webSocketws.accept()
// Send audio chunksws.send(JSON.stringify({ type: 'input_audio_buffer.append', audio: audioBase64}))
// Receive transcriptions and audio responsesws.addEventListener('message', (event) => { const data = JSON.parse(event.data) console.log(data)})# Note: WebSocket connections require a WebSocket client# curl does not support WebSocket upgrade# Use wscat, websocat, or a programming language WebSocket library
wscat -c 'wss://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run?model=xai/grok-voice' \ -H 'Authorization: Bearer $CLOUDFLARE_API_TOKEN'{ "websocket": { "url": "wss://api.x.ai/v1/realtime?model=grok-voice-latest", "headers": { "Authorization": "Bearer [ephemeral_token]" } }, "gatewayMetadata": { "keySource": "Unified" }}Parameters
websocket
booleanEnable real-time WebSocket connection for voice conversations. When true, establishes a bidirectional WebSocket for speech-to-speech interaction with Grok voice models.▶headers{}
objectOptional headers to include when establishing the WebSocket connection (e.g., Authorization)url
stringWebSocket URL for the realtime connection (e.g., wss://...)