Skip to main content

Sessions API

Reference for creating verification sessions and confirming their results. For a step-by-step walkthrough with complete code, see Server integration.

Base URL and authentication​

https://api.safepassageapp.com/api/v1

Send your API key as a bearer token:

Authorization: Bearer sk_your_secret_key
Content-Type: application/json
KeyPrefixCan create sessionsCan set per-session policyCan validate results
Publishablepk_Yes, with your account's configured policyNo (ignored)No
Secretsk_YesYesYes

The key identifies your account. Keys from one account cannot read sessions of another account, and SafePassage keys work only with the SafePassage API address above.

Create Session​

POST /api/v1/sessions/create

Creates a verification session and returns the link to send the user to.

Request body​

{
"returnUrl": "https://example.com/verify/return",
"externalUserId": "user_12345"
}
FieldRequiredDescription
returnUrlYesWhere the user is sent after a successful verification. Must start with http:// or https://; use https:// for anything other than local testing. When your account has allowed domains, the host must be one of them or a subdomain of one.
externalUserIdNoYour identifier for the user (up to 255 characters). Returned by Validate Session and included in webhooks and the Dashboard. Do not use an email address or other personal data.
cancelUrlNoWhere the user is sent if they leave without finishing, including from a new-tab or popup verification. Same rules as returnUrl. Without it, a user who leaves is sent to returnUrl without parameters.
merchantNameNoDisplay name shown to the user during verification.
verificationModeNoSecret key only. "L1" or "L2". Overrides the account setting for this session. Omit it to use your Dashboard setting.
challengeAgeNoSecret key only. Whole number, 25 or above; the Dashboard accepts 25 to 99. Overrides the account setting for this session. Applies only to the L1 selfie estimate; see Age policy.
faceMatchEnabledNoSecret key only. false skips the selfie-to-ID face comparison where it is not permitted. Default true.

Each successful call creates a new session. If a call times out and you retry it, you may create a second session; that is harmless, because sessions that are never completed expire after 10 minutes and are not billed. Use the sessionId from the response you act on.

Older integrations may send merchantId. It is not needed: the API key identifies your account. Leave it out.

Response: 201 Created​

{
"sessionId": "550e8400-e29b-41d4-a716-446655440000",
"sessionToken": "v2.eyJ…",
"verifyUrl": "https://av.safepassageapp.com/?sessionId=550e8400-…&sessionToken=v2.eyJ…",
"expiresAt": "2026-11-17T10:10:00.000Z",
"externalUserId": "user_12345",
"faceMatchEnabled": true,
"sandboxMode": true,
"testMode": false,
"handoffToken": "…"
}
FieldDescription
sessionIdIdentifies the session. Store it; you need it to validate the result.
verifyUrlThe hosted verification page. Redirect the user to it exactly as returned. You may add the display parameters below, but do not rebuild the URL or remove anything from it.
expiresAtWhen the session's 10-minute window ends.
externalUserIdYour identifier, or null.
faceMatchEnabledWhether face matching applies to this session.
sandboxModetrue while your account is using its sandbox allowance. See Test your integration.
billingBlockPresent only when the session cannot proceed because your sandbox allowance is used up. See Account limits.
sessionToken, handoffTokenUsed by the hosted page. Do not parse, store or send them anywhere.
testModeDeprecated. Always false.

Display parameters​

You can append these to verifyUrl. They change only the presentation.

ParameterValuesEffect
langen, de, es, fr, pt, itInterface language. Without it, the user's browser language is used, then English. Regional variants such as pt-BR are accepted.
skip_introtrueSkip the introduction screen.
auto_returntrueAfter a successful verification, return to returnUrl immediately instead of showing the success screen.

Return to your site​

After a successful verification, the user is sent to returnUrl with these parameters added:

ParameterDescription
sessionIdThe session.
statusverified.
timestampMilliseconds since the Unix epoch.
externalUserIdOnly if you sent one.

Two other returns are possible:

  • New-tab or popup verification closed early: the verification window is gone, so your original page (the one that opened it) is sent to cancelUrl with sessionId, status=cancelled and timestamp.
  • Return to site chosen before finishing: the verification page itself navigates to cancelUrl, or to returnUrl if you set no cancelUrl, without parameters. The session stays open until it expires.

These parameters are notifications, not proof. Anyone can type them. Always validate the session on your server before granting access.

Validate Session​

POST /api/v1/sessions/validate

Returns the authoritative result of a session. Requires a secret key.

Request body​

{
"sessionId": "550e8400-e29b-41d4-a716-446655440000"
}

Send only sessionId.

Response: 200 OK​

