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

# Create a session

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

Creates a hosted verification link for one applicant from a published workflow. The session carries one verification and is spent once submitted. Its configuration is fixed at creation, so later workflow edits do not change a link already sent.

**Error codes**

| `error` | Status | Meaning |
|---|---|---|
| `invalid_input` | 400 | The body failed validation. `message` names the first problem. |
| `invalid_reference_photo` | 400 | The reference face photo was not found. |
| `workflow_not_available` | 422 | The workflow is not published. |
| `user_reference_required` | 422 | A biometric workflow did not name its subject. |
| `not_enrolled` | 422 | The subject has no active biometric enrolment and no reference photo was given. |
| `rate_limited` | 429 | Too many sessions were started. Try again shortly. |
| `Missing or invalid Authorization header` | 401 | No bearer credential was sent. |
| `Invalid API key` | 401 | The key is unknown or revoked. |
| `environment_mismatch` | 403 | The key belongs to an environment this host does not serve. |
| `origin_not_allowed` | 403 | The request origin is not on the publishable key allowlist. |
| `ip_not_allowed` | 403 | The caller address is not on the secret key allowlist. |
| `organization_suspended` | 403 | The organisation is suspended. |
| `secret_key_required` | 403 | A publishable key was used on a secret-key endpoint. |
| `business_not_approved` | 403 | A production key was used before the business was approved. |

Requires a secret (`sk_`) key. A publishable key receives `403 secret_key_required`.

Reference: https://docs.toden.co/api-reference/verification/sessions/create-session

## 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 CreateSessionRequest.

- `workflowId` (string, required) — The published workflow to run.
- `externalUserId` (string, optional) — Your reference for the subject. It links the verification to your records and is what a returning applicant resumes by.
- `metadata` (map from string to any, optional) — Your own correlation fields, carried onto the verification and its webhooks. Bounded: at most 16 KiB, four levels deep and 100 keys.
- `faceReferenceMediaId` (string, optional) — Biometric authentication workflows only: the `mediaId` of a reference face photo uploaded with type `auth_reference`.
- `userData` (CreateSessionRequestUserData, optional) — What you already know about the subject, to prefill the flow. The applicant can correct every value.
- `email` (string, optional) — Email the link to this address on your behalf.
- `business` (CreateSessionRequestBusiness, optional) — For business workflows, the company where you already know it.
- `expectedIpAddress` (string, optional) — The IPv4 or IPv6 address you expect the applicant to verify from, compared by the workflow device rules.

## Response

### 201

The session was created.

- `session` (SessionLink, required) — A hosted verification session for one applicant.
- `delivery` (CreateSessionResponseDelivery, required, nullable) — Whether the link was emailed. Null when no `email` was given.

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

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

### 422 Unprocessable Entity Error

The request was understood but cannot be processed as sent.

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

## Types

### CreateSessionRequestUserData

What you already know about the subject, to prefill the flow. The applicant can correct every value.

- `firstName` (string, optional) — Given name.
- `lastName` (string, optional) — Family name.
- `dateOfBirth` (string, optional) — Date of birth.
- `businessName` (string, optional) — The business name, for business workflows.
- `email` (string, optional) — The applicant email address.

### CreateSessionRequestBusiness

For business workflows, the company where you already know it.

- `country` (string, optional) — ISO 3166 alpha-2 country code of the register.
- `registrationNumber` (string, optional) — The registration number.
- `registrationName` (string, optional) — The registered name.

### SessionLink

A hosted verification session for one applicant.

- `sessionId` (string, required) — The session identifier. The verification takes the same identifier once submitted.
- `url` (string, required) — The applicant link. Treat it as a credential: whoever opens it verifies as this applicant.
- `shortCode` (string, required) — A short code the applicant can type when a QR code cannot be scanned.
- `expiresAt` (datetime, required) — When the link stops accepting a new start.
- `kind` (enum, required) — What the session verifies, following the workflow.
  - Allowed values: `individual`, `business`
