Errors, retries and idempotency

The error envelope

A failed request returns an HTTP status and a JSON body in the same envelope shape:

{
  "success": false,
  "message": "Enter a valid recipient",
  "data": {
    "request_id": "req_01...",
    "error": { "code": "INVALID_DESTINATION" }
  }
}
  • message is written for a person and may change.
  • data.error.code is stable; branch on it.
  • data.request_id identifies the request in logs and support.

Agent routes use the same envelope with agent-specific codes such as agent_budget, agent_paused or agent_scope_denied.

Status families

StatusMeaningTypical cause
400Malformed requestBad JSON, invalid field, missing required value
401Not authenticatedMissing, expired or revoked credential
402No funds or entitlementWallet, subscription or inbound entitlement missing
403Not allowedScope, role, workspace or policy refusal
404Not foundUnknown or inaccessible resource (both look identical)
409ConflictIdempotency conflict, stale revision, suppressed recipient
422UnprocessableChannel unqualified, invalid content, policy refusal
423LockedAgent paused or send budget exhausted
429Rate limitedKey request limit or daily quota reached
500Server errorUnexpected failure; safe to retry a read
503UnavailableProvider, policy store or transport unavailable

Idempotency

Sends accept Idempotency-Key. The key is bound to the exact normalized request:

  • Reuse the same key with the same payload and you receive the original result, marked replay: true or idempotent-replay: true.
  • Reuse it with a different payload and you get 409.
  • Omit it and retrying a timeout can send twice.

Generate one key per user action, not per HTTP attempt:

KEY="order-4821-welcome"
curl -X POST 'https://api.bonga.africa/api/v2/messages' \
  -H "Authorization: Bearer $BONGA_API_KEY" \
  -H "Idempotency-Key: $KEY" \
  -H 'Content-Type: application/json' \
  --data '@message.json'

Agent sends accept the same header. The MCP tools forward it when the client supplies it.

Retry policy

SituationRetry?
429Yes, after Retry-After
500, 502, 503 on a readYes, with backoff
503 on a send with an idempotency keyYes, same key and payload
503 on a send without a keyOnly after checking status
409 with an idempotency conflictNo; the key was reused with another payload
400, 401, 403, 422No; fix the request or credential
submission_unknownDo not resend automatically; reconcile status first

Use exponential backoff with jitter for retries. A provider that may have accepted a message is never retried blindly: submission_unknown exists so you can look before sending again.

Async work and statuses

A 202 Accepted means Bonga recorded the request; it does not prove provider delivery. Track the returned message or job:

curl 'https://api.bonga.africa/api/v2/messages/msg_0123456789abcdef' \
  -H "Authorization: Bearer $BONGA_API_KEY"
StatusMeaning
queuedRecorded, not attempted
scheduledWaiting for its send time
sentConfirmed provider submission
delivered, readProvider receipt observed
failedDefinite failure; inspect error
submission_unknownThe provider may have accepted it; reconcile, never auto-resend

Retry-safe agent work

Agent keys can read their own approval and sending status. When a send returns pending_approval, do not rephrase and retry to get around the rule. Wait for a person, then read the approval with GET /api/v1/agent/approvals/{id} or the MCP get_approval tool.

Next