Error Handling and Retries
Overview
The Speechify API returns standard HTTP status codes. Transient errors (rate limits, server errors) can be retried safely. Client errors (bad input, auth failures) require fixing the request.
Error types
Transient errors (retry safe)
These errors are temporary. Retry with exponential backoff.
Persistent errors (fix the request)
These errors indicate a problem with the request itself. Retrying without changes will fail again.
Server errors (retry cautiously)
A 500 error often signals a request that will keep failing (e.g., a bug triggered by specific input). Retry a few times, but stop if it persists. Log the Speechify-Request-Id and contact support.
Retry strategy
Use exponential backoff with jitter for transient errors:
Python
TypeScript
cURL
Retry-After header
When present, Retry-After tells you how long to wait (in seconds) before retrying. Respect this value to avoid hammering the API.
Wait at least 5 seconds before the next attempt.
Idempotency on retries
Retrying a mutating POST (anything that creates a call, batch, purchase, or resource) risks performing the action twice if the first attempt succeeded but the response was lost.
Only endpoints that explicitly document Idempotency-Key support will replay the original response. Check the endpoint reference before relying on idempotency protection.
For supported endpoints, send an Idempotency-Key header with a unique value per logical operation. Reuse the same key on every retry:
The server runs the request once and replays the original response on retries. Endpoints that do not document idempotency support will ignore the header. See Idempotency for details.
Logging and debugging
Always log the Speechify-Request-Id from error responses. Include it when contacting support:
The request_id uniquely identifies the failed request in Speechify’s logs.
FAQ
Should I retry 4xx errors?
No. A 4xx (except 429) means the request itself is wrong. Retrying it unchanged will fail again. Fix the input, auth, or resource ID, then try a new request.
How many times should I retry?
For transient errors (429, 502, 503, 504), retry 3-5 times with exponential backoff. For 500, retry cautiously (2-3 times max) and stop if it persists.
What if an error occurs mid-stream?
HTTP chunked responses (e.g., /v1/audio/stream) cannot send error messages after the stream starts. If the connection closes early, check total bytes received and retry the remaining text. See Streaming.