> Toden documentation. For the full index fetch /llms.txt. Every page is available as Markdown by appending .md to its URL. Identity verification uses /api/kyc, Risk Intelligence uses /api/v1; they are separate contracts with different error shapes. Never invent an endpoint, field or enum value: read the API reference page for the operation first.

# Re-authenticate a verified person by face

POST https://sandbox-api.toden.co/api/kyc/biometric/authenticate
Content-Type: application/json

Matches a live selfie against the reference enrolled when the person was verified, and answers in the same call. A liveness failure and a face that does not match are both `200` responses with `authenticated: false`. A hosted verification session token is also accepted in place of a key.

An unknown reference, a business, and a person who is not enrolled all answer the same `404 not_enrolled`, so references cannot be probed.

**Sandbox.** Outside production the comparison is simulated and free. The outcome is `authenticated` unless `sandboxOutcome` pins another, or the `externalUserId` contains `no_match`, `nomatch` or `mismatch` (no match) or `bio_error` or `bioerror` (error).

**Billing.** Production attempts are charged per attempt. A `no_match` is charged, because the check ran. An attempt that fails with `502` is refunded.

**Error codes**

| `error` | Status | Meaning |
|---|---|---|
| `invalid_request` | 400 | The body failed validation. |
| `handoff_session_expired` | 401 | The hosted session token has expired. |
| `insufficient_credits` | 402 | The organisation's balance cannot cover the attempt. The `message` is written for the end user and does not mention credit. |
| `environment_mismatch` | 403 | The key belongs to an environment this deployment does not serve. |
| `origin_not_allowed` | 403 | The publishable key has an origin allowlist and the request origin is not on it. |
| `ip_not_allowed` | 403 | The secret key has an IP allowlist and the calling address is not on it. |
| `organization_suspended` | 403 | The organisation is suspended. The response carries `reason` and `suspendedAt`. |
| `business_not_approved` | 403 | A live key was used before the business was approved for production. |
| `not_enrolled` | 404 | There is no enrolled person under that reference. |
| `handoff_session_busy` | 409 | The hosted session is busy with another request. Retry shortly. |
| `handoff_session_used` | 409 | The hosted session has already been submitted. |
| `rate_limited` | 429 | The organisation's hourly limit was reached. |
| `authentication_failed` | 502 | The comparison could not be completed. |

A missing or unknown key answers `401`, where `error` is a short sentence rather than a code.

Accepts a publishable (`pk_`) or secret (`sk_`) key.

Reference: https://docs.toden.co/api-reference/verification/biometric-authentication/authenticate-biometric

## Authentication

- `Authorization` header (bearer token, required) — Send the API key as a Bearer token. Each operation states whether a publishable key is enough or a secret key is required.

## Servers

- `https://sandbox-api.toden.co` (Sandbox, default)
- `https://api.toden.co` (Production)

## Request

### Body (application/json)

This endpoint expects a BiometricAuthRequest.

- `externalUserId` (string, required) — Your reference for the person, the one their original verification was submitted with.
- `selfie` (string, required) — The `mediaId` of a live selfie uploaded through the upload endpoint with type `selfie`.
- `liveness` (BiometricAuthRequestLiveness, optional) — The liveness result reported by the capture. Required in effect: without it, or without a `mode`, the attempt answers `liveness_failed`.
- `sandboxOutcome` (string, optional) — Pins the simulated outcome outside production: `authenticated`, `no_match` or `error`, or `live` to run the real comparison on a development key. Ignored on live keys.

## Response

### 200

The attempt ran. Read `authenticated` for the outcome.

- `authenticated` (boolean, required) — True only when the person passed liveness and the selfie matched their enrolled reference.
- `status` (enum, required) — `authenticated`, `no_match` when the faces did not match, or `liveness_failed` when the liveness result did not pass.
  - Allowed values: `authenticated`, `no_match`, `liveness_failed`
- `confidence` (double, required, nullable) — The similarity score on a 0 to 100 scale. Null when no comparison ran.
- `live` (boolean, required) — Whether the liveness result was accepted.
- `attemptId` (string, required) — The id of this attempt, for your records.
- `token` (string, optional) — A single-use proof token, present only when `authenticated` is true. Your backend redeems it within 30 minutes to trust a result that came from a browser or app.

