Asynchronous workflows
Some operations commit intent now and finish later — here's the one polling loop that handles all of them.
Provisioning a SIP trunk, placing an outbound call, running an eval: these
commit durable intent immediately and finish in the background. The initial
response identifies the resource to poll; a 2xx on the create is not
workflow success.
The loop is always the same:
POSTwith anIdempotency-Key; persist the returned ID/URL and the key.- Wait — at least
Retry-Afterseconds when present, otherwise bounded exponential backoff with jitter. GETthe point resource (theLocationheader is the canonical poll target); record its status and any stable failure code.- Stop on a terminal status.
| Workflow | Poll | Terminal states |
|---|---|---|
| SIP trunk provisioning | GET /sip-trunks/{id} | active, error, archived |
| Phone-number connection | GET /phone-numbers/{id} | active, error, archived |
Outbound calling (202 job) | GET /outbound-jobs/{id} | completed, canceled, failed, expired |
Live context injection (202) | GET /calls/{id}, match the message ID in data_messages | message delivery state terminal |
| Webhook test/replay | GET /webhook-deliveries/{id} | terminal delivery status |
| Transfer cancellation | GET /transfers/{id} | transfer state is authoritative; provider ambiguity leaves it nonterminal (502/503/504) |
Call purge (202) | GET /calls/{id}, inspect purge_cleanup | all cleanup counts terminal |
Eval scenario generation (202) | GET /eval-generation-jobs/{id} | done, failed |
Eval run (202) | GET /eval-runs/{id} | documented terminal status; cancel with POST /eval-runs/{id}/cancel |
The rules that prevent duplicates
- A client timeout does not cancel committed work. Retry the exact POST with the same idempotency key; if the API replays, continue from the returned resource. To actually stop a durable outbound job, use its cancel operation — dropping the connection is not cancellation.
- Never create a second resource to recover an ambiguous first one. Replay the original create, read what it returns, proceed from there.
- Repair, don't recreate.
POST /sip-trunks/{id}/reconcileandPOST /phone-numbers/{id}/reconcilere-sync provider state from committed configuration or retry eligible failed provisioning. They take no body, support idempotency, and can answer409+Retry-Afterwhile a recent operation is still active.
Failure information is sanitized
Async resources expose stable failure codes and safe messages — raw provider output (which can contain credentials, SIP headers, or phone numbers) is withheld unless a separately audited permission grants it. Branch on the stable code, never on a provider string.