Authentication

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: Bearer
HTTP
Authorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6ImFhZDcxZjM1NzNhNjAyYTMiLCJ0eXAiOiJKV1QifQ...

Credentials#

Superpay issues your credentials. There is no API for creating, rotating or revoking them.

CredentialFormatExample
Client IDcli_ + 26 characterscli_01M2FJA2M08R0T2V4X6Z8B0D2F
Client secret, test modeStarts with sk_test_sk_test_...
Client secret, live modeStarts 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#

POST/oauth2/token

Send 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_typestringRequired

Always client_credentials.

client_idstring

Your client ID. Required unless you send credentials with HTTP Basic.

client_secretstring

Your client secret. Required unless you send credentials with HTTP Basic.

scopestring

Space-separated scopes. Every scope must already be granted to your credential. Omit it to get every scope your credential holds.

Shell
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"

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#

FieldTypeDescription
access_tokenstringThe token. Send it as Authorization: Bearer <access_token>. Treat it as opaque.
token_typestringAlways Bearer.
expires_inintegerSeconds until the token expires. Never more than 900.
scopestringSpace-separated scopes the token carries.
livemodebooleantrue 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.

Shell
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 /v1 request is authenticated before routing. An unknown path without a token returns 401, not 404.

Token lifetime#

A token is valid for expires_in seconds from issue. Read the value from each response; don't hardcode it.

DoDon't
Cache one token and reuse it across requestsRequest a token per API call
Renew before it expires, e.g. at 80% of expires_inWait for a 401 on every expiry
On 401 INVALID_TOKEN, get one new token and retry onceRetry in a loop
Time renewal from when you received the response, using expires_inDecode 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.

Node.js
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
  }
}

Scopes#

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.

Jobscope
Reporting, read-onlybalances:read payouts:read fx:read treasury:read originators:read beneficiaries:read events:read
Onboarding and paying outoriginators:write originators:read beneficiaries:write beneficiaries:read payouts:write payouts:read balances:read
Converting fundsfx:quote fx:execute fx:read balances:read treasury:read
Business verification and custodytreasury:manage treasury:read. Only treasury:read if your business is verified with the form and its people upload its documents there
Receiving eventsevents: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 modeLive mode
Secret prefixsk_test_sk_live_
livemode in responsesfalsetrue
Hosthttps://api.withsuperpay.comhttps://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: 404 in the path, a not-found code with 404 or 422 when a request body refers to it. Idempotency keys are separate too.
  • Every resource the API returns carries livemode. In a list, each item in data carries 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.

401 Unauthorized
{
  "error": "invalid_client",
  "error_description": "client authentication failed"
}
HTTPerrorerror_descriptionWhenWhat to do
400invalid_requestmalformed form bodyThe request can't be parsed as a form: bad percent-encoding in the body or query string, or a malformed Content-TypeSend a correctly encoded application/x-www-form-urlencoded body
400unsupported_grant_typeonly client_credentials is supportedgrant_type is missing or not client_credentials, including when the body is JSONSend grant_type=client_credentials as a form field
401invalid_clientclient credentials requiredNo client ID or no secret was sentSend both, with HTTP Basic or form fields
401invalid_clientclient authentication failedUnknown 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 credentialCheck you are using the matching pair for the mode you want. If it persists, contact Superpay
400invalid_scopescope not granted to this client: <scope>A requested scope is misspelled or not granted. Only the first one is namedRequest only granted scopes, or omit scope
500server_errorcould not issue tokenSuperpay couldn't issue the tokenRetry 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.

Shell
curl https://api.withsuperpay.com/v1/payouts \
  -H "Authorization: Bearer $EXPIRED_TOKEN"
codeHTTPWhenWhat to do
UNAUTHENTICATED401No Authorization header, or it isn't Bearer <token>Request a token and send it
INVALID_TOKEN401The token is expired, malformed, altered, or signed with a key Superpay no longer usesRequest a new token and retry once
TENANT_NOT_ACTIVE403Your account isn't active in this mode, so every /v1 request is refusedContact Superpay if it persists. Token requests still succeed, so a new token won't help
INSUFFICIENT_SCOPE403The token lacks the scope the endpoint requires. The response doesn't name itCheck 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#

GET/.well-known/jwks.json

Access 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.

200 OK
{
  "keys": [
    {
      "alg": "ES256",
      "crv": "P-256",
      "kid": "aad71f3573a602a3",
      "kty": "EC",
      "use": "sig",
      "x": "pHQ6GyUqrY2nrRQU8dyPDkMexCG07V2XFSMKCK4UdzA",
      "y": "890nu9IHc0onuth40Phrgu9Boy5l5ODB_Ew9WQI4wPU"
    }
  ]
}
  • A token's kid header matches one key in keys. During a key rotation the list holds two keys.
  • The response can be cached for 5 minutes. Refetch when you see a kid you don't have.
  • Don't build logic on the token's contents. Use scope, expires_in and livemode from the token response instead.