- `workflow` (SessionLinkWorkflow, required) — The workflow the session runs.
- `externalUserId` (string, required, nullable) — Your reference for the subject, as stored.
- `metadata` (map from string to any, optional, nullable) — Your customer metadata, as stored. Bounded: at most 16 KiB, four levels deep and 100 keys.

### CreateSessionResponseDelivery

Whether the link was emailed. Null when no `email` was given.

- `sent` (boolean, optional) — Whether the email was sent.
- `reason` (enum, optional) — Why the email was not sent. Present only when `sent` is false.
  - Allowed values: `send_failed`

### SessionLinkWorkflow

The workflow the session runs.

- `id` (string, required) — The workflow public identifier.
- `name` (string, required) — The workflow name.
- `version` (integer, required) — The published version the session was created from.

## Examples

**Request**

```json
{
  "workflowId": "wf_AbC123dEf456",
  "externalUserId": "user_42",
  "metadata": {
    "loanId": "loan_20191"
  },
  "userData": {
    "firstName": "Ada",
    "lastName": "Example"
  }
}
```

**Response**

```json
{
  "session": {
    "sessionId": "ses_01j9x2k4m8",
    "url": "https://verify.toden.co/session/hs_test_example",
    "shortCode": "7K9F-2QHM",
    "expiresAt": "2026-08-21T12:00:00.000Z",
    "kind": "individual",
    "workflow": {
      "id": "wf_AbC123dEf456",
      "name": "Identity verification",
      "version": 3
    },
    "externalUserId": "user_42",
    "metadata": {
      "loanId": "loan_20191"
    }
  },
  "delivery": null
}
```

**SDK Code**

```python
import requests

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

payload = {
    "workflowId": "wf_AbC123dEf456",
    "externalUserId": "user_42",
    "metadata": { "loanId": "loan_20191" },
    "userData": {
        "firstName": "Ada",
        "lastName": "Example"
    }
}
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/sessions';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <apiKey>', 'Content-Type': 'application/json'},
  body: '{"workflowId":"wf_AbC123dEf456","externalUserId":"user_42","metadata":{"loanId":"loan_20191"},"userData":{"firstName":"Ada","lastName":"Example"}}'
};

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/sessions"

	payload := strings.NewReader("{\n  \"workflowId\": \"wf_AbC123dEf456\",\n  \"externalUserId\": \"user_42\",\n  \"metadata\": {\n    \"loanId\": \"loan_20191\"\n  },\n  \"userData\": {\n    \"firstName\": \"Ada\",\n    \"lastName\": \"Example\"\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/sessions")

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  \"workflowId\": \"wf_AbC123dEf456\",\n  \"externalUserId\": \"user_42\",\n  \"metadata\": {\n    \"loanId\": \"loan_20191\"\n  },\n  \"userData\": {\n    \"firstName\": \"Ada\",\n    \"lastName\": \"Example\"\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/sessions")
  .header("Authorization", "Bearer <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"workflowId\": \"wf_AbC123dEf456\",\n  \"externalUserId\": \"user_42\",\n  \"metadata\": {\n    \"loanId\": \"loan_20191\"\n  },\n  \"userData\": {\n    \"firstName\": \"Ada\",\n    \"lastName\": \"Example\"\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/sessions', [
  'body' => '{
  "workflowId": "wf_AbC123dEf456",
  "externalUserId": "user_42",
  "metadata": {
    "loanId": "loan_20191"
  },
  "userData": {
    "firstName": "Ada",
    "lastName": "Example"
  }
}',
  '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/sessions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"workflowId\": \"wf_AbC123dEf456\",\n  \"externalUserId\": \"user_42\",\n  \"metadata\": {\n    \"loanId\": \"loan_20191\"\n  },\n  \"userData\": {\n    \"firstName\": \"Ada\",\n    \"lastName\": \"Example\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "workflowId": "wf_AbC123dEf456",
  "externalUserId": "user_42",
  "metadata": ["loanId": "loan_20191"],
  "userData": [
    "firstName": "Ada",
    "lastName": "Example"
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox-api.toden.co/api/kyc/sessions")! 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()
```