API reference
Errors
Every error has a stable code and a retryable flag. Handle errors by code and retryable, never by the detail text.
Error format
HTTP errors return a JSON body with a 4xx or 5xx status. Streaming errors arrive as an error event, which ends the request.
json
{
"event": "error",
"request_id": "rq_0f8c2d4e-...",
"code": "invalid_request",
"retryable": false,
"detail": "String must contain at least 1 character(s)"
}| Field | Type | Description |
|---|---|---|
request_id | string | The request's ID. Include it when you contact support. |
code | string | Stable, machine-readable error code. |
retryable | boolean | true if the same request can succeed on a new attempt. |
detail | string | Human-readable explanation. Its wording can change; don't parse it. |
Idempotency and job errors return a shorter body with only code (idempotency errors also include request_id), plus the status and headers listed below.
Error codes
| Code | Status | Retry | Meaning and action |
|---|---|---|---|
invalid_request | 400 | No | The JSON, a field, the event order, a tag or a limit is invalid, or the voice is not available to this workspace. Fix the request. |
invalid_voice | 400 | No | The voice can't be used with the requested model, or has no usable recording. Choose another voice or omit model. |
unsupported_output_format | 400 | No | The model can't produce this format. Choose one listed in GET /v1/models. |
unauthorized | 401 | No | The API key or stream token is missing, invalid, expired or revoked. |
insufficient_credit | 402 | No | The workspace balance is too low. Buy credits under Billing in Studio, then retry. |
capability_disabled | 403 | No | Text to Speech is not enabled for this workspace. |
organization_suspended | 403 | No | The workspace is suspended. Contact us. |
idempotency_conflict | 409 | No | The Idempotency-Key was already used with a different body. Use a new key. |
idempotency_in_progress | 409 | Yes | The original request with this key is still running. Retry after Retry-After. |
batch_in_progress | 409 | Yes | The job hasn't finished. Retry after Retry-After. |
idempotency_result_unavailable | 410 | No | The original result failed or expired. Send a new request with a new key. |
batch_result_unavailable | 410 | No | The job failed or expired. Submit a new job with a new key. |
batch_not_found | 404 | No | No job with this ID exists in the workspace. |
idempotency_key_required | 400 | No | POST /v1/tts/jobs needs an Idempotency-Key of 1–200 characters. |
rate_limited | 429 | Yes | Capacity is temporarily full. Retry with backoff. |
batch_queue_full | 429 | Yes | The workspace has 20 jobs queued or running. Retry after Retry-After. |
provider_error | 5xx | If retryable | Speech generation failed. Retry only if retryable is true; otherwise contact us with the request_id. |
provider_unavailable | 5xx | If retryable | The speech service is temporarily unavailable. Retry with backoff. |
organization_account_missing | 503 | No | The workspace's billing account is not set up. Contact us. |
Retries
- Retry only when
retryableistrue, or the status is 409 or 429 with aRetry-Afterheader. - Wait at least
Retry-Afterseconds when present. Otherwise use exponential backoff with jitter, for example 1, 2, 4 and 8 seconds. - Send an
Idempotency-KeywithPOST /v1/ttsso a retry after a lost response can't generate or charge twice. - A streaming retry is a new WebSocket connection with a new
request_id. - A streaming error can arrive after some audio has played. Decide whether to replay the whole utterance or resume at a sentence boundary, so the listener doesn't hear the same words twice.
WebSocket handshake and close codes
A rejected API key, stream token or browser origin fails the handshake with HTTP 401, before the connection opens. After the connection opens:
| Close code | Meaning |
|---|---|
1000 | Normal close after finish. |
1008 | A control message was binary or not valid JSON. |
1009 | A control message was larger than 64 KiB. |
Other protocol mistakes, such as a second start or a text event after stop, end the request with an invalid_request error event.