Grok Voice
websocket • xAI
xai/grok-voice
- Third-party
- Zero data retention
xAI's real-time voice conversation model with low-latency audio input and output streaming.
| Model Info | |
|---|---|
| Terms and License | link ↗ |
| More information | link ↗ |
| Zero data retention | Yes |
| Pricing | <ul><li>total audio minutes$0.05</li><li>input text messages$0.004</li></ul> |
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://...)
▶headers{}
objectOptional headers to include when establishing the WebSocket connection (e.g., Authorization)
API Schemas (Raw)
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai/models/xai/grok-voice/#page","headline":"Grok Voice","description":"xAI's real-time voice conversation model with low-latency audio input and output streaming.","url":"https://developers.cloudflare.com/ai/models/xai/grok-voice/","inLanguage":"en","image":"https://developers.cloudflare.com/og-docs.png","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Explore Cloudflare products that complement AI, including Workers AI, AI Gateway, Vectorize, and more. title: Related products image: https://developers.cloudflare.com/ai/related-products/og.png?v=e2eabf2d333ed6f6
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ai/llms.txt
Use this file to discover all available pages before exploring further.
Docs