Korzen
Bot Protection
In these docs

The call from your server

POST /v1/decide before a sign-up, a sign-in or a checkout: what to send, what comes back, the errors, the regions and your timeout.

Before the protected action, your server asks Bot Protection about the request and applies the action in the answer. Use a short timeout, and let the visitor through on any error: that is fail open, and it means Bot Protection can never take your sign-up down.

Behind Cloudflare? A Worker can do this without changing your app. Cloudflare Workers

The request

# Korzen-Deadline-Ms: the timeout for your server's region, https://korzen.dev/bot-protection/docs/server-call#latency
curl -s -X POST https://eu.korzen.dev/v1/decide \
  -H "Authorization: Bearer $KORZEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Korzen-Deadline-Ms: 200" \
  -d '{"ip":"203.0.113.10","ip_from":"peer","user_agent":"Mozilla/5.0 …",
       "headers":{"accept":"text/html,…","accept-language":"en-US","sec-ch-ua":"…","sec-fetch-site":"same-origin"},
       "token":"<the _kz cookie>","path":"/signup","method":"POST"}'

Call over https alone. Plain http to /v1/ is refused with 403, never redirected: the key in that call crossed the network in clear, so revoke it on the Set-up page and deploy a new one.

Every field is optional, and the more you send the more Bot Protection sees. A field Bot Protection does not know, such as protectedAction for protected_action, is read as none, never refused, so an SDK newer than the release that answers it costs no decision; the Set-up page shows it as a field Korzen does not know, so a typo is still seen. null is none: for protected_action and a claim's yes or no, false.

In headers, send these as the visitor's browser sent them, under their lower-cased names, and leave out the ones the request does not carry: accept, accept-encoding, accept-language, host, sec-ch-ua, sec-ch-ua-mobile, sec-ch-ua-platform, sec-fetch-dest, sec-fetch-mode, sec-fetch-site and upgrade-insecure-requests. host names the domain the request was made to: a decision proves that domain yours with it, and without it the domain is never listed under Your domains. The SDKs and the code below send this list.

Behind a CDN that forwards the visitor's JA4, name it to the SDK and it sends it as ja4: cdn: "cloudfront" in Node, CDN: botprotection.CDNCloudFront in Go. On CloudFront, add CloudFront-Viewer-JA4-Fingerprint, CloudFront-Viewer-Header-Order and CloudFront-Viewer-Http-Version to the origin request policy: the visitor's header order and HTTP version come with them. Azure Front Door (azure_front_door) sends X-Azure-JA4-Fingerprint, Vercel (vercel) x-vercel-ja4-digest and bunny.net (bunny) CDN-JA4, with nothing to turn on. On Google Cloud's load balancer (google_cloud), add the custom request header X-Client-JA4:{tls_ja4_fingerprint} to the backend service; on Fastly (fastly), set req.http.X-Client-JA4 = tls.client.ja4; in vcl_recv. Name the CDN only when your server takes traffic from it alone: anyone can send these headers to a server reachable around it. A value that does not read is left out, and a field you set yourself wins.

The visitor's IP and your own servers

Which IP to send behind a proxy or a CDN, the scheme, the requests of your own server and your trusted servers: The visitor's IP and your own servers

Your custom rules

Let your own automation through with a rule of yours: Custom rules

How a decision is made

Bot Protection asks three things in order, and the first that answers decides; nothing after it runs:

  1. A verified known bot (known_bots): a crawler from its vendor's published addresses, or an agent its signature proves, gets your choice for it on the Bots page. A request that only names a crawler is no known bot.
  2. Your custom rules (custom_rules), top to bottom: the first that allows or blocks decides. A rule that only logs lets the next one decide.
  3. The bot engine (bot_engine): it classes the visitor human, unknown or bot, and the action is the one for that class. Only the bot engine gives a class and a bot score.

The answer

{
  "request_id": "AQEAo3k9Zx4VbQ…",
  "decided_by": "bot_engine",
  "class": "bot",
  "bot_score": 72,
  "action": "allow",
  "mode": "monitor",
  "token_required": false
}
FieldMeaning
request_idthis decision's ID, at most 96 characters: keep it with an order, and send it to us when you ask about one answer
decided_bywhat decided (in this order): known_bots, custom_rules or bot_engine; null while the protection is paused
bot_scoreThe bot score, 0 to 100: how much evidence of automation the class stands on; null when class is
actionwhat to do: allow or block. Always allow in monitor mode.
classhuman, unknown or bot, as the bot engine judged; null when a known bot or a custom rule decided first, or while the protection is paused
modemonitor, block or paused (you paused the protection on the Set-up page: action is allow)
token_requiredtrue when you sent protected_action and the request carried no valid token for this action, or one this session already used on it. In block mode action is then block; in monitor mode action stays allow. The class does not change (see an action that needs the tag). false otherwise, and always while the protection is paused

Every member is always there: an object with nothing to say is null. What stands behind a decision (the kinds of evidence, a verified crawler, your own server) is on the Decisions page.

Errors

Any status other than 200 (a wrong key, a month's limit reached, an outage) means: let the visitor through. An error's body is an RFC 9457 problem, application/problem+json, whose code says what went wrong:

{
  "type": "https://korzen.dev/bot-protection/docs/server-call#invalid_field",
  "title": "A field is not valid",
  "status": 400,
  "code": "invalid_field",
  "detail": "invalid type: string, expected a boolean at line 1 column 22",
  "request_id": "rq_01a15441820577808ce489c291023c16"
}
StatuscodeWhen
400invalid_json, invalid_fieldthe body is no JSON, or a field has the wrong type
401, 403unauthorizedno API key, or one Bot Protection does not know; 403 on first-party mode's routes
402over_limitthe decisions of the free trial, of the free plan's month or of the billing period are used
402, 403domain_refusedthe page's domain is not one the site key protects (the tag's calls)
404not_foundno such route
405method_not_allowedthe route takes other methods, which Allow names
409conflictwhat the call would make exists already
413body_too_largethe body is past the route's bound
429rate_limitedtoo many calls from one network to the tag's routes, with Retry-After
503over_capacity, deadline, unavailabletoo many calls at once, no decision within your deadline, or a service Bot Protection depends on is down, with Retry-After
500internalBot Protection failed

