knownprintDocs

Get started

Quickstart

Add knownprint to a site in three steps (a proxy rule, a script tag and one backend call) with a complete example in curl and Node.

This page takes one form on your site, a signup form, from nothing to a decision in your backend. It takes three changes:

  1. A proxy rule that forwards /kp/ on your domain to knownprint.
  2. A script tag, and a few lines that identify the browser when the form is submitted and post the request id with the form.
  3. One call in your backend that reads the event for that request id and checks it.

Each step links to the page that covers it in full.

Before you start

You need, from your knownprint account:

WhatLooks likeWhere it goes
The API addressa URLyour backend, as KNOWNPRINT_API
A public keypk_live_ or pk_test_ and 32 charactersthe page
A secret keysk_live_ or sk_test_ and 32 charactersyour backend only, as KNOWNPRINT_SECRET_KEY
A proxy secret32 charactersyour proxy configuration only
Your proxy snippetan nginx or Caddy fileyour web server

Every account has a live environment and a test environment, each with its own keys and proxy secret. Use the test environment's values while you build. Concepts explains the difference, and Keys and secrets explains where each one may be used.

The public key must list the origin of every page that runs the script, exactly as the browser writes it: scheme, host and port, such as https://www.example.com. A page whose origin is not on the list is refused. https://example.com and https://www.example.com are two origins.

Step 1: Add the proxy rule

Your web server forwards every request under /kp/ to knownprint, with your proxy secret and the visitor's address. Only knownprint's own cookie goes through; your session cookies stay on your server.

nginx
# Once, inside the http block:
include /etc/knownprint/knownprint-map.conf;

server {
    listen 443 ssl;
    server_name www.example.com;
    # ... your existing TLS and site configuration ...

    # Inside your site's TLS server block:
    include /etc/knownprint/knownprint.conf;

    # Your application, as before. Your backend needs the visitor's address (step 3).
    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
Caddy
# The knownprint snippet from your account sits at the top level of the
# Caddyfile (or is imported there). Then, inside your site block:
www.example.com {
	import knownprint

	# Your application, as before. reverse_proxy sends X-Forwarded-For itself.
	handle {
		reverse_proxy localhost:3000
	}
}

The paths above are examples: use wherever you saved the files from your account. The location / block is your own: nginx sends no X-Forwarded-For to your application unless you set it, and the backend in step 3 reads the visitor's address from it. The nginx recipe keeps the proxy secret in a separate file that only root and the group of the nginx workers can read; Caddy reads it from the KNOWNPRINT_PROXY_SECRET environment variable, set from a file only root can read. The full recipes, what each part does and the Cloudflare variant are in The proxy, nginx, Caddy and Cloudflare.

Reload your server and check that the script loads from your own domain:

Shell
curl -sS -o /dev/null -D - https://www.example.com/kp/agent.js

The answer is 200 with Cache-Control: public, max-age=3600, s-maxage=60.

Step 2: Add the script and send the request id

Add the script tag to the page with the form, and a hidden field for the request id:

signup.html
<script src="/kp/agent.js" defer></script>

<form id="signup" method="post" action="/signup">
  <input name="email" type="email" required>
  <input name="password" type="password" required>
  <input name="kp_request_id" type="hidden">
  <button type="submit">Create account</button>
</form>

Then identify the browser when the form is submitted, not when the page loads. A request id is meant to be checked within 10 seconds of the identification, so take it right before the form is sent:

signup.html
<script>
  const PUBLIC_KEY = 'pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  const form = document.getElementById('signup');
  let resubmitting = false;

  form.addEventListener('submit', async (event) => {
    if (resubmitting) return; // our own resubmit below: let it through
    event.preventDefault();
    const field = form.elements.kp_request_id;
    field.value = '';
    try {
      const { requestId } = await Promise.race([
        window.knownprint.load({ pk: PUBLIC_KEY }).then((agent) => agent.identify()),
        new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 3000)),
      ]);
      field.value = requestId;
    } catch (err) {
      // Blocked, offline or too slow: the form goes without a request id.
    }
    resubmitting = true;
    try {
      form.requestSubmit(event.submitter);
    } finally {
      resubmitting = false;
    }
  });
</script>

What this does:

  • window.knownprint.load({ pk }) loads the agent once and resolves the same agent on every later call with the same options. The default profile is full; see Profiles.
  • agent.identify() runs one identification and resolves { requestId, expiresAt }. The page never sees the visitor id, the confidence or the signals.
  • The form is always sent. If the script was blocked, failed, or took longer than 3 seconds, the field is empty and your backend treats the visit as unknown.
  • requestSubmit(event.submitter) sends the form again with the button the visitor pressed, so its name and value still reach your backend. It dispatches the submit event at once, so the flag is cleared again right after it.

