Errors
Understand and handle API errors gracefully.
Discover with AI
Error Format
All errors from the /v1 API use a consistent JSON structure with a top-level error object:
| Field | Type | Description |
|---|---|---|
| error.code | string | Machine-readable error identifier. Use this in your code to distinguish error types programmatically. |
| error.message | string | Human-readable description of the error. May include actionable details like retry timing. |
json
{
"error": {
"code": "rate_limit_exceeded",
"message": "Too many requests. You can make 600 requests per 60s on your pro plan. Retry after 12s."
}
}HTTP Status Codes & Error Codes
| HTTP Status | error.code | Cause & Resolution |
|---|---|---|
| 400 | invalid_request | A required parameter is missing, the wrong type, or out of the allowed range. Check the message field for the specific parameter. Example: submitting emails as a string instead of an array. |
| 401 | unauthorized | No Authorization header, key doesn't start with sbai_live_, or key has been revoked. Generate a new key in the dashboard. |
| 402 | insufficient_credits | Your account has run out of verifier or finder credits for this billing period. Upgrade your plan or wait for your credits to reset next period. |
| 404 | not_found | The requested resource (e.g. a job ID) does not exist, or belongs to a different account. Verify the ID and that you're using the correct API key. |
| 429 | rate_limit_exceeded | Too many requests in the current 60-second window. Wait until the time in X-RateLimit-Reset before retrying. See Rate Limits for per-plan limits. |
| 500 | internal_error | Unexpected server error. Retry with exponential backoff. If the problem persists, contact support@stopbounceai.com. |
| 503 | engine_unavailable | The SMTP verification engine is temporarily unavailable. Retry after 5–10 seconds. Credits are refunded automatically if the job could not be submitted. |
Handling Errors in Code
Always check the HTTP status code first, then branch on error.code for specific handling:
javascript
async function submitBulkJob(emails) {
const res = await fetch(
'https://api.stopbounceai.com/v1/bulk',
{
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ emails }),
}
);
if (res.ok) return res.json();
const { error } = await res.json();
switch (error.code) {
case 'unauthorized':
throw new Error('API key is invalid or has been revoked.');
case 'insufficient_credits':
throw new Error('Out of credits. Upgrade your plan.');
case 'rate_limit_exceeded':
// Parse retry seconds from message or use X-RateLimit-Reset header
const retryAfter = parseInt(res.headers.get('X-RateLimit-Reset') ?? '60');
await new Promise(r => setTimeout(r, retryAfter * 1000));
return verifyEmail(email); // retry once
case 'engine_unavailable':
await new Promise(r => setTimeout(r, 5000));
return verifyEmail(email); // retry once
default:
throw new Error(`API error: ${error.message}`);
}
}