Skip to content
xAI logo

Grok Voice

websocketxAI

xAI's real-time voice conversation model with low-latency audio input and output streaming.

Model Info
Terms and Licenselink
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
// Establish WebSocket connection
const 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.webSocket
ws.accept()
// Send audio chunks
ws.send(JSON.stringify({
type: 'input_audio_buffer.append',
audio: audioBase64
}))
// Receive transcriptions and audio responses
ws.addEventListener('message', (event) => {
const data = JSON.parse(event.data)
console.log(data)
})
{
"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.

API Schemas (Raw)

Input
Output