To attach your own account id to the event from the page, pass it to identify: agent.identify({ linkedId: 'acct_1042' }). For a signup, where the account does not exist yet, set it from your backend after the account is created (step 3).

The browser agent covers every option of load and identify, and the errors they reject with. Forms covers several forms on a page, single-page applications and fetch submissions. If your site sends a Content Security Policy, add what Content Security Policy lists.

Step 3: Read the event in your backend

Your backend receives the form with kp_request_id. It reads the event with your secret key:

HTTP
GET /v1/events/evt_q3vx7k2mz4rb6nw5tc2ehj7ypd
Authorization: Bearer sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Before it trusts the answer, it checks four things:

CheckHowWhy
Used onceRecord each request id the first time you see it; refuse one you have seen.A request id stolen from one visit cannot be posted again.
Freshreceived_at is at most 10 seconds before now (allow some clock skew the other way).An old request id cannot be saved up and used later.
Not replayed, from your pageintegrity.replayed is false and integrity.origin is your page's origin.The identification came from your own page and was not a replay.
Same addressnetwork.ip is the address your own proxy saw for the form post.The browser that identified is the one that sent the form.

An address that changed between the identification and the form post can be innocent (a phone moving from Wi-Fi to mobile data, a privacy relay), so many sites send such a visit to a second check instead of refusing it. Your backend covers each check, and how to get the visitor's address behind your proxy.

Then your own rules decide. knownprint gives no verdict: read the signals and the suspect score, and act on them as your business needs.

Try it with curl

