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
| Key | Prefix | Can create sessions | Can set per-session policy | Can validate results |
|---|---|---|---|---|
| Publishable | pk_ | Yes, with your account's configured policy | No (ignored) | No |
| Secret | sk_ | Yes | Yes | Yes |
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"
}
| Field | Required | Description |
|---|---|---|
returnUrl | Yes | Where 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. |
externalUserId | No | Your 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. |
cancelUrl | No | Where 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. |
merchantName | No | Display name shown to the user during verification. |
verificationMode | No | Secret key only. "L1" or "L2". Overrides the account setting for this session. Omit it to use your Dashboard setting. |
challengeAge | No | Secret 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. |
faceMatchEnabled | No | Secret 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": "…"
}
| Field | Description |
|---|---|
sessionId | Identifies the session. Store it; you need it to validate the result. |
verifyUrl | The 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. |
expiresAt | When the session's 10-minute window ends. |
externalUserId | Your identifier, or null. |
faceMatchEnabled | Whether face matching applies to this session. |
sandboxMode | true while your account is using its sandbox allowance. See Test your integration. |
billingBlock | Present only when the session cannot proceed because your sandbox allowance is used up. See Account limits. |
sessionToken, handoffToken | Used by the hosted page. Do not parse, store or send them anywhere. |
testMode | Deprecated. Always false. |
Display parameters
You can append these to verifyUrl. They change only the presentation.
| Parameter | Values | Effect |
|---|---|---|
lang | en, de, es, fr, pt, it | Interface language. Without it, the user's browser language is used, then English. Regional variants such as pt-BR are accepted. |
skip_intro | true | Skip the introduction screen. |
auto_return | true | After 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:
| Parameter | Description |
|---|---|
sessionId | The session. |
status | verified. |
timestamp | Milliseconds since the Unix epoch. |
externalUserId | Only 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
cancelUrlwithsessionId,status=cancelledandtimestamp. - Return to site chosen before finishing: the verification page itself
navigates to
cancelUrl, or toreturnUrlif you set nocancelUrl, 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
}
| Field | Description |
|---|---|
accessGranted | true only when the session is verified. Base access decisions on this field. |
verified | Same value as accessGranted. |
status | verified, pending (not finished), cancelled, or failed (ended in an unrecoverable error). |
externalUserId | The value sent when the session was created. Check it matches the user you are granting access to. |
verificationMode, challengeAge, faceMatchEnabled | The policy the session used. |
merchantId | Your account ID (the same value as tenantId in webhooks). |
timestamp | When the session was created. |
expiresAt | When the session's 10-minute window ended or ends. A finished result does not expire at this time. |
testMode | Deprecated. 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"
}
| Status | Example message / code | Endpoint | Cause and fix |
|---|---|---|---|
400 | ["returnUrl must be a valid URL starting with http:// or https://"] | Both | Invalid request body. The messages say which field is wrong. |
400 | Return URL domain not allowed / Cancel URL domain not allowed | Create | The URL's domain is not in Configuration → Domains. Add it, or use an allowed URL. |
400 | Challenge age must be at least 25 | Create | Send 25 or above, or omit challengeAge. |
400 | Session has expired | Validate | The session ended unfinished. Start a new one. |
401 | API key required / Invalid API key | Both | Missing, mistyped or deleted key. |
401 | Private API key required for session validation | Validate | A publishable key (pk_) was used. Use your secret key. |
401 | Private API key is not authorized | Validate | The secret key is revoked or expired. |
401 | Tenant is not active | Both | The account is suspended or closed. Contact support. |
403 | API key not valid for this brand | Both | The key belongs to a different service. Use a SafePassage key with the SafePassage API address. |
403 | Origin '…' not allowed. Configure allowed domains in your dashboard. | Create (publishable key) | The browser page's origin is not in Configuration → Domains. |
403 | SUBSCRIPTION_REQUIRED and other account limits | Create | See Account limits. |
404 | Session not found | Validate | Unknown session ID, or a session that belongs to a different account. |
429 | Both | Rate limit exceeded. See Rate limits. | |
503 | SESSION_LAUNCH_CONFIGURATION_UNAVAILABLE | Create | The 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. |
5xx | Both | Temporary 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.
| Signal | Meaning | What 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_REQUIRED | No active paid plan and sandbox is off. | Subscribe to a plan in Billing. |
403 PLAN_LIMIT_REACHED | Your 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:
| Endpoint | Limit |
|---|---|
POST /sessions/create | 300 requests per 60 seconds |
POST /sessions/validate | 100 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).
- cURL
- Node.js
- PHP
# 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"}'
const headers = {
Authorization: `Bearer ${process.env.SAFEPASSAGE_SECRET_KEY}`,
'Content-Type': 'application/json',
};
const created = await fetch('https://api.safepassageapp.com/api/v1/sessions/create', {
method: 'POST',
headers,
body: JSON.stringify({ returnUrl: 'https://example.com/verify/return', externalUserId: 'user_12345' }),
});
const session = await created.json(); // { sessionId, verifyUrl, expiresAt, ... }
const validated = await fetch('https://api.safepassageapp.com/api/v1/sessions/validate', {
method: 'POST',
headers,
body: JSON.stringify({ sessionId: session.sessionId }),
});
const result = await validated.json(); // grant access only if result.accessGranted === true
<?php
function api_post(string $path, array $payload): array {
$ch = curl_init('https://api.safepassageapp.com/api/v1' . $path);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SAFEPASSAGE_SECRET_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
return [$status, json_decode((string) $raw, true)];
}
[$status, $session] = api_post('/sessions/create', [
'returnUrl' => 'https://example.com/verify/return',
'externalUserId' => 'user_12345',
]);
[$status, $result] = api_post('/sessions/validate', ['sessionId' => $session['sessionId']]);
// Grant access only if $status === 200 && $result['accessGranted'] === true
Related
- Server integration: complete, runnable examples
- Webhooks
- Age policy and verification modes
- Troubleshooting