Authorization header on every call. This page explains how to generate keys, request tokens, and keep your credentials safe.
How API keys work
Each API key pair has two parts that do different jobs:
The
test prefix marks sandbox keys and the live prefix marks production keys. A sandbox key pair never works against production, and the reverse is also true.
Generate an API key pair
You must complete KYC verification before you can generate API keys. Sandbox keys unlock after KYC approval; live keys also require approved production access.
1
Sign in to the dashboard
Sign in to the PeerPesa dashboard. Use the sandbox dashboard for test keys and the production dashboard for live keys.
2
Open API Keys
Go to Settings > API Keys and select Generate new key.
3
Name the key
Give the key a descriptive label, such as
payouts-backend, so you can identify it later when rotating or revoking.4
Copy both keys
The dashboard shows the public key and the secret key. Copy the secret key immediately and store it in a secrets manager or environment variable.
.env
Request an access token
Exchange your key pair for an access token withPOST /auth/token.
string
required
Your public key, starting with
pk_test_ or pk_live_.string
required
The secret key generated with the public key, starting with
sk_test_ or sk_live_.Response
string
Token to send in the
Authorization header.string
Always
Bearer.integer
Seconds until the token expires. Defaults to
3600 (1 hour).Authorize API requests
Send the access token in theAuthorization header on every request except POST /auth/token.
Token expiry and renewal
Tokens expire afterexpires_in seconds. Requests with an expired or missing token return 401 with code unauthorized. There is no refresh token: request a new token with your key pair and retry. Cache the token and renew it a minute or two before it expires to avoid failed requests.
Token cache
Rotate and revoke keys
- Rotate: generate a new key pair, deploy it to your servers, then revoke the old pair. Both pairs work until you revoke the old one, so rotation needs no downtime.
- Revoke: in Settings > API Keys, select the key and choose Revoke. Tokens issued from a revoked pair stop working immediately.
Authentication errors
Environments
Sandbox quotes and transactions never move real funds.