## Errors

### 400 Bad Request Error

The request body, query or path was invalid.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 401 Unauthorized Error

The Authorization header is missing, or the API key is unknown or revoked.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 402 Payment Required Error

The organisation does not have enough credit for this request.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 403 Forbidden Error

The key may not call this endpoint, or the organisation may not use this feature.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 404 Not Found Error

The resource does not exist for this organisation and environment.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 409 Conflict Error

The request conflicts with the current state of the resource.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 429 Too Many Requests Error

A rate limit was reached. Retry after a short wait.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

### 502 Bad Gateway Error

An upstream provider failed. Nothing was charged.

- `error` (string, required) — A stable machine-readable code such as `invalid_input`. Authentication failures (401) carry a short sentence here instead of a code.
- `message` (string, optional) — A human-readable explanation, safe to log. The wording may change.

## Types

### BiometricAuthRequestLiveness

The liveness result reported by the capture. Required in effect: without it, or without a `mode`, the attempt answers `liveness_failed`.

- `mode` (string, optional) — The liveness method that ran, for example `gestures` or `flash`.
- `passed` (boolean, optional) — Whether the liveness check passed.
- `flash` (BiometricAuthRequestLivenessFlash, optional) — The screen flash result, when that method ran.

### BiometricAuthRequestLivenessFlash

The screen flash result, when that method ran.

- `passed` (boolean, optional) — Whether the flash check passed.
- `inconclusive` (boolean, optional) — Whether the reflection could not be measured.

## Examples

**Request**

```json
{
  "externalUserId": "user_8f21",
  "selfie": "med_3f9c2a71d04e",
  "liveness": {
    "mode": "gestures",
    "passed": true
  }
}
```

**Response**

```json
{
  "authenticated": true,
  "status": "authenticated",
  "confidence": 96,
  "live": true,
  "attemptId": "cmt8s0a4p0004qw9k2m7f3ba1",
  "token": "bpt_example"
}
```

**SDK Code**

```python
import requests

url = "https://sandbox-api.toden.co/api/kyc/biometric/authenticate"

payload = {
    "externalUserId": "user_8f21",
    "selfie": "med_3f9c2a71d04e",
    "liveness": {
        "mode": "gestures",
        "passed": True
    }
}
headers = {
    "Authorization": "Bearer <apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox-api.toden.co/api/kyc/biometric/authenticate';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <apiKey>', 'Content-Type': 'application/json'},
  body: '{"externalUserId":"user_8f21","selfie":"med_3f9c2a71d04e","liveness":{"mode":"gestures","passed":true}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox-api.toden.co/api/kyc/biometric/authenticate"

	payload := strings.NewReader("{\n  \"externalUserId\": \"user_8f21\",\n  \"selfie\": \"med_3f9c2a71d04e\",\n  \"liveness\": {\n    \"mode\": \"gestures\",\n    \"passed\": true\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox-api.toden.co/api/kyc/biometric/authenticate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"externalUserId\": \"user_8f21\",\n  \"selfie\": \"med_3f9c2a71d04e\",\n  \"liveness\": {\n    \"mode\": \"gestures\",\n    \"passed\": true\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox-api.toden.co/api/kyc/biometric/authenticate")
  .header("Authorization", "Bearer <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"externalUserId\": \"user_8f21\",\n  \"selfie\": \"med_3f9c2a71d04e\",\n  \"liveness\": {\n    \"mode\": \"gestures\",\n    \"passed\": true\n  }\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox-api.toden.co/api/kyc/biometric/authenticate', [
  'body' => '{
  "externalUserId": "user_8f21",
  "selfie": "med_3f9c2a71d04e",
  "liveness": {
    "mode": "gestures",
    "passed": true
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox-api.toden.co/api/kyc/biometric/authenticate");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"externalUserId\": \"user_8f21\",\n  \"selfie\": \"med_3f9c2a71d04e\",\n  \"liveness\": {\n    \"mode\": \"gestures\",\n    \"passed\": true\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "externalUserId": "user_8f21",
  "selfie": "med_3f9c2a71d04e",
  "liveness": [
    "mode": "gestures",
    "passed": true
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox-api.toden.co/api/kyc/biometric/authenticate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```