Pular para o conteúdo
xAI logo

Grok Voice

websocket • xAI

Ver como Markdown
  • Third-party

xAI'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 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)
})
# 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.
url
stringWebSocket URL for the realtime connection (e.g., wss://...)

API Schemas (Raw)

Input
Output