Guides & reference
Errors, limits & security
Predictable JSON error envelopes, explicit WebSocket close codes, clear rate/concurrency ceilings, and strict zero-retention privacy guarantees.
Zero-billing on errorsRetry-After headersX-Data-Retention: zero
Error response shape
Every non-2xx HTTP response returns a JSON object with a stable machine-readable code and an actionable message:
JSON
{
"error": {
"code": "insufficient_balance",
"message": "Your balance does not cover this request.",
"type": "billing_error"
}
}HTTP status codes
| Status | Code | Retryable? | What to do |
|---|---|---|---|
400 | invalid_request | No | Fix the field named in error.message. |
401 | unauthorized | No | Check your bearer key. Revoked keys stop working within 30 seconds. |
402 | insufficient_balance | After top-up | Your balance does not cover this request. Add credit. |
413 | payload_too_large | No | STT upload exceeds 25 MiB. Compress to 16 kHz mono Opus/MP3/M4A or split. |
429 | rate_limited | Yes | Wait the seconds in Retry-After (rate or concurrency ceiling), then retry. |
503 | unavailable | Yes | Service temporarily at capacity or unavailable. Wait for Retry-After and retry with backoff. |
Failed requests are never charged. Retrying after any 4xx or 5xx error, or after an upstream TTS stream drop, costs $0.
Recommended retry logic
import time, httpx
def request_with_retry(client: httpx.Client, method: str, url: str, **kwargs) -> httpx.Response:
for attempt in range(4):
resp = client.request(method, url, **kwargs)
if resp.status_code not in (429, 503):
return resp
retry_after = float(resp.headers.get("Retry-After", 2 ** attempt))
time.sleep(min(retry_after, 30.0))
return respWebSocket close codes (WS /v1/audio/stream)
| Code | Meaning & recovery |
|---|---|
4400 | Invalid query parameter, unknown model, or streaming disabled for that model. Fix the URL before reconnecting. |
4401 | Missing, invalid, or expired credentials, or credentials sent in the query string (?api_key= / ?token=). Authenticate via header, subprotocol, or first-frame JSON. |
4402 | Insufficient balance at connect (< 60 s credit) or balance exhausted mid-stream. Top up before reconnecting. |
4429 | Per-key rate limit or 4-stream concurrency limit reached. Back off and close idle sockets. |
4503 | Live streaming is temporarily unavailable. Retry with jittered backoff. |
Common 400 validation messages
Text to speech (POST /v1/audio/speech)
| Message | Fix |
|---|---|
Streaming is not available for this voice yet. Use `spero-f1`, or leave it out. | Stream in spero-f1, or set stream: false. |
`stream` must be true or false. | Send a JSON boolean. |
With `stream`, `response_format` must be `pcm` or `wav`. | Ask for pcm or wav, or omit response_format (defaults to pcm). |
With `stream`, `input` must be at most 600 characters. | Shorten the text or request a file. |
With `stream`, `input` must be one paragraph. | Send a single paragraph per stream. |
`speed` cannot be used with `stream`. | Omit speed when streaming. |
`sample_rate` cannot be used with `stream`. | Omit sample_rate when streaming. |
`speed` must be a number from 0.9 to 1.1. | Send a number in [0.9, 1.1]. |
`sample_rate` must be 8000, 16000 or 24000. | Send one of those three rates. |
With `opus`, leave `sample_rate` out: Opus has its own rates. | Omit sample_rate or use another format. |
With `ulaw`, `sample_rate` must be 8000 or left out. | Omit sample_rate or pass 8000. |
Unknown response_format. Use one of: mp3, wav, flac, opus, pcm, ulaw. | Pick one of the six TTS formats. |
Speech to text (POST /v1/audio/transcriptions)
| Message | Fix |
|---|---|
Unknown response_format. Use one of: json, verbose_json, text. | Use json, verbose_json, or text. |
With `stream`, `response_format` must be `json` or left out. | Omit response_format or pass json when using SSE. |
`language` must be an ISO language code such as `en`. | Pass a supported code like en, es, tr, ja, or auto. |
`prompt` must be at most 1000 characters. | Keep glossary hints within 1,000 characters. |
`transcription_mode` must be one of: verbatim, clean, verbatim_latin. | Use verbatim, clean, or verbatim_latin. |
`temperature` must be a number between 0 and 1. | Pass a finite float in [0.0, 1.0]. |
Limits & quotas
| Limit | Default value |
|---|---|
| TTS file input | 2,000 characters · max 12 paragraphs · max 100 chars/word · 64 KiB JSON body |
| TTS stream input | 1 paragraph · max 600 characters (spero-f1) |
| STT file upload | 25 MiB per file · up to 60 minutes audio |
| STT glossary prompt | Up to 1,000 characters |
| STT live WebSocket | 45 minutes max session length · 5 s auth window if using first-frame JSON auth |
| Concurrency (per key & account) | 4 TTS · 8 batch STT · 4 live STT WebSocket streams simultaneously |
| Request rate | 120 requests/minute per key |
| API keys | 10 active keys per account |
| Capacity protection | Excess requests under heavy load return 503 with a Retry-After header |
Zero data retention & security
- Audit logs contain metadata only: model ID, request ID, character count or audio seconds, cost, and status codes. Validation errors never echo user text.
- Key hygiene:
sp_live_keys are shown once at creation and stored hashed. Keep them strictly server-side; revoke compromised keys from API keys (takes effect within 30 s). - Browser clients: never bundle
sp_live_keys into frontend JavaScript. Mint a short-lived session token server-side and authenticate WebSockets viaSec-WebSocket-Protocol: spero-auth, bearer.<jwt>.