{
"sessionId": "550e8400-e29b-41d4-a716-446655440000",
"merchantId": "9fe431ea-ad69-46d7-a201-c3481fffdb99",
"status": "verified",
"verified": true,
"accessGranted": true,
"verificationMode": "L2",
"challengeAge": 25,
"faceMatchEnabled": true,
"externalUserId": "user_12345",
"timestamp": "2026-11-17T10:00:00.000Z",
"expiresAt": "2026-11-17T10:10:00.000Z",
"testMode": false
}
FieldDescription
accessGrantedtrue only when the session is verified. Base access decisions on this field.
verifiedSame value as accessGranted.
statusverified, pending (not finished), cancelled, or failed (ended in an unrecoverable error).
externalUserIdThe value sent when the session was created. Check it matches the user you are granting access to.
verificationMode, challengeAge, faceMatchEnabledThe policy the session used.
merchantIdYour account ID (the same value as tenantId in webhooks).
timestampWhen the session was created.
expiresAtWhen the session's 10-minute window ended or ends. A finished result does not expire at this time.
testModeDeprecated. Always false.

Validating more than once​

You can validate the same session as often as you need, including after its 10-minute window, after a dropped connection, or from both your return page and your webhook handler. Each call returns the current result and never creates another verification, charge or webhook. A session that is still pending when its window ends becomes expired, and then returns 400 Session has expired.

Errors​

Errors use this format. message is a string or, for invalid request bodies, an array of strings. Some errors include a machine-readable code.

{
"statusCode": 403,
"message": "A subscription is required for production verifications. Please subscribe to a plan to continue.",
"code": "SUBSCRIPTION_REQUIRED",
"timestamp": "2026-11-17T10:00:00.000Z",
"path": "/api/v1/sessions/create"
}
StatusExample message / codeEndpointCause and fix
400["returnUrl must be a valid URL starting with http:// or https://"]BothInvalid request body. The messages say which field is wrong.
400Return URL domain not allowed / Cancel URL domain not allowedCreateThe URL's domain is not in Configuration → Domains. Add it, or use an allowed URL.
400Challenge age must be at least 25CreateSend 25 or above, or omit challengeAge.
400Session has expiredValidateThe session ended unfinished. Start a new one.
401API key required / Invalid API keyBothMissing, mistyped or deleted key.
401Private API key required for session validationValidateA publishable key (pk_) was used. Use your secret key.
401Private API key is not authorizedValidateThe secret key is revoked or expired.
401Tenant is not activeBothThe account is suspended or closed. Contact support.
403API key not valid for this brandBothThe key belongs to a different service. Use a SafePassage key with the SafePassage API address.
403Origin '…' not allowed. Configure allowed domains in your dashboard.Create (publishable key)The browser page's origin is not in Configuration → Domains.
403SUBSCRIPTION_REQUIRED and other account limitsCreateSee Account limits.
404Session not foundValidateUnknown session ID, or a session that belongs to a different account.
429BothRate limit exceeded. See Rate limits.
503SESSION_LAUNCH_CONFIGURATION_UNAVAILABLECreateThe secret key's key pair has no active publishable key. Create or restore the key pair in API Keys, then retry. Do not build a verification link yourself.
5xxBothTemporary problem. Retry with a short delay; never treat it as verified.

Account limits​

Session creation can be stopped by your account's plan or subscription state.

SignalMeaningWhat to do
201 with billingBlock.code: "SANDBOX_LIMIT_REACHED"Your sandbox allowance is used up. The returned verifyUrl shows the user a "Sandbox Limit Reached" screen.Subscribe to a plan in Billing.
403 SUBSCRIPTION_REQUIREDNo active paid plan and sandbox is off.Subscribe to a plan in Billing.
403 PLAN_LIMIT_REACHEDYour plan's monthly verification limit is reached. New sessions are refused until the next billing period.Upgrade your plan in Billing, or contact support@safepassageapp.com.

Check for billingBlock in a 201 response as well as for 403 errors. When you use the JavaScript SDK, it shows these screens to the user automatically. See Plans, billing and limits.

Rate limits​

Limits apply per account, shared by all of its keys:

EndpointLimit
POST /sessions/create300 requests per 60 seconds
POST /sessions/validate100 requests per 60 seconds

Responses include X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Window. A 429 response also includes X-RateLimit-Retry-After (seconds). If you need higher limits, contact sales.

Code examples​

These examples use your account's configured policy (no override fields).

# Create a session
curl -X POST "https://api.safepassageapp.com/api/v1/sessions/create" \
-H "Authorization: Bearer $SAFEPASSAGE_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"returnUrl": "https://example.com/verify/return", "externalUserId": "user_12345"}'

# Validate it
curl -X POST "https://api.safepassageapp.com/api/v1/sessions/validate" \
-H "Authorization: Bearer $SAFEPASSAGE_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"sessionId": "550e8400-e29b-41d4-a716-446655440000"}'