API keys & scopes
Your servers authenticate with API keys. Each key has scopes that decide which endpoints it may call, and can be revoked on its own.
Sending the key
curl https://api.mypayments.co.ke/api/v1/accounts \
-H "Authorization: Bearer $MYPAYMENTS_KEY"Keys start with mpk_. Keep them on your server, in an environment variable or a secret store. Never put one in a web page, a mobile app or a git repository: anyone holding it can prompt your customers for money.
Minting and revoking
Create keys in Dashboard → API keys. The full key is shown once; afterwards you see only its prefix and when it was last used. Revoking a key stops it at once. Use one key per system (your website, your billing server) so you can revoke one without touching the others.
You can only give a key scopes your own role has: a member who cannot initiate payments cannot mint a key that does.
Scopes
| Scope | Allows | Endpoints |
|---|---|---|
| accounts:read | List your accounts and read one | GET /accounts, GET /accounts/{id} |
| stk:initiate | Send STK Push prompts | POST /stk |
| transactions:read | Look up and list payments | GET /transactions, GET /transactions/{reference} |
| numbers:manage | Issue, list and close account numbers | POST /accounts/{id}/numbers, GET …/numbers, GET and DELETE /numbers/{id} |
| payouts:initiate | Reserved for the payout API (no endpoint yet) | — |
Give each key only what that system needs. A server that only checks payment status needs only transactions:read.
When a key is refused
- 401: no key, an unknown or revoked key, or a malformed header.
- 403: the key is valid but lacks the scope, for example
this API key lacks the "accounts:read" scope. - 404: the id is not one of yours. Another business's account or payment is indistinguishable from one that doesn't exist.
Dashboard-only operations
See responses & errors for the error envelope and rate limits.