The Grok Voice API: TTS, Voice Agents and Speech to Text
The Grok Voice API in one guide: text to speech (POST /v1/tts, $15/1M characters), voice agents ($0.08/min) and speech to text ($0.10/h), with code.
Last updated:
The Grok Voice API is xAI’s developer interface for speech, and it has three separately billed parts: text to speech, which turns text into audio; voice agents, real-time speech-to-speech conversations; and speech to text, which transcribes recordings or live audio.
| Part | What it does | Endpoint | List price (checked 21 Oct 2026) | Details |
|---|---|---|---|---|
| Text to speech | Text in, MP3/WAV/PCM out, the 28 built-in voices | POST https://api.x.ai/v1/tts | $15 per 1M characters | this page, below |
| Voice agent | Real-time speech-to-speech with tools and phone calls | wss://api.x.ai/v1/realtime | $0.08 per minute | voice agent guide |
| Speech to text | Transcribes recordings or live audio | REST upload and streaming | $0.10 / $0.20 per hour | pricing |
Text to speech, the most-used part, is one endpoint: POST https://api.x.ai/v1/tts, with a JSON body of text (up to 60,000 characters, speech tags allowed) and voice_id (one of 28 built-in ids, default eve). It returns raw MP3 at 24 kHz / 128 kbps by default and costs $15 per million characters (docs.x.ai, checked 21 October 2026). Every parameter that matters, the voice and language lists, and copy-paste code follow.
What is the Grok TTS API endpoint?
POST https://api.x.ai/v1/tts
Authorization: Bearer $XAI_API_KEY
Content-Type: application/json
Minimal request:
curl -X POST https://api.x.ai/v1/tts \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Hello! Welcome to the xAI text to speech API.", "voice_id": "eve", "language": "en"}' \
--output hello.mp3
The response body is the raw audio (MP3 unless you ask for another codec). There is no JSON wrapper unless you request timestamps.
Get a key at console.x.ai → API keys. Want to hear a voice before writing code? The free tool on this site calls the same endpoint.
What can the request body contain?
| Field | Required | What it does |
|---|---|---|
text | yes | Up to 60,000 characters. May contain speech tags. |
language | yes | BCP-47 code (en, zh, pt-BR, …) or auto. Case-insensitive. |
voice_id | no | One of the 28 built-in ids (default eve) or a custom voice id. Case-insensitive. |
speed | no | 0.7 to 1.5; 1.0 is normal. |
output_format | no | { "codec", "sample_rate", "bit_rate" }; default MP3, 24000 Hz, 128000 bps. |
optimize_streaming_latency | no | 0 (best quality, default), 1 or 2 (smaller first chunk, faster first audio). |
text_normalization | no | true reads "$5" as "five dollars", expands abbreviations and numbers. Default false. |
with_timestamps | no | true returns JSON with base64 audio plus per-character start/end times. |
replace | no | Map of phrases to how they should be spoken, as respellings or IPA between slashes. Up to 200 entries. |
Voices
28 built-in ids, all lower-case, all able to speak every supported language:
ara eve leo rex sal altair atlas aurora carina castor celeste cosmo helios helix iris kepler liora lumen luna lux naksh orion perseus rigel sirius ursa zagan zenith
List them programmatically with GET /v1/tts/voices, or fetch one with GET /v1/tts/voices/{voice_id}. Each has a page with a live demo on this site: see all voices. Custom voices from the cloning API are passed in the same voice_id field.
Languages
auto, en, ar-EG, ar-SA, ar-AE, bn, zh, fr, de, hi, id, it, ja, ko, pt-BR, pt-PT, ru, es-MX, es-ES, tr, vi. xAI says the model can also produce other languages "with varying degrees of accuracy", but only these are validated. Set the code explicitly for mixed-language text; auto is fine for single-language input.
Speech tags
Laughs, whispers, pauses and other effects are tags written into text; there is no separate parameter. The full list of all 26 tags, grouped the way xAI groups them and with an example sentence for each, is in the Grok TTS speech tags guide. There are two kinds:
- Inline, a sound at that spot:
[pause],[long-pause],[laugh],[chuckle],[giggle],[cry],[sigh],[breath],[inhale],[exhale],[hum-tune],[tsk],[tongue-click],[lip-smack]. - Wrapping, a delivery change for the wrapped phrase:
<whisper>,<soft>,<loud>,<build-intensity>,<decrease-intensity>,<higher-pitch>,<lower-pitch>,<slow>,<fast>,<emphasis>,<sing-song>,<singing>.
{
"text": "So I walked in and [pause] there it was. [laugh] <whisper>It was a secret the whole time.</whisper>",
"voice_id": "ara",
"language": "en"
}
Tags nest (<slow><soft>…</soft></slow>) and are billed as characters but never spoken. To hear each one, see the Grok TTS speech tags guide and paste its examples into the free tool.
Which audio formats does Grok TTS return?
codec | Content-Type | Use |
|---|---|---|
mp3 | audio/mpeg | Default; web and apps |
wav | audio/wav | Lossless; editing |
pcm | audio/pcm | Raw samples; real-time pipelines |
mulaw | audio/basic | Telephony (G.711 μ-law) |
alaw | audio/alaw | Telephony (G.711 A-law) |
sample_rate: 8000, 16000, 22050, 24000 (default), 44100 or 48000. bit_rate (MP3 only): 32000, 64000, 96000, 128000 (default) or 192000.
{
"text": "Crystal clear.",
"voice_id": "rex",
"language": "en",
"output_format": { "codec": "mp3", "sample_rate": 44100, "bit_rate": 192000 }
}
For a phone system: { "codec": "mulaw", "sample_rate": 8000 }.
Character-level timestamps
Set "with_timestamps": true and the response becomes JSON:
{
"audio": "<base64 audio>",
"content_type": "audio/mpeg",
"duration": 0.92,
"audio_timestamps": {
"graph_chars": ["H", "e", "l", "l", "o"],
"graph_times": [
[0.0, 0.06],
[0.06, 0.12],
[0.12, 0.18],
[0.18, 0.24],
[0.24, 0.34]
]
}
}
graph_chars mirrors your input character for character (spaces, punctuation and tags included) and graph_times is the parallel list of [start, end] seconds. Use it for captions, karaoke-style highlighting or lip sync. Walk the arrays in order rather than slicing your original string by index, because with text_normalization one written token ("$5") can be spoken as several words.
Pronunciation fixes with replace
{
"text": "Deploy it behind nginx on Acme Mobile.",
"voice_id": "leo",
"language": "en",
"replace": { "nginx": "/ˈɛndʒɪn ˈɛks/", "Acme Mobile": "Acme Mobull" }
}
Matching is case-insensitive on whole words, longest match wins, and you are still billed for the original text.
Code examples
Python
import os, requests
r = requests.post(
"https://api.x.ai/v1/tts",
headers={"Authorization": f"Bearer {os.environ['XAI_API_KEY']}"},
json={"text": "Hello from Grok.", "voice_id": "ara", "language": "en", "speed": 1.1},
)
r.raise_for_status()
open("hello.mp3", "wb").write(r.content)
JavaScript (Node 18+ or any runtime with fetch)
const res = await fetch('https://api.x.ai/v1/tts', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.XAI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: 'Hello from Grok.',
voice_id: 'ara',
language: 'en',
}),
});
if (!res.ok) throw new Error(`TTS error ${res.status}`);
await fs.promises.writeFile('hello.mp3', Buffer.from(await res.arrayBuffer()));
Keep the API key on a server. In a browser app, proxy the call through your backend (that is what this site does) or, for speech-to-speech sessions, mint an ephemeral client secret.
Pricing
$15.00 per million characters of input, counted on the text you send including tags and replace keys. A 1,000-character paragraph is $0.015. The other Voice API prices (speech to speech $0.08 per minute, speech to text $0.10 per hour) and a calculator are on the pricing page.
Errors you will meet
- 401 – missing or wrong key.
- 400 / 422 – unknown
voice_idorlanguage, speed out of 0.7–1.5, or malformed tags. - 413 – text over 60,000 characters; split it.
- 429 – rate limit; back off and retry, or ask xAI for a higher limit.
Related
- Grok Voice 3.0: the speech-to-speech model
- Grok voice agent guide: sessions, ephemeral tokens, phone numbers
- Grok voice clone: custom voices
- All 28 voices with live demos