Every answer carries Korzen-Request-Id, the same as the problem's request_id: it names the call, so name it when you ask us about a call that failed. About a decision, name the decision's own request_id, the one the dashboard finds. Decide carries the IETF's RateLimit-Policy and RateLimit headers for your account's decisions: "month";q=50000 and "month";r=41234;t=86400 say 41,234 of the month's 50,000 are left and the month ends in a day (on the free trial, "trial"). Log them if you like, and never wait on them. The SDKs hand both to onAnswer (in Go, OnAnswer) after each call.

What your server knows: the context

The fields your server can send in context, and the resource to send in your industry: What your server knows: the context

Regions

Your account and its keys live in the region chosen at sign-up, and your server calls that region's address. The SDKs read the region from the secret key, so there is nothing to set. A region not open yet is answered from Europe, at its own address, until it opens.

RegionAddressServers
Europehttps://eu.korzen.devFalkenstein, Germany
Latin Americahttps://br.korzen.devIn Europe until it opens
US Easthttps://us1.korzen.devIn Europe until it opens
US Westhttps://us2.korzen.devIn Europe until it opens

Latency and your timeout

Bot Protection runs in Falkenstein, Germany. A decision takes the network's round trip from your server plus a few milliseconds, on a connection your server keeps open; a new connection adds the TLS handshake, one or two more round trips. Keep one HTTP client for the whole process, as the examples below do, and choose your timeout by where your server runs. Send it as Korzen-Deadline-Ms, how long your call waits in all: Bot Protection takes half of it for the decision, between 10 and 1,000 ms (200 ms without the header), and leaves the other half for the network. A decision not made within its half is answered 503 deadline at once, and not counted. The SDKs send their timeout for you.

Your server inRound tripTimeout
Europe10–40 ms100–200 ms
US east~85 ms200 ms
US west~145 ms300 ms
South America~190 ms500 ms

A timeout too short for the distance lets every visitor through, and those calls still count as decisions.

Writing your own client

The SDKs do what follows for you. A client of your own, in a language without one, sends these too; the example below is the whole call from Express, with no SDK.

From Node, send header_order too: the names of the request's headers in the order they came, lower-cased (every other entry of req.rawHeaders), such as ["host", "user-agent", "accept"]. Where the order is lost (Go's net/http, the Fetch API's Headers, a Cloudflare Worker), leave it out; a value that is not a list of header names is ignored, never refused.

Send tls_group and http_protocol only as the visitor's own connection had them, from the server or edge that ended the visitor's TLS (a Cloudflare Worker sends request.cf's). Behind a load balancer your server's own connection is the balancer's, so leave them out. Bot Protection reads a classical group or HTTP/1.1 only through an integration that sent a post-quantum group (MLKEM) or HTTP/2 before: a hop's own values accuse nobody, and the two rules stay silent there.

A value longer than Bot Protection keeps is cut, never refused: 512 bytes of the User-Agent, the path and each header, 32 headers (first those Bot Protection reads, then the first by name), 256 bytes of the token. The SDKs cut them before they send the call; a call of your own may send them whole. The body is read up to 256 KiB, which a call within those bounds always fits; past that, a string longer than 4 KiB is cut to its head and every other field is judged as sent, so one oversized header a visitor writes costs no decision. A body still past 256 KiB is judged by the fields whole within it, and one that loses protected_action there is taken as requiring a token.

// The headers Bot Protection reads: those one browser build sends alike, and Accept-Language.
const FORWARDED = ["accept", "accept-encoding", "accept-language", "host", "sec-ch-ua", "sec-ch-ua-mobile", "sec-ch-ua-platform",
  "sec-fetch-dest", "sec-fetch-mode", "sec-fetch-site", "upgrade-insecure-requests"];

app.post("/signup", async (req, res) => {
  let action = "allow";
  try {
    const r = await fetch("https://eu.korzen.dev/v1/decide", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.KORZEN_API_KEY}`, "Content-Type": "application/json",
        // How long this call waits, the decision half of it; the timeout for your server's region:
        // https://korzen.dev/bot-protection/docs/server-call#latency
        "Korzen-Deadline-Ms": "200",
      },
      body: JSON.stringify({
        // The connection's address. Behind your own proxy, the last X-Forwarded-For entry and
        // "last_forwarded"; behind Cloudflare alone, req.get("cf-connecting-ip") and "cloudflare".
        ip: req.socket.remoteAddress, ip_from: "peer", user_agent: req.get("user-agent"), token: req.cookies?._kz, path: "/signup", method: "POST",
        headers: Object.fromEntries(FORWARDED.filter((n) => req.get(n) !== undefined).map((n) => [n, req.get(n)])),
        header_order: req.rawHeaders.filter((_, i) => i % 2 === 0).map((n) => n.toLowerCase()), // the order they came in
      }),
      signal: AbortSignal.timeout(200),
    });
    if (r.ok) action = (await r.json()).action;
  } catch {} // fail open
  if (action === "block") return res.status(400).send("We could not create your account.");
  // Then create the account.
});