Skip to main content
Know Your Agent (KYA) is the receiving side of AIR Agent. When an agent visits your site on a user’s behalf, it can carry a proof of what the user holds, such as a membership tier. Your site checks that proof and decides what the agent gets. This guide shows how to do that check at the edge, with a Cloudflare Worker in front of any existing site. Your origin does not change except to read one header.

air-kya-edge

The example repository for this guide: a small Worker, a reusable KYA module, an example agent and origin, and tests for every rejection.

What you build

The Worker verifies an SD-JWT presentation that the agent obtained from AIR, offline, on every request it protects. It never calls AIR per request and never trusts a status relayed by the agent. Each request is classified, then handled by the rule for its path:
  • Gate a path to serve it only to verified agents, such as member-only content or a limited offer.
  • Triage a path to serve everyone but let your origin tailor the response, such as member prices, higher rate limits, or a prompt to verify.
anonymous means the caller sent no proof. It is not a proof of humanity: people and unverified bots both land there. If you need that distinction, combine it with Cloudflare Bot Management.

Before you start

  • A verification program. In the AIR Dashboard, create an SD_JWT_VC verification program for the credential you accept. Save its program ID, the issuer DID (did:web:…) and the credential type (vct). See Verifying credentials.
  • A Cloudflare account with your site’s domain on Cloudflare, or a workers.dev subdomain for testing.
  • Node.js 20 or later.
You can complete the local steps without an AIR account. The repository includes a test issuer that signs credentials in AIR’s format.

Build and run it

1

Clone the repository and run it locally

npm run setup creates a local test issuer and a .dev.vars that trusts it. Then run the example origin and the edge in two terminals:
2

Try each outcome

The example agent runs the full agent flow. --fixture signs the credential with the local test issuer instead of calling AIR; the edge checks are the same as in production.
3

Set your policy and rules

Edit kya.config.ts. The policy mirrors your verification program; the rules decide where it applies.
kya.config.ts
  • fieldsToDisclose is exactly what the agent must reveal: no more, no less. Ask only for the claims your decision needs.
  • conditions support =, !=, >, >=, <, <= and in. Each condition’s attribute must be in fieldsToDisclose.
  • A rule path is exact (/pricing) or a prefix ending in * (/members/*). Modes are gate, triage and off.
4

Deploy in front of your site

Set your program ID, issuer and credential type as Worker vars in wrangler.jsonc, and add a route for your domain:
wrangler.jsonc
With ORIGIN_URL empty, the Worker forwards to your zone’s existing origin. Set it only to proxy a different host, for example while testing on workers.dev.
5

Read the decision in your origin

The edge removes every caller-supplied X-AIR-* header, including the proof, then adds its own:Your origin should accept these headers only from the edge. Refuse any request without the secret, and compare it in constant time:
For an origin behind Cloudflare’s proxy, Authenticated Origin Pulls or a Cloudflare Tunnel can also keep traffic from bypassing the edge.

What the agent does

An agent needs a delegated identity and an agent session first. See Using Agentic Identity. For each protected request, it then:
  1. Reads GET /.well-known/air-kya to learn the program, required claims and accepted issuers.
  2. Gets a nonce from POST /kya/challenge. Each nonce expires after 60 seconds and works once.
  3. Calls Verify a credential with the site’s program, fields and nonce:
  4. Sends the request with X-AIR-KYA: <proof>.
The repository’s examples/agent.ts runs these steps against a live site when you set AIR_AGENT_JWT:
A gate refusal returns 403 with a Link: </.well-known/air-kya>; rel="service-desc" header, so an agent that arrives without a proof can find out what to present.

What the edge checks

The Worker runs the SD-JWT backend checks in this order. The first failure decides the reason code.
  1. The issuer is in trustedIssuers. Its ES256 key comes from its did:web document (assertionMethod, matching kid).
  2. The issuer signature, iat, exp and vct are valid.
  3. The disclosed claims are exactly fieldsToDisclose, and each matches a digest the issuer signed.
  4. The key-binding JWT is signed by the holder key in cnf.jwk, has typ kb+jwt and aud equal to the program ID, is at most 5 minutes old, and its sd_hash covers this presentation.
  5. The nonce was issued by this site and is consumed now, atomically, in a Durable Object.
  6. The policy conditions hold for the disclosed claims.
The verification logic lives in src/kya/ and has no Cloudflare dependency apart from the nonce store. To run it in other middleware, such as Express or Next.js, pass your own consumeNonce backed by a store with an atomic delete.

Reason codes

X-AIR-Reason carries one of these fixed codes. Tokens and library errors are never echoed. Track these codes in your Worker logs. A spike in nonce_reused_or_unknown or invalid_credential from one source is a signal for your abuse controls.

Before production

  • Revocation is not checked. If your issuer publishes a Token Status List, add a status check. See Revocation.
  • Rate-limit /kya/challenge with a Cloudflare rate-limiting rule. Each call stores a nonce for 60 seconds.
  • Expect one proof per request. A presentation is single-use. For high traffic, shard the nonce store.
  • Do not cache across caller classes. The Worker sends responses to callers with a proof as private, no-store and fetches them with cache: "no-store". If you add your own caching, key it on X-AIR-Viewer.
  • Keep the policy under your control. Never let a caller choose the program, issuer or origin.
  • Know the binding’s scope. The proof is bound to your nonce and program, not to the HTTP connection. Request signing, such as Web Bot Auth (RFC 9421), is out of scope.

Going further

  • People, too. The air-kya demo store runs the same checks for people who sign in with AIR Kit and verify the same credential in the browser. A verified person and their verified agent see the same catalog.
  • Decide what to gate. Agent Gating covers which claims to ask for and how to combine them with your abuse controls.
  • Offer a benefit. Agentic Commerce covers member pricing and other benefits applied after a successful check.