VOICE / convert-text-to-speech-with-voice-api

Voice

Convert text to speech with the Voice API

Convert text to speech with the Voice API

Send text to POST https://api.x.ai/v1/tts. The response body is raw audio bytes. Default output is MP3 at 24 kHz / 128 kbps. Get a key and credits at console.x.ai.

Minimal call

text and language are required. voice_id defaults to eve. language is a BCP-47 tag (en, pt-BR) or auto.

export XAI_API_KEY="your_api_key"

curl -X POST https://api.x.ai/v1/tts \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Confirm the meeting at 3pm.",
    "voice_id": "eve",
    "language": "en"
  }' \
  --output speech.mp3

List built-in voices with GET /v1/tts/voices. An unknown voice_id returns 404.

Tags

Inline tags fire at that point in the line: [pause], [laugh]. Wrapping tags change delivery for a span: <whisper>...</whisper>.

Unary requests cap at 15,000 characters. Route the call through your server. Do not send XAI_API_KEY from browser JavaScript.

Pitfalls

  • Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.
  • A 400 usually means empty text, more than 15,000 characters, or a bad codec / sample rate.
  • with_timestamps wraps the body in JSON (base64 audio plus timings). Leave it off when you want raw bytes.