Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

xAI のロゴ

Grok Voice

WebSocket • xAI

Markdown で表示Agent セットアップ
  • サードパーティ
  • ゼロデータ保持

低レイテンシの音声入出力ストリーミングに対応した、xAI のリアルタイム音声会話モデルです。

モデル情報
利用規約とライセンスリンク
詳細情報リンク
ゼロデータ保持はい
料金Cloudflare ダッシュボードで料金を見る

使い方

// 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"
  }
}

パラメーター

websocket
boolean音声会話向けのリアルタイム WebSocket 接続を有効にします。`true` の場合、Grok 音声モデルとの speech-to-speech 用の双方向 WebSocket を確立します。
url
stringリアルタイム接続の WebSocket URL です(例: `wss://...`)

API スキーマ(Raw)

Input
Output

役に立ちましたか?