Error Handling

Every API response follows a consistent envelope. When something goes wrong, you’ll get a clear error with an actionable message.

Error Response Format

1{
2 "success": false,
3 "error": {
4 "code": "validation_error",
5 "message": "Agent name is already in use"
6 },
7 "request_id": "req_abc123",
8 "timestamp": "2025-01-01T12:00:00Z"
9}

Always log the request_id — our support team can use it to trace any issue instantly.

HTTP Status Codes

Client Errors (4xx)

CodeNameWhen It Happens
400Bad RequestMalformed JSON, missing required fields
401UnauthorizedMissing or invalid API key
403ForbiddenAPI key lacks permission for this resource
404Not FoundAgent, campaign, or call doesn’t exist
409ConflictDuplicate resource (e.g., agent name already taken)
422Validation ErrorFields present but invalid values
429Rate LimitedToo many requests — back off and retry

Server Errors (5xx)

CodeNameWhen It Happens
500Internal ErrorUnexpected server error — safe to retry
502Bad GatewayUpstream service temporarily unavailable
503Service UnavailableSystem under maintenance
504Gateway TimeoutRequest took too long — retry with backoff

Rate Limiting

Rate limits depend on your plan:

PlanRequests/Minute
Free60
Pro300
EnterpriseCustom

When you hit the limit, you’ll get a 429 response with these headers:

X-RateLimit-Limit: 300
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1706140800

Exceeding rate limits repeatedly may result in temporary IP-level throttling. Always implement exponential backoff.

Retry Strategy

Not all errors should be retried. Follow this guide:

StatusRetry?Strategy
400NoFix the request
401NoCheck your API key
404NoVerify the resource ID
422NoFix validation errors
429YesWait for X-RateLimit-Reset, then retry
500YesRetry with exponential backoff
502YesRetry after 1-2 seconds
503YesWait 30+ seconds, then retry
504YesRetry with longer timeout

Code Examples

1import requests
2import time
3
4def api_call_with_retry(method, url, headers, json=None, max_retries=3):
5 """Make an API call with automatic retry on transient errors."""
6 for attempt in range(max_retries):
7 response = requests.request(method, url, headers=headers, json=json)
8
9 if response.status_code == 200:
10 return response.json()
11
12 if response.status_code == 429:
13 # Rate limited — wait for reset
14 reset_time = int(response.headers.get("X-RateLimit-Reset", 0))
15 wait = max(reset_time - int(time.time()), 1)
16 print(f"Rate limited. Waiting {wait}s...")
17 time.sleep(wait)
18 continue
19
20 if response.status_code >= 500:
21 # Server error — exponential backoff
22 wait = (2 ** attempt) + 0.5
23 print(f"Server error {response.status_code}. Retrying in {wait}s...")
24 time.sleep(wait)
25 continue
26
27 # Client error — don't retry
28 error = response.json()
29 raise Exception(f"API Error {response.status_code}: {error}")
30
31 raise Exception("Max retries exceeded")

Common Errors & Fixes

Error CodeMessageFix
validation_error”Agent name is already in use”Choose a unique agent name
validation_error”phone_number must be E.164 format”Use format +919876543210
not_found”Agent not found”Verify the agent ID exists
authentication_error”Invalid or expired API key”Regenerate your API key in the Dashboard
quota_exceeded”Insufficient credits”Top up credits in the Dashboard