Authentication & API keys
Authenticate server-to-server requests with a secret key in the Authorization header. Keys are scoped, per environment, and can be rolled without downtime.
Bearer secret keys
Every /v1 request is authenticated with a secret key sent as a Bearer token:
curl https://beta.api.epay.lk/v1/balance \
-H "Authorization: Bearer $EPAY_SECRET_KEY"Keys look like sk_<env>_<32 characters>:
| Prefix | Environment |
|---|---|
sk_live_ | Production (beta.api.epay.lk) |
sk_test_ | Sandbox (beta.sandbox-api.epay.lk) |
sk_dev_ | Local development of ePay itself |
Create keys in the dashboard under Developers → API keys. The full key is shown once; ePay stores only a keyed hash of it, so a lost key can't be recovered — create a new one.
Secret keys never go in a browser or app
A secret key can create payments and refunds on your account. Keep it on your server — in environment variables or a secrets manager — and never in front-end JavaScript, mobile apps, Git repositories, logs or support tickets. Browsers and apps should call your backend, which calls ePay.
Scopes
Each key carries a list of scopes. Give each integration only what it needs — for example, a reporting job needs payments:read and balance:read but not payments:write.
| Scope | Allows |
|---|---|
payments:write | POST /v1/payments, POST /v1/payments/:id/cancel |
payments:read | GET /v1/payments, GET /v1/payments/:id |
refunds:write | POST /v1/refunds |
refunds:read | GET /v1/refunds, GET /v1/refunds/:id |
payment_links:write | POST /v1/payment_links |
payment_links:read | GET /v1/payment_links/:id |
events:read | GET /v1/events, GET /v1/events/:id |
balance:read | GET /v1/balance |
customers:read | Reserved for upcoming customer endpoints |
A request with a valid key that lacks the scope fails with 403 permission_error / missing_scope.
Authentication errors
| HTTP | code | Meaning |
|---|---|---|
| 401 | api_key_missing | No Authorization: Bearer … header |
| 401 | api_key_invalid | Malformed, unknown, revoked or expired key |
| 401 | api_key_environment_mismatch | e.g. an sk_test_ key sent to beta.api.epay.lk — use the matching hostname |
| 401 | publishable_key_not_allowed | A pk_… key was used on a secret-key endpoint |
| 403 | missing_scope | The key doesn't have the scope the endpoint requires |
| 403 | merchant_not_active | Production only: your business isn't verified/active yet |
| 429 | rate_limited | Too many requests for this key — back off and retry |
Rolling a key
Rotate keys periodically and immediately if one may have leaked. Rolling is zero-downtime:
- Create a new key with the same scopes.
- Deploy it to your servers and confirm traffic is using it — the dashboard shows each key's last used time.
- Revoke the old key. Revocation is immediate; any request still using it gets
401 api_key_invalid.
If a key is exposed (pushed to a public repo, pasted in a chat, logged), revoke it first and investigate afterwards. Review the Activity log for actions taken with it.
Publishable keys
Publishable keys (pk_live_… / pk_test_…) are reserved for future client-side features. No endpoint accepts them today. Everything in this documentation uses secret keys from your server.
Dashboard sessions are separate
The merchant dashboard uses its own cookie-based sessions with CSRF protection and optional TOTP two-factor authentication. Those sessions can't call /v1, and API keys can't sign in to the dashboard.
Environments & sandbox
Production and sandbox are separate deployments with separate accounts, keys, data and hostnames. Test everything in the sandbox with the bank simulator and test cards.
Create a payment
Create a payment on your server with POST /v1/payments, then send the payer to the hosted checkout.

