> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.portreeve.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.portreeve.com/_mcp/server.

# Exchange fingerprint components for a device token

POST https://api.portreeve.com/v1/device
Content-Type: application/json

Called from the **browser**, cross-origin, with your **publishable** key (`pk_live_…` / `pk_test_…`) — never the secret key. In practice you do not call this yourself: `@portreeve/browser`'s `collectDeviceToken()` does, and resolves to `null` instead of throwing when collection is blocked.

The raw components never leave the request — they are hashed server-side and the response is a short-lived signed token you forward to your own backend and pass through as `device_token` on the verdict call. This is the only endpoint with CORS enabled and the only one a publishable key can reach.

A `device_token` that is expired, tampered with, or minted for a different tenant or mode is **silently dropped** by `POST /v1/verdict`: the verdict still returns 200, simply without device signals. A bad token never rejects or degrades a verdict call.

Reference: https://docs.portreeve.com/api-reference/device/create-device-token

## Authentication

- `Authorization` header (bearer token, required) — `Authorization: Bearer pk_live_…` (or `pk_test_…`). Public by design — it is meant to appear in page source. It can mint device tokens and nothing else; it is rejected on every other endpoint.

## Request

### Body (application/json)

This endpoint expects a DeviceRequest.

- `components` (map from string to any, required) — Component name → value. Keys up to 64 characters; values are opaque. Hashed server-side; the raw components are not stored.

## Response

### 200

A signed, short-lived device token.

- `device_token` (string, required) — Forward this to your own backend and pass it through as `device_token` on the verdict call.
- `expires_at` (datetime, required) — RFC 3339 timestamp. Tokens are short-lived — collect close to the screened action, not at page load.

## Errors

### 400 Bad Request Error

The body failed contract validation (for example a component key longer than 64 characters, or an unknown top-level key).

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 401 Unauthorized Error

This endpoint requires a publishable key (`pk_live_…` / `pk_test_…`). Secret keys are rejected here.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 429 Too Many Requests Error

Per-key rate limit exceeded (default 600 requests/minute per API key; requests with an unparseable key are bucketed per source IP). `retry-after` and `x-ratelimit-*` headers accompany the response. Retry after the window; do not treat this as a verdict.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 500 Internal Server Error

Unhandled server error. The verdict engine itself fails open rather than 500ing — a rules bug returns `allow` with no reasons — so a 500 here means the request never reached a decision. Treat as retryable.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

## Examples

### a signed device token

**Response**

```json
{
  "device_token": "dtk_2ZqX7Yk1",
  "expires_at": "2026-08-16T10:41:02.417Z"
}
```

**SDK Code**

```python a signed device token
import requests

url = "https://api.portreeve.com/v1/device"

headers = {"Authorization": "Bearer <token>"}

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

print(response.json())
```

```javascript a signed device token
const url = 'https://api.portreeve.com/v1/device';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

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

```go a signed device token
package main

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

func main() {

	url := "https://api.portreeve.com/v1/device"

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

	req.Header.Add("Authorization", "Bearer <token>")

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

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

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

}
```

```ruby a signed device token
require 'uri'
require 'net/http'

url = URI("https://api.portreeve.com/v1/device")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

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

```java a signed device token
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.portreeve.com/v1/device")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php a signed device token
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.portreeve.com/v1/device', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp a signed device token
using RestSharp;

var client = new RestClient("https://api.portreeve.com/v1/device");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift a signed device token
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.portreeve.com/v1/device")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```

### FingerprintJS v5 components

**Request**

```json
{
  "components": {
    "canvas": "a1b2c3",
    "fonts": [
      "Arial",
      "Helvetica"
    ],
    "timezone": "Europe/London"
  }
}
```

**Response**

```json
{
  "device_token": "dtk_2ZqX7Yk1",
  "expires_at": "2026-08-16T10:41:02.417Z"
}
```

**SDK Code**

```python FingerprintJS v5 components
import requests

url = "https://api.portreeve.com/v1/device"

payload = { "components": {
        "canvas": "a1b2c3",
        "fonts": ["Arial", "Helvetica"],
        "timezone": "Europe/London"
    } }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript FingerprintJS v5 components
const url = 'https://api.portreeve.com/v1/device';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"components":{"canvas":"a1b2c3","fonts":["Arial","Helvetica"],"timezone":"Europe/London"}}'
};

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

```go FingerprintJS v5 components
package main

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

func main() {

	url := "https://api.portreeve.com/v1/device"

	payload := strings.NewReader("{\n  \"components\": {\n    \"canvas\": \"a1b2c3\",\n    \"fonts\": [\n      \"Arial\",\n      \"Helvetica\"\n    ],\n    \"timezone\": \"Europe/London\"\n  }\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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 FingerprintJS v5 components
require 'uri'
require 'net/http'

url = URI("https://api.portreeve.com/v1/device")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"components\": {\n    \"canvas\": \"a1b2c3\",\n    \"fonts\": [\n      \"Arial\",\n      \"Helvetica\"\n    ],\n    \"timezone\": \"Europe/London\"\n  }\n}"

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

```java FingerprintJS v5 components
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.portreeve.com/v1/device")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"components\": {\n    \"canvas\": \"a1b2c3\",\n    \"fonts\": [\n      \"Arial\",\n      \"Helvetica\"\n    ],\n    \"timezone\": \"Europe/London\"\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.portreeve.com/v1/device', [
  'body' => '{
  "components": {
    "canvas": "a1b2c3",
    "fonts": [
      "Arial",
      "Helvetica"
    ],
    "timezone": "Europe/London"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp FingerprintJS v5 components
using RestSharp;

var client = new RestClient("https://api.portreeve.com/v1/device");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"components\": {\n    \"canvas\": \"a1b2c3\",\n    \"fonts\": [\n      \"Arial\",\n      \"Helvetica\"\n    ],\n    \"timezone\": \"Europe/London\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift FingerprintJS v5 components
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["components": [
    "canvas": "a1b2c3",
    "fonts": ["Arial", "Helvetica"],
    "timezone": "Europe/London"
  ]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.portreeve.com/v1/device")! 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()
```