Edge package

@finic/kya for Cloudflare Workers, Next.js and Node: it serves the snippet from your own domain and hands your origin each request's verdict as kya-* headers.

Not on npm yet

@finic/kya is being published and can't be installed from npm yet. Email support@finic.ai for early access.

After this page your application receives a verdict on every request as kya-* request headers, with no API call from your code. The package runs in front of your site and:

  • serves the snippet and relays its reports from your own domain (/_kya/agent.js, /_kya/s);
  • removes any kya-* header the client sent, then sets its own;
  • never blocks a request. If Finic is slow or down, the request goes on without a verdict.

It needs two keys: KYA_API_KEY, your secret gsk_… API key, and KYA_SITE_KEY, a site's public gpk_… key (create a site).

Set it up

For a site already proxied through Cloudflare. The Worker adds the script tag to your HTML pages itself, so your application doesn't change. In a new directory:

export { default } from "@finic/kya/cloudflare";
name = "kya"
main = "worker.js"
compatibility_date = "2025-01-01"
routes = [{ pattern = "{your_domain}/*", zone_name = "{your_domain}" }]

[vars]
KYA_SITE_KEY = "gpk_…"
npm init -y
npm install @finic/kya
npm install -D wrangler
npx wrangler secret put KYA_API_KEY   # paste your gsk_… key
npx wrangler deploy

Optional: KYA_ORIGIN_SECRET (a secret, see Trust the headers) and KYA_SITE_ORIGIN (your site's public origin, such as https://www.example.com).

Request headers

Your application receives these on each request. A header is left out when its value is unknown.

HeaderValues
kya-actorhuman, ai_agent, automation, unknown
kya-verificationsigned, network_verified, claimed, impersonated, none
kya-operatorSuch as OpenAI
kya-productSuch as ChatGPT-User
kya-categorySuch as user_triggered_agent
kya-confidencehigh, medium, low. Only from a session
kya-sessionThe session's id, ksn_…. Only from a session
kya-sourceWhere the verdict came from, below
kya-edgeYour originSecret, when you set one
kya-sourceMeaning
sessionThe visitor's browser ran the snippet, and this request comes from that browser
lookupJudged from this request's IP address, user agent and signature alone. Never human
skippedNot looked at: a static asset, or a path you excluded
unavailableFinic didn't answer in time

skipped, unavailable and a missing kya-source mean no information. Never treat them as human. A visitor's first request has no session yet, so it's a lookup.

A session's verdict is used only when the request has the same user agent as the browser that reported, an address in the same network, and a report in the last 12 hours. A copied kya_session cookie doesn't make another client human.

Trust the headers

A request that reaches your application without passing the package carries whatever kya-* headers its sender chose: one sent straight to your origin, or one that bypassed a failing Worker. Set originSecret to a long random value. It's sent as kya-edge; ignore every kya-* header unless it matches.

const trusted = req.headers["kya-edge"] === process.env.KYA_ORIGIN_SECRET;
const actor = trusted ? req.headers["kya-actor"] : undefined;

When Finic is slow or down

Your site keeps working. Nothing throws, and a request waits at most timeoutMs for its verdict.

What happensWhat the package does
A verdict takes longer than timeoutMs (150 ms), or the API returns an errorThe request goes on with kya-source: unavailable and no other verdict header
5 verdict calls in a row failThe API isn't called for 10 seconds; requests go on at once as unavailable
/_kya/agent.js can't be fetchedThe last good copy is served, else an empty script
/_kya/s can't be relayed within 2 secondsThe report is dropped with a 204
A key is missing, or the two are swappedThe API isn't called: every request goes on as unavailable, with one console warning

Options

OptionDefault
apiKey, siteKeyRequiredThe gsk_… and gpk_… keys
apiUrlhttps://api.finic.ai
path/_kyaWhere the snippet and its reports are served on your domain. Change it in the script tag too
timeoutMs150The longest a request waits for its verdict
originSecretNoneSent to your application as kya-edge
siteOriginNoneYour site's public origin. Request signatures are checked against it instead of the Host the client sent. Set it on Node and self-hosted Next.js
injecttrueCloudflare only: add the script tag to HTML pages
excludeNonePath prefixes that never get a verdict
includeNonePath prefixes that get a verdict. When set, nothing else does

Without include, every request gets a verdict except a GET or HEAD of a static asset, such as .js, .css or an image. On Cloudflare, pass options with createWorker((env) => ({ apiKey: env.KYA_API_KEY, siteKey: env.KYA_SITE_KEY, exclude: ["/health"] })) as the Worker's default export.

On this page