Errors and Testing
If you only test the happy path, telephony will punish you.
Common error families
Expect these kinds of failures:
- invalid or revoked API key
- validation errors on line or call creation
- insufficient credits
- consent missing for outbound calls
- webhook destination failures
- missing resources
- rate limiting
Error response shape
Every error response follows the same envelope. The code field is the stable, machine-readable identifier you should branch on. The message field is human-readable and may change over time.
Error codes
Every error response includes a stable code field. Branch on the code, not the message.
Error response examples
Concrete shapes for the codes you are most likely to hit in production.
After adding a payment method in the portal, retry POST /v1/lines with a
new Idempotency-Key. The original 402 is sticky-cached for ~12h on the
original key — reusing it returns the same 402.
Rate limits
Rate limits vary per endpoint. Most use a 1 hour rolling window; SMS is the only endpoint with a 1 minute window.
When you exceed a limit, the API returns 429 Too Many Requests with the rate_limited error code.
SDK error handling
Both SDKs surface a typed error class so you can branch on code without parsing response bodies.
What to test before shipping
Inbound call
- call connects
- caller hears the expected first response
- transcript is readable
- call record is queryable after completion
Outbound call
- blocked without consent
- succeeds with consent
- failure state is visible if destination is unreachable
SMS
- inbound event arrives
- reply succeeds
- conversation history looks correct
Webhooks
- your endpoint is idempotent (Saperly delivers each webhook once; network-level duplicates are still possible)
- non-200 responses are visible in webhook delivery logs
- test endpoint can hit your webhook before production traffic does
Load testing
sk_test_ keys for load testing. Test keys hit the same infrastructure but are isolated from production billing. Rate limits still apply — if you hit 429 rate_limited, back off and retry.Recommended approach:
- Create 2-3 test lines
- Simulate inbound webhook events against your handler
- Place outbound calls to your own test numbers
- Monitor webhook delivery success rate and latency
- Check billing transactions to verify correct charging
Useful debugging endpoints
GET /api/v1/webhooks/deliveriesGET /api/v1/webhooks/statsPOST /api/v1/webhooks/testGET /api/v1/callsGET /api/v1/compliance/audit
Advice
Break your webhook on purpose once in staging.
Then look at delivery logs and the failure-mode user experience. Better to learn that path deliberately than from your first customer.
