2 2
3# Speech to Text3# Speech to Text
4 4
55Transcribe audio files into text with a single API call, or stream audio in real time over WebSocket. The API supports 15 audio formats, word-level timestamps, multichannel transcription, and text formatting.Transcribe audio files into text with a single API call, or stream audio in real time over WebSocket. The API supports 15 audio formats, word-level timestamps, multichannel transcription, text formatting, and redaction of sensitive data.
6 6
7## Quick Start7## Quick Start
8 8
154| `multichannel` | boolean | `false` | | When `true`, transcribes each audio channel independently. Results returned in the `channels` array. |154| `multichannel` | boolean | `false` | | When `true`, transcribes each audio channel independently. Results returned in the `channels` array. |
155| `channels` | integer | | | Number of audio channels (2–8). Only required for multichannel raw audio. Auto-detected for container formats. |155| `channels` | integer | | | Number of audio channels (2–8). Only required for multichannel raw audio. Auto-detected for container formats. |
156| `diarize` | boolean | `false` | | When `true`, enables speaker diarization. Each word in the response includes a `speaker` field (integer) identifying the detected speaker. |156| `diarize` | boolean | `false` | | When `true`, enables speaker diarization. Each word in the response includes a `speaker` field (integer) identifying the detected speaker. |
157157| `keyterm` | string | | | A key term to bias transcription toward (e.g. product names, proper nouns). Repeat the field for multiple terms (e.g. `keyterm=Understand+The+Universe`). Max 100 terms, each up to 50 characters. || `keyterm` | string | | | A key term to bias transcription toward (e.g. product names, proper nouns). Repeat the field for multiple terms (e.g. `keyterm=Understand The Universe`). Max 100 terms, each up to 50 characters. |
158| `filler_words` | boolean | `false` | | When `true`, filler words (e.g. "uh", "um", "er") are included in the transcript. When `false` (default), filler words are automatically removed from the transcript text and the `words` array. |158| `filler_words` | boolean | `false` | | When `true`, filler words (e.g. "uh", "um", "er") are included in the transcript. When `false` (default), filler words are automatically removed from the transcript text and the `words` array. |
159| `vad_threshold` | number | `0.5` | | Speech-probability threshold for the voice-activity gate (0.0–1.0). Audio segments scoring below the threshold are treated as non-speech and skipped for transcription. Lower values transcribe quieter or noisier speech (e.g. narrowband telephony) but may produce spurious text for background noise. `0` disables the gate. |159| `vad_threshold` | number | `0.5` | | Speech-probability threshold for the voice-activity gate (0.0–1.0). Audio segments scoring below the threshold are treated as non-speech and skipped for transcription. Lower values transcribe quieter or noisier speech (e.g. narrowband telephony) but may produce spurious text for background noise. `0` disables the gate. |
160| `redact` | string | | | Types of sensitive data to replace with tags: `pii`, `pci`, `phi`, or a single type such as `ssn`. Repeat the field for multiple values. See [Redaction](#redaction). |
161| `show_redacted_text` | boolean | `false` | | When `true`, each redacted word in the response includes a `redacted_text` field with the original words. Only applies with `redact`. |
160 162
161† Either `file` or `url` must be provided.163† Either `file` or `url` must be provided.
162 164
199| `text` | string | Full transcript text. |201| `text` | string | Full transcript text. |
200| `language` | string | Detected language as a BCP-47 code (e.g. `en`, `es-mx`). |202| `language` | string | Detected language as a BCP-47 code (e.g. `en`, `es-mx`). |
201| `duration` | number | Audio duration in seconds (3 d.p.). |203| `duration` | number | Audio duration in seconds (3 d.p.). |
202204| `words` | array | Word-level segments with `text`, `start`, `end`, and `speaker` (integer, only when `diarize=true`). || `words` | array | Word-level segments with `text`, `start`, `end`, `speaker` (integer, only when `diarize=true`), and `redacted_text` (only when `show_redacted_text=true`). |
203| `channels` | array | Per-channel transcripts (only when `multichannel=true`). Each entry has `index`, `text`, and `words`. |205| `channels` | array | Per-channel transcripts (only when `multichannel=true`). Each entry has `index`, `text`, and `words`. |
204 206
207## Redaction
208
209Set `redact` to replace sensitive values in the transcript with tags such as `[NAME_1]`, on both the REST and WebSocket endpoints.
210
211```bash
212curl -X POST https://api.x.ai/v1/stt \
213 -H "Authorization: Bearer $XAI_API_KEY" \
214 -F format=true \
215 -F language=en \
216 -F redact=pii \
217 -F redact=pci \
218 -F file=@call.mp3
219```
220
221```json
222{
223 "text": "Hi, my name is [NAME_1]. My card number is [CREDIT_CARD_1].",
224 "language": "en",
225 "duration": 8.673,
226 "words": [
227 { "text": "Hi,", "start": 0.12, "end": 0.34 },
228 { "text": "my", "start": 0.601, "end": 0.721 },
229 { "text": "name", "start": 0.761, "end": 0.901 },
230 { "text": "is", "start": 0.921, "end": 1.001 },
231 { "text": "[NAME_1]", "start": 1.082, "end": 1.422 },
232 { "text": ".", "start": 1.522, "end": 2.003 },
233 { "text": "My", "start": 2.444, "end": 2.564 },
234 { "text": "card", "start": 2.604, "end": 2.824 },
235 { "text": "number", "start": 2.864, "end": 3.084 },
236 { "text": "is", "start": 3.145, "end": 3.225 },
237 { "text": "[CREDIT_CARD_1]", "start": 3.325, "end": 8.092 },
238 { "text": ".", "start": 8.192, "end": 8.372 }
239 ]
240}
241```
242
243**How it works:**
244
245* A tag is `[TYPE_N]`. The same value keeps its number, so every `[NAME_1]` in a response or streaming session is the same name.
246* Tags replace the values in `text`, `words`, and `channels`.
247* `show_redacted_text=true` adds the original words to each redacted word as `redacted_text`. REST only.
248* Streaming sends no interim results while `redact` is set. Chunk-final and utterance-final events arrive redacted.
249* If redaction cannot run, the request fails instead of returning the unredacted transcript: `503` on REST, an `error` event on WebSocket.
250
251`redact` accepts a group, a single type, or several of either:
252
253| Value | Types |
254|-------|-------|
255| `pii` | `name`, `name_given`, `name_family`, `name_medical_professional`, `username`, `password`, `phone_number`, `email_address`, `ip_address`, `url`, `filename`, `location`, `location_address`, `location_city`, `location_state`, `location_zip`, `location_country`, `location_coordinate`, `ssn`, `passport_number`, `vehicle_id`, `healthcare_number`, `account_number`, `numerical_pii`, `dob`, `age`, `date`, `date_interval`, `time`, `duration`, `money`, `organization`, `organization_medical_facility`, `occupation`, `event`, `language`, `origin`, `religion`, `political_affiliation`, `marital_status`, `gender_sexuality`, `physical_attribute`, `zodiac_sign` |
256| `pci` | `credit_card`, `credit_card_expiration`, `cvv` |
257| `phi` | `condition`, `drug`, `dose`, `injury`, `blood_type`, `medical_process`, `statistics` |
258| Ungrouped | `bank_account`, `routing_number`, `drivers_license`, `pin` |
259
260`pii` leaves card details, bank account numbers, and routing numbers in the transcript. Add `pci`, `bank_account`, and `routing_number` to redact them.
261
262Redaction is tuned for English, Spanish, French, German, and Portuguese. It costs $0.05 per hour of audio on top of transcription.
263
205## Supported Audio Formats264## Supported Audio Formats
206 265
207### Container formats (auto-detected)266### Container formats (auto-detected)
266| `smart_turn` | number | | End-of-turn detection threshold (0.0–1.0). When set, enables Smart Turn — an ML model predicts whether the speaker has finished their thought at each silence boundary. See [Smart Turn](#smart-turn). |325| `smart_turn` | number | | End-of-turn detection threshold (0.0–1.0). When set, enables Smart Turn — an ML model predicts whether the speaker has finished their thought at each silence boundary. See [Smart Turn](#smart-turn). |
267| `smart_turn_timeout` | integer | | Maximum silence duration (ms) before forcing `speech_final`, even when the Smart Turn model predicts the speaker hasn't finished. Range: 1–5000. Only applies when `smart_turn` is enabled. See [Smart Turn](#smart-turn). |326| `smart_turn_timeout` | integer | | Maximum silence duration (ms) before forcing `speech_final`, even when the Smart Turn model predicts the speaker hasn't finished. Range: 1–5000. Only applies when `smart_turn` is enabled. See [Smart Turn](#smart-turn). |
268| `vad_threshold` | number | `0.08` | Speech-probability threshold for the voice-activity gate (0.0–1.0). Audio in chunks scoring below the threshold is treated as non-speech and skipped for transcription. Lower values transcribe quieter or noisier speech (e.g. narrowband telephony) but may produce spurious text for background noise. `0` disables the gate. Does not affect endpointing or `speech_final` timing. |327| `vad_threshold` | number | `0.08` | Speech-probability threshold for the voice-activity gate (0.0–1.0). Audio in chunks scoring below the threshold is treated as non-speech and skipped for transcription. Lower values transcribe quieter or noisier speech (e.g. narrowband telephony) but may produce spurious text for background noise. `0` disables the gate. Does not affect endpointing or `speech_final` timing. |
328| `redact` | string | | Types of sensitive data to replace with tags. Repeat the parameter for multiple values. Interim results are not sent when set. See [Redaction](#redaction). |
269 329
270### Server Events330### Server Events
271 331
501| Status | Meaning | Action |561| Status | Meaning | Action |
502|--------|---------|--------|562|--------|---------|--------|
503| `200` | Success | Transcription in the response body |563| `200` | Success | Transcription in the response body |
504564| `400` | Bad request | Missing `file`/`url`, unsupported format, missing `sample_rate` for raw audio, `format=true` without `language` || `400` | Bad request | Missing `file`/`url`, unsupported format, missing `sample_rate` for raw audio, `format=true` without `language`, unsupported `redact` value |
505| `401` | Unauthorized | API key is missing or invalid |565| `401` | Unauthorized | API key is missing or invalid |
506| `413` | Payload too large | File exceeds 500 MB |566| `413` | Payload too large | File exceeds 500 MB |
507| `429` | Rate limited | Back off and retry with exponential delay |567| `429` | Rate limited | Back off and retry with exponential delay |
508| `502` | Bad gateway | URL download failed (when using `url`) |568| `502` | Bad gateway | URL download failed (when using `url`) |
509569| `503` | Service unavailable | Backend not available — retry || `503` | Service unavailable | Backend not available, or redaction could not run — retry |
510 570
511## Related571## Related
512 572