Error Handling

API error codes, formats, and troubleshooting

HTTP Status Codes

CodeMeaning
200Success
201Created
204Success — no body (deletions)
400Bad request — check detail
401Authentication failed — invalid or missing X-API-Key
402Quota exhausted — balance empty
403Forbidden — resource belongs to another organisation
404Not found
409Conflict — e.g. trigger path collision, missing agent owner
422Validation error — check the detail array
429Rate limited — check Retry-After header
500Internal server error — retry with exponential backoff

Error Response Format

Response
json
{ "detail": "Human-readable description" }

Validation errors (422):

Response
json
{
  "detail": [
    {
      "loc": ["body", "phone_number"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}

Retry Strategy

typescript
async function withRetry<T>(fn: () => Promise<T>, maxAttempts = 3): Promise<T> {
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
    try {
      return await fn();
    } catch (err: any) {
      if (attempt === maxAttempts) throw err;
      // 4xx (except 429) are not retryable
      if (err.status < 500 && err.status !== 429) throw err;
      const delay = err.status === 429
        ? parseInt(err.headers?.get("Retry-After") ?? "5") * 1000
        : Math.pow(2, attempt) * 1000;
      await new Promise(r => setTimeout(r, delay));
    }
  }
  throw new Error("Max retries exceeded");
}
Was this page helpful?
Open Dashboard →