How errors work
When a request fails, the API returns a standard HTTP status code and a JSON body that explains what went wrong. Check the status code first to decide what to do, then read the message for the detail.
2xxmeans the request worked.4xxmeans something about the request needs fixing. Retrying the same request will fail again.5xxmeans a temporary problem on our side. Retrying after a short wait usually works.
Error format
Every failed request returns success: false with a short error code and a readable message. Some errors add extra fields that help you fix the problem.
{
"success": false,
"error": "quota_exceeded",
"message": "Your package limit has been reached, or this request is larger than what is left. Add a package or send fewer messages.",
"sms_required": 3,
"sms_remaining": 2
}| Field | Description |
|---|---|
| success | Always false for an error. |
| error | A short code for the problem. Use it in your code to decide what to do. |
| message | A readable explanation. Show it in logs, not to your customers. |
| errors | Only on validation_failed. Lists each field and what is wrong with it. |
| sms_required, sms_remaining | Only on quota_exceeded. How many SMS the request needed and how many are left. |
HTTP status codes
| Status | Meaning | What to do |
|---|---|---|
| 200 | The request was accepted and the message is queued. | Store the batch_id and wait for delivery events. |
| 401 | The API key is missing, wrong or revoked. | Check the x-api-key header and the key itself. |
| 402 | Your package limit is reached. | Add a package, or send fewer messages, then retry. |
| 403 | Your account cannot send yet, or the Sender ID is not yours. | Check that you have an active package and an approved Sender ID. |
| 404 | The endpoint or resource does not exist. | Check the path, for example /api/v1/send/sms. |
| 422 | A field is missing or badly formatted, or a number is invalid. | Check the body against the field table and fix it before retrying. |
| 429 | You are sending too many requests. | Slow down and retry with a delay. See Rate limits. |
| 500 | Something went wrong on our side. | Retry with backoff. Contact us if it continues. |
| 502 | The network refused the message. Nothing was deducted. | Retry with backoff. |
Error codes
The error field gives a more specific reason than the status code alone.
| Error | Status | Cause and fix |
|---|---|---|
| missing_api_key | 401 | No x-api-key header was sent. Add it to the request. |
| invalid_api_key | 401 | The key is wrong or has been revoked. Use a valid key. |
| unauthenticated | 401 | A dashboard login token is missing or expired. Log in again. |
| validation_failed | 422 | A required field such as recipients or message is missing or too long. Read errors for the exact field. |
| invalid_recipients | 422 | A number is not a valid Malawi number. Use the country code, for example 265, followed by the number. |
| quota_exceeded | 402 | The package limit is reached or too low for this send. Add a package or send fewer messages. |
| no_active_package | 403 | There is no active package on the account. Choose a package, or ask us to activate it. |
| no_sender_id | 403 | No Sender ID is assigned to the account yet. Contact us. |
| sender_not_allowed | 403 | The sender_id you sent is not available on your account. Use an approved Sender ID. |
| not_found | 404 | The path is wrong. Check the endpoint. |
| rate_limited | 429 | You exceeded the request limit. Wait, then retry with backoff. |
| delivery_failed | 502 | The network refused the message and nothing was deducted. Retry after a short wait. |
| server_error | 500 | A problem on our side. Retry after a short wait. |
Delivery failures
A 200 response only means the message was queued. If it cannot be delivered later, you receive a message.failed webhook event with a reason.
| Reason | Meaning | What to do |
|---|---|---|
| invalid_number | The number does not exist or is not valid. | Check the number and remove it from your list. |
| unreachable | The phone was off or out of coverage for too long. | Try again later or use another channel. |
| blocked | The recipient has blocked or opted out of messages. | Do not retry. Respect the opt-out. |
| not_on_whatsapp | The number is not registered on WhatsApp. | Send the message by SMS instead. |
| mailbox_unavailable | The email address does not exist or the inbox is full. | Check the address and remove it if it keeps failing. |
Handling errors in code
Retry only the errors that can fix themselves, and fix the rest at the source.
- Retry
429,500and502with exponential backoff. - Do not retry
401,402,403,404or422. Fix the request, key or package first. - Log the
errorcode, the message and thebatch_idfor every failure. - Never show raw API messages to your customers. Show your own friendly text.
const res = await fetch(url, options);
const data = await res.json();
if (!res.ok) {
switch (data.error) {
case "quota_exceeded":
notifyAdmin("Add an AvenoLink package");
break;
case "invalid_recipients":
reviewNumbers(data.message);
break;
case "rate_limited":
await retryLater();
break;
default:
console.error("AvenoLink error", res.status, data);
}
}Still stuck?
Contact support with the error code, the HTTP status, the time of the request and the batch_id if you have one. Remove your API key from anything you send us.