With the request id from a test submission (log it in your backend, or read it from the hidden field in your browser's developer tools before the form posts):

Shell
export KNOWNPRINT_API="<the API address from your account>"
export KNOWNPRINT_SECRET_KEY="sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
REQUEST_ID="evt_q3vx7k2mz4rb6nw5tc2ehj7ypd"

curl -sS "$KNOWNPRINT_API/v1/events/$REQUEST_ID" \
  -H "Authorization: Bearer $KNOWNPRINT_SECRET_KEY" \
  -H "Accept: application/json"

The answer is the whole event. An abbreviated example: most signals and several fields are left out, and Events has a complete one.

JSON
{
  "request_id": "evt_q3vx7k2mz4rb6nw5tc2ehj7ypd",
  "environment_id": "env_b5l7rluhuy37x7qxlnu5qtjlsl",
  "created_at": "2026-11-03T14:00:00.412Z",
  "received_at": "2026-11-03T14:00:00.412Z",
  "visitor_id": "v_f6i63ol6cpthl5uajnmobnbm5k",
  "confidence": 0.98,
  "anonymity_set_size": 1,
  "high_recall_id": null,
  "browser": {
    "family": "firefox",
    "major": 145,
    "os_family": "windows",
    "os_version": "10.0",
    "platform": "Win32",
    "class": "firefox",
    "engine": "gecko"
  },
  "network": {
    "ip": "203.0.113.24",
    "ip_prefix": "203.0.113.0/24",
    "asn": 64500,
    "country": "DE"
  },
  "signals": {
    "bot": {
      "value": "not_detected",
      "confidence": 0.7,
      "reasons": [],
      "capped": true,
      "detail": { "version": "v2" }
    },
    "suspect_score": {
      "value": 0,
      "confidence": 1,
      "reasons": [],
      "detail": { "version": "v3", "parts": {}, "max": 100 }
    }
  },
  "integrity": {
    "origin": "https://www.example.com",
    "replayed": false
  },
  "linked_id": null,
  "tags": null,
  "url_path": "/signup"
}

Events lists every field. A request id that names no event of your environment answers 404 not_found, and an event whose visitor is being deleted answers 409 deletion_pending, each with an application/problem+json body; every error code is on Errors.

A complete Node example

This is the backend half of the signup form above, in Node 22 with Express and the built-in fetch. It reads the event, runs the four checks, makes a decision and, once the account exists, attaches the account id to the event.

server.js
import express from 'express';

const API = process.env.KNOWNPRINT_API;
const SECRET_KEY = process.env.KNOWNPRINT_SECRET_KEY;
const SITE_ORIGIN = 'https://www.example.com';
const MAX_AGE_MS = 10_000; // a request id is checked within 10 seconds
const CLOCK_SKEW_MS = 60_000; // allowance for a receipt time slightly ahead of this clock
const REQUEST_ID = /^evt_[a-z2-7]{26}$/;

// Request ids seen once. One process only: with several, use a shared store such as
// Redis: SET kp:used:<request id> 1 PX 70000 NX, and refuse when it does not answer OK.
const used = new Map();
function useOnce(requestId) {
  const now = Date.now();
  for (const [id, until] of used) if (until <= now) used.delete(id);
  if (used.has(requestId)) return false;
  used.set(requestId, now + MAX_AGE_MS + CLOCK_SKEW_MS);
  return true;
}

async function knownprint(method, path, body) {
  const res = await fetch(`${API}${path}`, {
    method,
    headers: {
      Authorization: `Bearer ${SECRET_KEY}`,
      Accept: 'application/json',
      ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
    },
    body: body === undefined ? undefined : JSON.stringify(body),
    signal: AbortSignal.timeout(5000),
  });
  // 404: no such event in this environment. 409: its visitor is being deleted.
  if (res.status === 404 || res.status === 409) return null;
  if (!res.ok) throw new Error(`knownprint answered ${res.status}`);
  return res.json();
}

// Resolves { ok: true, event } or { ok: false, reason, event? }.
async function verifyRequestId(requestId, { origin, ip }) {
  if (typeof requestId !== 'string' || !REQUEST_ID.test(requestId)) {
    return { ok: false, reason: 'missing' };
  }
  if (!useOnce(requestId)) return { ok: false, reason: 'used' };
  const event = await knownprint('GET', `/v1/events/${requestId}`);
  if (event === null) return { ok: false, reason: 'not_found' };
  const age = Date.now() - Date.parse(event.received_at);
  if (!(age <= MAX_AGE_MS && age >= -CLOCK_SKEW_MS)) return { ok: false, reason: 'stale', event };
  if (event.integrity.replayed) return { ok: false, reason: 'replayed', event };
  if (event.integrity.origin !== origin) return { ok: false, reason: 'origin', event };
  if (event.network.ip !== ip) return { ok: false, reason: 'address', event };
  return { ok: true, event };
}

// Your rules. The thresholds here are an example: set your own.
function decide(result) {
  if (!result.ok) {
    // Reused, replayed or from another origin: someone is forging the request.
    if (['used', 'replayed', 'origin'].includes(result.reason)) return 'block';
    // Missing, unknown, stale or from another address: unknown, not a pass.
    return 'challenge';
  }
  const { signals } = result.event;
  if (signals.bot?.value === 'bad') return 'block';
  const score = signals.suspect_score?.value ?? 0;
  if (score >= 70) return 'block';
  if (score >= 40) return 'challenge';
  return 'allow';
}

const app = express();
app.set('trust proxy', 'loopback'); // req.ip is the address your own proxy appended

app.post('/signup', express.urlencoded({ extended: false }), async (req, res, next) => {
  try {
    const result = await verifyRequestId(req.body.kp_request_id, {
      origin: SITE_ORIGIN,
      ip: req.ip,
    });
    const decision = decide(result);
    if (decision === 'block') return res.status(403).send('We could not create your account.');
    if (decision === 'challenge') return res.redirect(303, '/signup/verify-email');

    const account = await createAccount(req.body.email, req.body.password); // your code
    if (result.ok) {
      // Attach your account id, so knownprint keeps which accounts this browser has used.
      await knownprint('PATCH', `/v1/events/${result.event.request_id}`, {
        linked_id: String(account.id), // a string of 1 to 128 characters
      });
    }
    res.redirect(303, '/welcome');
  } catch (err) {
    next(err);
  }
});

app.listen(3000);

Notes on the example:

  • The request id is recorded as used before anything else is checked, so a stale or mismatched attempt still uses it up.
  • req.ip with trust proxy set to loopback is the address your own proxy appended to X-Forwarded-For, never the first entry, which the client controls. Set it to match how your proxy reaches your app. Without that header from your proxy (proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; in nginx, as in step 1), req.ip is your proxy's own address and the address check fails for every visitor.
  • A missing request id goes to a second check here, not straight through. Choose what fits your form: an email confirmation, a second factor, a CAPTCHA, or manual review.
  • The PATCH call needs the events:write scope, and the event read needs events:read. The secret key that comes with your account carries every scope.
  • Every key is limited to 50 requests a second with a burst of 150. Past the limit the API answers 429 rate_limited with a Retry-After header; this example then fails the request with an error, so add a retry if your traffic comes near the limit. See Limits.

What to do next