Authentication
Exchange your client credentials for a short-lived bearer token, and send it on every request.
Superpay uses the OAuth 2.0 client credentials grant. Trade your client ID and secret for an access token, then send the token on every /v1 request.
Client ID + secretPOST /oauth2/tokenAccess tokenAuthorization: BearerAuthorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6ImFhZDcxZjM1NzNhNjAyYTMiLCJ0eXAiOiJKV1QifQ...Credentials#
Superpay issues your credentials. There is no API for creating, rotating or revoking them.
| Credential | Format | Example |
|---|---|---|
| Client ID | cli_ + 26 characters | cli_01M2FJA2M08R0T2V4X6Z8B0D2F |
| Client secret, test mode | Starts with sk_test_ | sk_test_... |
| Client secret, live mode | Starts with sk_live_ | sk_live_... |
- Each client ID and secret pair belongs to exactly one mode. Test and live each have their own pair.
- Treat the secret as an opaque string. Don't validate its length or characters.
- Save the secret when you receive it. Superpay can't show it again. If you lose it, ask for a new one.
Request an access token#
/oauth2/tokenSend the body as application/x-www-form-urlencoded. Authenticate with HTTP Basic (client_id:client_secret) or with form fields. If both are present, the Basic header is used and the form fields are ignored.
grant_typestringRequiredAlways client_credentials.
client_idstringYour client ID. Required unless you send credentials with HTTP Basic.
client_secretstringYour client secret. Required unless you send credentials with HTTP Basic.
scopestringSpace-separated scopes. Every scope must already be granted to your credential. Omit it to get every scope your credential holds.
curl https://api.withsuperpay.com/oauth2/token \
-u "$SUPERPAY_CLIENT_ID:$SUPERPAY_CLIENT_SECRET" \
-d grant_type=client_credentials \
--data-urlencode "scope=payouts:write payouts:read balances:read"curl https://api.withsuperpay.com/oauth2/token \
-d grant_type=client_credentials \
--data-urlencode "client_id=$SUPERPAY_CLIENT_ID" \
--data-urlencode "client_secret=$SUPERPAY_CLIENT_SECRET" \
--data-urlencode "scope=payouts:write payouts:read balances:read"{
"access_token": "eyJhbGciOiJFUzI1NiIsImtpZCI6ImFhZDcxZjM1NzNhNjAyYTMiLCJ0eXAiOiJKV1QifQ...",
"expires_in": 300,
"livemode": false,
"scope": "payouts:write payouts:read balances:read",
"token_type": "Bearer"
}Form-encoded, not JSON
A JSON body, a body without a Content-Type, and parameters in the query string are not read. Without a form-encoded grant_type, the request fails with 400 unsupported_grant_type. Only POST is accepted; any other method returns a 404 problem document with code UNKNOWN_ENDPOINT.
Response#
| Field | Type | Description |
|---|---|---|
access_token | string | The token. Send it as Authorization: Bearer <access_token>. Treat it as opaque. |
token_type | string | Always Bearer. |
expires_in | integer | Seconds until the token expires. Never more than 900. |
scope | string | Space-separated scopes the token carries. |
livemode | boolean | true for a live-mode token, false for test mode. |
No refresh token is returned. When a token expires, request a new one.
Use the token#
Send the token in the Authorization header of every /v1 request.
curl https://api.withsuperpay.com/v1/balances \
-H "Authorization: Bearer $SUPERPAY_TOKEN"- The header is the only place a token is accepted. Query parameters and cookies are ignored.
- The token decides your account, your mode and your scopes. Nothing in a request can change them.
- Every
/v1request is authenticated before routing. An unknown path without a token returns401, not404.
Token lifetime#
A token is valid for expires_in seconds from issue. Read the value from each response; don't hardcode it.
| Do | Don't |
|---|---|
| Cache one token and reuse it across requests | Request a token per API call |
Renew before it expires, e.g. at 80% of expires_in | Wait for a 401 on every expiry |
On 401 INVALID_TOKEN, get one new token and retry once | Retry in a loop |
Time renewal from when you received the response, using expires_in | Decode the token to read its expiry |
Token requests are deliberately slow, so reusing tokens keeps your integration fast. Tokens are independent: you can hold several valid tokens at once, for example one per worker.
const API = 'https://api.withsuperpay.com';
let cached = null; // { token, renewAt }
async function getToken() {
if (cached && Date.now() < cached.renewAt) return cached.token;
const credentials = `${process.env.SUPERPAY_CLIENT_ID}:${process.env.SUPERPAY_CLIENT_SECRET}`;
const res = await fetch(`${API}/oauth2/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${Buffer.from(credentials).toString('base64')}`,
},
body: new URLSearchParams({ grant_type: 'client_credentials' }),
});
const body = await res.json();
if (!res.ok) throw new Error(`token request failed: ${body.error}`);
cached = { token: body.access_token, renewAt: Date.now() + body.expires_in * 800 };
return cached.token;
}
async function superpay(path, init = {}) {
for (let attempt = 1; ; attempt++) {
const res = await fetch(`${API}${path}`, {
...init,
headers: { ...init.headers, Authorization: `Bearer ${await getToken()}` },
});
if (res.status !== 401 || attempt === 2) return res;
cached = null; // token rejected: get a fresh one and retry once
}
}import os
import time
import requests
API = "https://api.withsuperpay.com"
_cache = {"token": None, "renew_at": 0.0}
def get_token():
if _cache["token"] and time.time() < _cache["renew_at"]:
return _cache["token"]
res = requests.post(
f"{API}/oauth2/token",
auth=(os.environ["SUPERPAY_CLIENT_ID"], os.environ["SUPERPAY_CLIENT_SECRET"]),
data={"grant_type": "client_credentials"},
timeout=10,
)
body = res.json()
if res.status_code != 200:
raise RuntimeError(f"token request failed: {body['error']}")
_cache["token"] = body["access_token"]
_cache["renew_at"] = time.time() + body["expires_in"] * 0.8
return _cache["token"]
def superpay(method, path, headers=None, **kwargs):
for attempt in (1, 2):
merged = {**(headers or {}), "Authorization": f"Bearer {get_token()}"}
res = requests.request(method, f"{API}{path}", headers=merged, timeout=30, **kwargs)
if res.status_code != 401 or attempt == 2:
return res
_cache["token"] = None # token rejected: get a fresh one and retry onceScopes#
Each endpoint requires one scope. Scopes match exactly: payouts:write does not include payouts:read.
The scope field in the token response lists exactly what your token carries.
Least-privilege tokens#
Your credential holds a set of granted scopes. Use scope to mint a narrower token for a narrower job.
| Job | scope |
|---|---|
| Reporting, read-only | balances:read payouts:read fx:read treasury:read originators:read beneficiaries:read events:read |
| Onboarding and paying out | originators:write originators:read beneficiaries:write beneficiaries:read payouts:write payouts:read balances:read |
| Converting funds | fx:quote fx:execute fx:read balances:read treasury:read |
| Business verification and custody | treasury:manage treasury:read. Only treasury:read if your business is verified with the form and its people upload its documents there |
| Receiving events | events:read, and webhooks:manage to manage subscriptions |
Asking for a scope your credential doesn't hold fails with 400 invalid_scope; it is never silently dropped. To add scopes to a credential, contact Superpay. Changes apply to tokens issued afterwards.
Test and live mode#
The secret you authenticate with sets the mode. Everything else about authentication is the same.
| Test mode | Live mode | |
|---|---|---|
| Secret prefix | sk_test_ | sk_live_ |
livemode in responses | false | true |
| Host | https://api.withsuperpay.com | https://api.withsuperpay.com |
- There is no mode header, parameter or URL. Switching mode means switching credentials.
- A test secret never works with a live client ID, and a live secret never works with a test client ID.
- Test and live data are fully separate. An ID from one mode is not found in the other:
404in the path, a not-foundcodewith404or422when a request body refers to it. Idempotency keys are separate too. - Every resource the API returns carries
livemode. In a list, each item indatacarries it; the list itself doesn't. Check it before you act on a response.
See Testing for how test mode behaves, and Go live for getting live credentials.
Keep credentials safe#
- Call the API from your servers only. Never put a secret or token in a browser, mobile app or public repository.
- Store secrets in a secret manager. Don't log secrets or tokens.
- Suspect a leak? Contact Superpay to revoke the credential. New token requests with it fail straight away, but tokens already issued stay valid until they expire.
Errors#
Token endpoint#
POST /oauth2/token returns OAuth 2.0 errors, not problem documents. Branch on error; error_description is for people.
{
"error": "invalid_client",
"error_description": "client authentication failed"
}| HTTP | error | error_description | When | What to do |
|---|---|---|---|---|
| 400 | invalid_request | malformed form body | The request can't be parsed as a form: bad percent-encoding in the body or query string, or a malformed Content-Type | Send a correctly encoded application/x-www-form-urlencoded body |
| 400 | unsupported_grant_type | only client_credentials is supported | grant_type is missing or not client_credentials, including when the body is JSON | Send grant_type=client_credentials as a form field |
| 401 | invalid_client | client credentials required | No client ID or no secret was sent | Send both, with HTTP Basic or form fields |
| 401 | invalid_client | client authentication failed | Unknown client ID, wrong secret, a secret that doesn't start with sk_test_ or sk_live_, a test secret with a live client ID (or the reverse), or a revoked credential | Check you are using the matching pair for the mode you want. If it persists, contact Superpay |
| 400 | invalid_scope | scope not granted to this client: <scope> | A requested scope is misspelled or not granted. Only the first one is named | Request only granted scopes, or omit scope |
| 500 | server_error | could not issue token | Superpay couldn't issue the token | Retry with backoff |
A 401 also carries WWW-Authenticate: Basic realm="superpay". Every response carries an X-Request-Id header; quote it when you contact support.
API requests#
Authentication failures on /v1 endpoints are problem documents. Superpay checks, in order: a token is present, the token is valid, your account is active, the token has the endpoint's scope.
curl https://api.withsuperpay.com/v1/payouts \
-H "Authorization: Bearer $EXPIRED_TOKEN"HTTP/1.1 401 Unauthorized
Content-Type: application/problem+json
WWW-Authenticate: Bearer realm="superpay", error="invalid_token"
X-Request-Id: req_01M2FP1370C6D8E0F2G4H6J8K0
{
"type": "about:blank",
"title": "UNAUTHENTICATED",
"status": 401,
"detail": "the access token is invalid or expired",
"instance": "/v1/payouts",
"code": "INVALID_TOKEN",
"request_id": "req_01M2FP1370C6D8E0F2G4H6J8K0"
}code | HTTP | When | What to do |
|---|---|---|---|
UNAUTHENTICATED | 401 | No Authorization header, or it isn't Bearer <token> | Request a token and send it |
INVALID_TOKEN | 401 | The token is expired, malformed, altered, or signed with a key Superpay no longer uses | Request a new token and retry once |
TENANT_NOT_ACTIVE | 403 | Your account isn't active in this mode, so every /v1 request is refused | Contact Superpay if it persists. Token requests still succeed, so a new token won't help |
INSUFFICIENT_SCOPE | 403 | The token lacks the scope the endpoint requires. The response doesn't name it | Check the scopes table, then request a token that includes it |
Both 401 codes carry a WWW-Authenticate: Bearer realm="superpay" header, with error="invalid_token" added for INVALID_TOKEN. The 403 codes carry none. The detail never says exactly why a token was rejected. A token keeps the scopes it was issued with, even if your credential changes later.
Signing keys#
/.well-known/jwks.jsonAccess tokens are ES256-signed JWTs. Superpay verifies them for you, so you don't need this endpoint to call the API. Use it only if you want to verify a token yourself. No authentication.
{
"keys": [
{
"alg": "ES256",
"crv": "P-256",
"kid": "aad71f3573a602a3",
"kty": "EC",
"use": "sig",
"x": "pHQ6GyUqrY2nrRQU8dyPDkMexCG07V2XFSMKCK4UdzA",
"y": "890nu9IHc0onuth40Phrgu9Boy5l5ODB_Ew9WQI4wPU"
}
]
}- A token's
kidheader matches one key inkeys. During a key rotation the list holds two keys. - The response can be cached for 5 minutes. Refetch when you see a
kidyou don't have. - Don't build logic on the token's contents. Use
scope,expires_inandlivemodefrom the token response instead.