Status codes
Error codes
error.code is an open enum. New codes are added without a version bump.
Always have a default branch keyed on the HTTP status.Handling errors
The pattern that covers everything: branch on status, then on code.- Python
- Node.js
Retry rules
- Retry
429,500,502,503,504and network errors. Exponential backoff with jitter; honourRetry-Afterwhen present. - Never retry
400,401,403,404,501— the same request will fail the same way. 402is retryable only after a top-up, not on a timer.- Always send
Idempotency-KeyonPOST /v2/calls. A timeout tells you nothing about whether the phone rang; without the key, your retry is a second call to a real person.
What a 409 duplicate_call actually means
It means a request with this Idempotency-Key is still being processed. It
is the narrow race, not the normal retry path: we cannot replay a response that
has not been produced yet, and we must not place a second call, so we say so.
When the original request completes, the same key replays its stored response —
so a retry a moment later returns the original 202 and the original call_id.
Either way no second call is placed. That is usually the success path of a
retry, not a failure: log it and move on, do not surface it as an error to your
users.