Integration Guide
Xident is a backend-first integration. Your server creates a verification session with its secret key, redirects the user to the Xident widget, and reads the result back. This guide covers the full flow and the options at each step. For a minimal walkthrough, start with the Quick Start.
The flow
- Create a session: your backend calls
POST /verify/v1/initwith its secret key and gets averify_url. - Redirect the user's browser to
verify_url. - Callback: Xident redirects the user back to your
callback_urlwith?status&token&user_id. - Read the result: your backend calls
GET /verify/v1/result/{token}with its secret key.
Security: Keep your secret key (sk_live_…) server-side only. Never trust the callback URL's status for authorization — always read the result server-side with GET /verify/v1/result/{token}.
Only your server sets up a verification
Every setting of a verification comes from the call your server makes to POST /verify/v1/init: the minimum age, the purpose, the verification mode, the user id, the liveness difficulty and the data match. Xident stores these settings with the init token. The person being verified controls their browser and the verify_url, so nothing they change there can change the settings. Query parameters on the widget URL are not read.
POST /verify/v1/initaccepts only a server key:sk_live_,sk_test_,ak_live_,ak_test_, or an agent access token (xat_). A public key (pk_live_,pk_test_) gets403 SECRET_KEY_REQUIRED.- So a page in the browser cannot start a verification. See No browser-only integration.
Prerequisites
- A secret key (
sk_live_…) from your dashboard - A callback URL on your domain (HTTPS in production;
http://localhostallowed in development) - A backend route to create the session and another to handle the callback
Step 1: Create a verification session
Call POST /verify/v1/init from your backend:
curl https://api.xident.io/verify/v1/init \
-X POST \
-H "X-API-Key: sk_live_your_secret_key" \
-H "Content-Type: application/json" \
-d '{
"callback_url": "https://yoursite.com/verified",
"purpose": "age_verification",
"user_id": "your-user-123",
"theme": "system",
"locale": "en"
}'
This request sends no min_age. That works for a website in Auto Mode, which has a content category: Xident then uses the minimum age of the local rule in the visitor's country. Without a content category, add min_age. See Minimum age and Auto Mode.
The response gives you the init token and the URL to send the user to:
{
"success": true,
"data": {
"token": "xit_9f8e7d6c5b4a...",
"verify_url": "https://verify.xident.io?t=xit_9f8e7d6c5b4a..."
}
}
Init options
| Field | Required | Description |
|---|---|---|
callback_url | Yes | Where Xident redirects the user afterward. HTTPS, or http://localhost in dev. |
user_id | Yes | Your own identifier for the person being verified. It comes back in the result as external_user_id and on the callback as user_id, exactly as you sent it. Missing or empty: 400 MISSING_USER_ID. A value that starts like a Xident key or token (sk_, ak_, xat_, xtk_ or xit_) gets 400 INVALID_USER_ID. |
min_age | No in Auto Mode (we recommend leaving it out). Required otherwise, for age verification | The minimum age, from 12 to 25. In Auto Mode (a website with a content category), Xident uses the minimum age of the local rule, and a min_age you send can only raise it. Without a content category it is required for an age verification. An ID document is checked at the minimum age exactly, so at 19 a person who is 19 passes. The camera age check starts from the next of 12, 15, 18, 21 or 25 at or above it, so 19 starts at 21. See Minimum age and Auto Mode. Leave it out, or send 0, when purpose is id_verification. Any other value: 400 INVALID_MIN_AGE. |
verification_mode | No | auto (default), document or facial. See Verification mode. Works together with min_age. facial cannot be combined with purpose: id_verification. |
purpose | No | age_verification (default) or id_verification. An ID verification checks identity: liveness, a document and a face match. It checks no age. To check an age with a forced document, use verification_mode: document instead. |
expected | No | Identity data you already hold about the user, to be checked against the document: first_name, last_name, date_of_birth (YYYY-MM-DD), document_number, nationality (ISO alpha-2). Any subset. Needs a document: purpose: id_verification or verification_mode: document. Only verdicts come back — see Data match. |
mismatch_policy | No | report (default): mismatches are reported in the result, the outcome is unchanged. review: any mismatch sends the session to your review queue with reason data_mismatch. Only with expected. |
liveness_difficulty | No | easy (default), medium or hard. Any other value: 400 INVALID_LIVENESS_DIFFICULTY. |
theme | No | light, dark, or system |
locale | No | en, es, fr, de, pt, pt-BR, ar, zh, ja, hi, nl. A region tag other than pt-BR is reduced to its language (de-AT → de); auto or an unknown value lets the browser decide. |
Errors from init
Branch on the code field of the error. Billing refusals (402) have their own section.
| Status | Code | When |
|---|---|---|
403 | SECRET_KEY_REQUIRED | The request used a public key. Use a server key. |
400 | MISSING_USER_ID | user_id is missing or empty. |
400 | INVALID_USER_ID | user_id starts with sk_, ak_, xat_, xtk_ or xit_, like a Xident key or token. |
400 | INVALID_MIN_AGE | min_age is not between 12 and 25 for an age verification, is missing on a website that is not in Auto Mode, or is set for an ID verification. |
400 | INVALID_VERIFICATION_MODE | An unknown verification_mode, or facial with purpose: id_verification. |
400 | INVALID_LIVENESS_DIFFICULTY | liveness_difficulty is not easy, medium or hard. |
400 | EXPECTED_REQUIRES_DOCUMENT | expected was sent for a session that reads no document. |
409 | IDEMPOTENCY_IN_FLIGHT | A request with the same Idempotency-Key is still running. Retry a moment later. |
422 | IDEMPOTENCY_KEY_MISMATCH | The same Idempotency-Key was used with a different body. See Retries and idempotency. |
Minimum age and Auto Mode
A website is in Auto Mode when it has a content category, for example gambling or alcohol. You choose the category in the dashboard. For each visitor, Xident finds the local rule of that category for the visitor's country, from their IP address. In the US it uses the rule of the visitor's state where there is one. Where no rule is listed for a country, the category's default age applies. The minimum age of that rule is the floor: nothing you set can go below it. In the dashboard, a website with Custom Age is still in Auto Mode: the local rule stays the floor, and the custom age can only raise it.
There are three cases:
- Auto Mode without your own age (recommended). Leave
min_ageout. Xident checks each visitor at the minimum age of their local rule. - Auto Mode with your own age. If your own policy needs an older age, send
min_age, or save your own minimum age on the website in the dashboard. Xident then uses the highest of the local rule, your saved age and themin_ageyou sent. Your age can make the check stricter. It never lowers a local rule. - No Auto Mode. Without a content category, every age verification must send
min_age(400 INVALID_MIN_AGEotherwise). Xident uses that age in every country, and a minimum age saved in the dashboard is not used. The age you choose is your responsibility. If you are not sure which age the law asks for, use Auto Mode. A website created in the dashboard has no rule besides its category. Without the category,POST /verify/v1/initstill answers201, but when the widget opens the link,GET /verify/v1/requirements/checkrefuses it with400 NO_RULEand no verification starts.
Example. A gambling website saved 18 as its own age and sends min_age: 18. The local rule for New Jersey is 21. A visitor in New Jersey is checked at 21, because the local rule is higher. If the website saved 25 instead, every visitor would be checked at 25.
How the age is checked. An ID document, and the date of birth on a returning person's Xident account, are checked at the minimum age exactly: at 19, a person who is 19 passes. The camera age check starts from the next of 12, 15, 18, 21 or 25 at or above the minimum age, so at 19 it starts at 21. The strictness setting and the country rules can make it start from an older one. A person the camera check refuses can go on to the document check where your plan and the session have one.
Reading the result. checks.age.gate is the minimum age of the session, exact, whatever completed it. In Auto Mode it can differ from one visitor to the next: 18 in one country, 21 in another. Your key can read the result token of any website of your account, and the result does not say which website it came from. So always compare gate with a constant on your server: the lowest age your website accepts in any country. Grant access when the result is verified, is not a test result (test is not true), its external_user_id is your signed-in user, and gate is a whole number at or above that age. If your website has its own minimum age, send it as min_age, or save it on the website, and compare gate with it. Do not require checks.age.passed: it is false when a returning person's Xident account proved the age.
Verification mode
By default Xident chooses the verification path from the visitor's country
and your content category. verification_mode overrides that for a
single session, so you can apply a stricter path to some products without
changing anything account-wide.
| Mode | What runs | When to use it |
|---|---|---|
auto (default) | Whatever the rule engine resolves for the visitor's country and your content category | Almost all traffic. Cheapest path that still satisfies local law. |
document | Liveness → document capture → face match. No on-device age estimation. Requires a plan that includes document verification. A person whose Xident account holds a verified government ID can sign in instead; the result then says verification_type: xident_id. | Age-restricted goods where you need the highest-assurance path regardless of how the on-device model would classify a borderline visitor. |
facial | Liveness → on-device age estimation. Never escalates to a document. | When you would rather fail a borderline visitor than ask for ID. |
It composes with min_age. Mode decides
how you verify; min_age decides what threshold
must be met. A store selling age-restricted products in the US might send
min_age: 21 with verification_mode: "document" for
those SKUs, and plain min_age: 18 on everything else — two calls
to the same endpoint, one API key. In Auto Mode the local rule's minimum age
applies in every mode, and the min_age you send can only raise
it.
This is the difference from purpose.
purpose: "id_verification" also forces a document and a face
match, but it checks identity, not age: it takes no min_age, and
its result has no checks.age.gate. If you need a document and an
age check, use verification_mode: "document" with
min_age. verification_mode: "facial" cannot be
combined with purpose: "id_verification": the request gets
400 INVALID_VERIFICATION_MODE.
curl https://api.xident.io/verify/v1/init \
-X POST \
-H "X-API-Key: sk_live_your_secret_key" \
-H "Content-Type: application/json" \
-d '{
"callback_url": "https://yoursite.com/verified",
"min_age": 21,
"verification_mode": "document",
"user_id": "your-user-123"
}'
facial and document both bypass the rule engine,
so you take on responsibility for the path being adequate in the visitor's
jurisdiction. auto keeps that with us.
An unrecognised value is rejected with
400 INVALID_VERIFICATION_MODE rather than silently falling back
to auto — a typo should fail your build, not quietly downgrade a
restricted checkout.
Step 2: Redirect the user
Redirect the user's browser to the verify_url from Step 1 (for example, an HTTP 302 from your backend route). The widget runs on verify.xident.io and handles liveness, age estimation, and document capture as required. The init token (xit_…) is in the URL as ?t=. The link works for 10 minutes. If the person reloads the page in that time, the verification starts again with the same settings. After 10 minutes, create a new token.
How the widget creates the session
You do not need to do anything here. This is for integrators who build their own front end, and for tests without a browser.
The widget reads the init token from ?t= and creates the session with GET /verify/v1/requirements/check. It sends your public key in X-API-Key and the init token in the X-Init-Token header. It sends no settings in the URL; the server reads every setting from the init token.
GET https://api.xident.io/verify/v1/requirements/check
X-API-Key: pk_live_your_public_key
X-Init-Token: xit_9f8e7d6c5b4a...
| Status | Code | When |
|---|---|---|
400 | MISSING_INIT_TOKEN | The X-Init-Token header is missing. |
404 | NOT_FOUND | The init token is unknown or older than 10 minutes. |
400 | INIT_TOKEN_KEY_MISMATCH | The init token belongs to another project than the key. |
400 | NO_RULE | The website has no content category and no rule. Choose a content category in the dashboard. |
409 | MIN_AGE_REQUIRED | The init token was created without min_age while the website was in Auto Mode, and the website has no content category any more. Create a new token with min_age. |
No session is created in any of these cases.
The server version, GET /verify/v1/requirements, does the same with a server key instead of the public key. It also needs the X-Init-Token header, and the token must belong to the key's project. A public key gets 403 SECRET_KEY_REQUIRED, and a key whose live or test mode differs from its project's gets 403 KEY_MODE_MISMATCH. The answer's session_id is the session's result token (xtk_…).
curl https://api.xident.io/verify/v1/requirements \
-H "X-API-Key: sk_test_your_test_secret_key" \
-H "X-Init-Token: xit_9f8e7d6c5b4a..."
Step 3: Handle the callback
When verification finishes, Xident redirects the user to your callback_url:
https://yoursite.com/verified?status=success&token=xtk_abc123&user_id=your-user-123
| Parameter | Description |
|---|---|
status | success, failed, or canceled |
token | Result token (xtk_…) — pass to the result endpoint |
user_id | The user_id you sent to init |
The callback only ever reports a terminal verdict (one of the three values above); GET /verify/v1/result/{token}'s own status field has a wider set covering the whole session lifecycle — see Core Concepts → Result Status Values.
Step 4: Read the result (server-side)
Fetch the authoritative result with your secret key:
curl https://api.xident.io/verify/v1/result/xtk_abc123 \
-H "X-API-Key: sk_live_your_secret_key"
data.verified is the one field to branch on for access control — a boolean, derived server-side from data.status, never trusted from the client. Right after a callback fires, data.status itself will normally read success, failed, or canceled, but see Core Concepts → Result Status Values for its full vocabulary and the API Reference for the full response schema.
checks.age.gate is the minimum age of the session, exact: 19 for a session at 19. In Auto Mode it is the highest of the local rule, your saved age and your min_age, so it can differ from one visitor to the next. Compare it with >= against the lowest age your website accepts, and check verification_type against what your checkout asked for. See Minimum age and Auto Mode. An ID verification (purpose: id_verification) checks no age, so its result has no gate.
Language SDKs
Server SDKs wrap these two calls (plus optional webhook verification). Use the one for your stack:
- Node.js
- Python
- Go
- PHP
- Mobile apps (Android / iOS) — the app opens
verify_url; init and result stay on your backend
Retries and idempotency
Send an Idempotency-Key header on
POST /verify/v1/verification-tokens/verify and a retry of the
same call will not be billed twice.
Idempotency-Key: 8f14e45f-ea6b-4f2c-b6d3-9c1a2b3c4d5e
Generate one value per logical call and reuse it across every retry of that call — a fresh value on each attempt defeats the purpose. Any string up to a reasonable length works; a UUID per request is the usual choice.
The key covers one user token in one 10-minute block of time. The blocks start at :00, :10, :20 and so on, in UTC. Xident picks the block with its own server clock, when it has checked the token, not with the time your request was sent. For example, 12:09:59 UTC is in the 12:00 block, and 12:10:00 starts the 12:10 block.
These rules are about successful checks. A retry with the same key and the same token in the same block adds no Check. The same key with another token, or in a later block, is a new Check. So a retry whose first attempt fell in the previous block counts once more. Every retry checks the token again, and the key does not repeat an earlier answer: an invalid, expired or revoked token is never a Check. The key is compared exactly as you send it. With no header, or an empty one, every successful check is a Check.
Why this is yours to send. Verifying a token is a read: it does not consume the token, so calling twice is two billable Checks. That is correct when you genuinely check a user twice, and wrong when your HTTP client retried after a timeout. Those are identical from our side. You know which one happened, so you tell us.
Without the header, billing is unchanged — one event per call. The header is optional and costs nothing to ignore.
POST /verify/v1/init takes the same header.
A retry with the same key and the same body returns the same token and
verify_url, for 10 minutes and only while that token still
exists. After that, the same key creates a new token. The key belongs to your
project. The same key with a different body gets
422 IDEMPOTENCY_KEY_MISMATCH: use a new key for new settings. A
retry that arrives while the first request is still running gets
409 IDEMPOTENCY_IN_FLIGHT; retry a moment later.
When billing refuses a session (402)
POST /verify/v1/init can be refused for a billing reason
before any verification work starts. All of these answer HTTP
402, and the code field is what you branch on — the
status alone does not tell you what to do, because the three remedies are
different and two of them are not yours to apply.
| Code | What happened | How it clears |
|---|---|---|
ALLOWANCE_EXHAUSTED | The included monthly volume is used up on a plan that stops at its allowance. | Buy a top-up pack in the dashboard. Costs money. |
BUDGET_EXCEEDED | Spend reached the monthly budget the account owner set and asked us to enforce. Never happens unless someone switched it on. | Raise or remove the budget in billing settings, or wait for the next billing month. Costs nothing. |
PAYMENT_REQUIRED | The account is suspended for non-payment. | Update the payment method. |
Do not collapse these into one "payment problem" message. Telling a customer to buy a pack when their own budget cap is what stopped them makes them pay for a remedy that does not unblock them.
Which plans can hit ALLOWANCE_EXHAUSTED.
Starter, Growth and Scale are post-paid: they do not stop at the
allowance, they simply meter the extra usage at the plan's own rate and bill
it monthly. Basic and the free sandbox do stop. On a paid plan the only
ceiling is the account's own budget, and only if it was switched on.
A refusal never interrupts work already in progress. The stop refuses to start a new session; a session already running always finishes and returns a result. By the time usage is metered the document has already been processed and paid for, so abandoning it would burn the cost and deliver nothing.
The language SDKs below do not yet raise a dedicated exception type for
402 — it surfaces as the generic API error, with the code
available on the error object. Branch on the code.
Security Best Practices
- Use HTTPS — callback URLs must be HTTPS (except
http://localhostin development). - Read results server-side — never trust the callback
statusalone; always callGET /verify/v1/result/{token}with your secret key. - Keep server keys on your server. Never ship
sk_live_…orak_live_…to a browser or a mobile app. The public key (pk_live_…) cannot start a verification and cannot read a result. - Use
X-API-Key. A server key also works asAuthorization: Bearer; when both are sent,X-API-Keywins. The widget's/requirements/checkendpoint reads onlyX-API-Key; other widget endpoints, such as the status endpoint, also accept a Bearer token. - Init token lifetime. The init token (
xit_…) works for 10 minutes. Create a new one for each verification. - Set
user_idfrom your own login session, andmin_age, when you send it, from your own rules. Never take them from a request the browser sent.
Testing
- Test keys. Create a project with Test mode key switched on in the dashboard. Its keys start with
sk_test_andpk_test_. You use them like live keys to start verifications and read results. Some endpoints refuse a test key: the document upload (/ocr/…),/tokens, the wallet and Face 2FA. - A test session decides at once. When the widget opens the
verify_url, the session gets its result with no camera step, and the widget returns to yourcallback_url. A test session is never billed, and its result carriestest: true. Never grant access on a result withtest: true. - Pass or fail on purpose. A test session passes. To make it fail, end the
user_idwith+fail, for example"user_id": "user-123+fail". It then fails with reasontest_mode. http://localhost:*callback URLs are allowed (no HTTPS required).- Use a second project for staging: separate key pair, separate webhook endpoint and secret.
curl https://api.xident.io/verify/v1/init \
-X POST \
-H "X-API-Key: sk_test_your_test_secret_key" \
-H "Content-Type: application/json" \
-d '{
"callback_url": "http://localhost:3000/verified",
"min_age": 18,
"user_id": "user-123+fail"
}'
To test without a browser, call GET /verify/v1/requirements with the same test key and the init token in X-Init-Token (see How the widget creates the session). The session is created and decided in that call. Read its result with the session_id from the answer.
A test key checks your integration, not the verification itself. To see a real verification, use a live key and a real person. Full matrix in Core Concepts.
No browser-only integration
A page in the browser cannot start a verification: POST /verify/v1/init refuses the public key with 403 SECRET_KEY_REQUIRED. The person being verified controls their browser, so a token made there would carry the settings they chose, for example a lower minimum age. Start every verification on your server, send the person to the verify_url, and read the result on your server.
Every project still has a public key (pk_live_…). The Xident widget uses it, together with the init token, to create the session. You do not need to use it yourself.
Next Steps
- Quick Start — minimal end-to-end example
- Core Concepts — the two-token model and verification paths
- API Reference — full generated API documentation