Responses & errors
Every endpoint answers with the same JSON envelope, so one function in your code handles them all.
The envelope
{
"success": true,
"data": {
"…": "…"
}
}{
"success": false,
"error": "validation failed: amount must be 1–250000 KES"
}Branch on success, or on the HTTP status. error is written for a developer to read; don't parse it.
Status codes
| 200 | Success. |
| 400 | The request is invalid. error starts with "validation failed:" and says which field and why, reads "malformed request" when the body is not JSON or has a field the endpoint does not accept, or says the provider cannot do this (for example STK on a provider without it). |
| 401 | Missing, unknown or revoked API key. |
| 403 | The key lacks the scope, or the account does not allow this (for example STK on a shared shortcode not enabled for you). |
| 404 | Not found, or not yours. |
| 409 | Conflicts with the current state. |
| 429 | Rate limited. Wait for Retry-After seconds. |
| 500 | Our fault. Retry; tell us if it persists. |
| 503 | Safaricom or KopoKopo is failing, slow or refusing the account's credentials. Retry later; for STK, look the reference up first: a refused prompt is recorded as failed, so a retry needs a new reference. |
Unknown fields are refused
Request bodies are decoded strictly: a misspelt field ("ammount") is a 400, never silently ignored. That catches integration bugs before they become missing money.
Pagination
List endpoints take page (from 1) and per_page (1–100, default 25) and return a meta block:
{
"success": true,
"data": [
"…"
],
"meta": {
"page": 1,
"per_page": 25,
"total": 132
}
}Rate limits
Limits are per API key and refill continuously:
POST /stk: about 60 a minute, bursts of 20.- Other writes: about 120 a minute, bursts of 30.
- Reads: about 300 a minute, bursts of 60.
Over the limit you get a 429 with Retry-After: 60.
Poll gently
Phone numbers
Every phone number we return, in responses and webhooks, is 2547XXXXXXXX or 2541XXXXXXXX: the international number without the +, twelve digits. It is the format Safaricom uses, and the one phone_sha256 is computed from. Send numbers in that form too. We also accept and convert 0712345678, 712345678 and +254712345678, but store and return only 254712345678, so compare against that.
Formats
- Money is a decimal string in KES,
"100.00". Requests accept a number or a string. - Times are RFC 3339 in UTC,
2026-12-03T17:59:20Z. - Phones are
254712345678: see phone numbers. - Ids are UUIDs.