Errors
One envelope for every failure, and a retry strategy you can write once.
Every API failure uses a JSON error object, including endpoints whose
successful response is audio, CSV, PDF, or PCAP. Branch on its stable code
and keep the request_id when you need support.
{
"error": {
"code": "validation_failed",
"message": "request failed validation",
"request_id": "9f2c1a4b-...",
"details": {
"fields": [
{
"path": "members[0].phone_number_id",
"code": "not_found",
"message": "phone number is not active or not visible"
}
]
}
}
}| Field | Contract |
|---|---|
code | Stable machine token. Branch on this, never on message text. |
message | Human-readable; wording may improve without notice. |
request_id | Matches X-Request-Id; quote it in support reports. |
details | Optional structured context; the shape depends on the code. |
For validation_failed, details.fields lists every failing field as
{path, code, message} — fix all of them before retrying.
The complete code list, with per-code retry guidance, is the
error-code catalog. It also ships
machine-readable — every operation's OpenAPI entry has an
x-sonus-error-codes map (status → exhaustive code list), joined to the
top-level x-sonus-error-catalog (allowed statuses, retry class, details
contract per code) — and agents and CLIs should branch on those, not prose.
Status codes at a glance
| HTTP | Means | Typical codes |
|---|---|---|
400 | Request could not be interpreted | invalid_json, unknown_query_parameter, idempotency_key_required |
401 | Credential rejected | unauthorized |
403 | Authenticated but not allowed | forbidden, entitlement_required |
404 | Missing, cross-workspace, or outside the public boundary | *_not_found, operation_not_available |
408 | Body didn't arrive in time | request_timeout |
409 | Current state or duplicate intent blocks it | resource conflicts, idempotency_* |
410 | Metadata exists, binary is gone | recording_blob_missing, turn_audio_expired |
412 | Your If-Match is stale | precondition_failed |
413 / 415 / 416 | Body too large / wrong media type / bad Range | request_too_large, unsupported_media_type, invalid_range |
422 | Parsed fine, violates field rules | validation_failed |
429 | Too many requests | rate_limited, authentication_rate_limited |
5xx | Server, provider, or dependency failure | internal_error, provider_request_failed, *_unavailable, *_outcome_unknown |
Retry strategy
Three rules cover most of it:
- 4xx (except 408/409/429): fix something first. Credentials, input, or
precondition — retrying unchanged cannot succeed. A
410artifact must be regenerated, not re-downloaded. - 429 and 503: wait and retry the same request. Honor
Retry-After. For503 authentication_unavailable, retry the same credential — it was not judged invalid. - Other 5xx and ambiguous transport failures: retry only under
protection. Re-send the exact bytes with the same
Idempotency-Key(POST) or rely on natural idempotency (GET/PUT/DELETE). Exponential backoff with jitter, bounded attempts. Never invent a new intent to "recover" an ambiguous one.
The 409 idempotency_* family (in progress, conflict, context changed,
result lost) has precise per-code handling in
Idempotency.
Fine print
If an operation's OpenAPI entry has no requestBody, sending bytes returns
400 unexpected_body (details.path: "$") before the handler runs — don't
send {} or null unless a schema asks. A body arriving only partially
past the read deadline returns 408 request_timeout; retry the stored
bytes with the same Idempotency-Key.
If you don't send X-Request-Id, we generate one. A supplied value must
appear once, 1–128 visible ASCII characters, no whitespace — otherwise
400 invalid_request_id (the response still carries a fresh safe ID).
Log status, error.code, error.request_id, X-Request-Id, and resource
IDs. Never log bearer keys, one-time secrets, webhook secrets, raw
transcripts, raw tool I/O, recordings, or full request bodies that may
carry PII.
Omitted, null, "", and [] are four different values. A PATCH leaves
omitted fields alone; null is accepted only where the schema says so. Unknown mutation fields are rejected rather than ignored.
Malformed or out-of-scope pagination cursors return 400 — the exact
details contract is in Pagination.
A load balancer or WAF can reject a request before it reaches the API, without this envelope. Treat those as overload: back off with jitter and reduce concurrency.