> ## Documentation Index
> Fetch the complete documentation index at: https://developer.keverd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript SDK

> Vanilla JS and CDN with @keverdjs/agent

# JavaScript SDK

Collect device signals in the browser with a **public** API key (`kv_pk_…`). Send the billable `event_id` / `requestId` to your backend and [verify on the server](https://developer.keverd.com/server/overview.md).

## Install

### npm

```bash theme={null}
npm install @keverdjs/agent
```

### CDN (no npm)

Load the ESM bundle from [cdn.keverd.com](https://cdn.keverd.com). Put your **public** key in the URL path — `start()` reads it automatically.

```js theme={null}
const keverdPromise = import(
  'https://cdn.keverd.com/v1/YOUR_PUBLIC_API_KEY/keverd.min.js'
).then((Keverd) => Keverd.start());

keverdPromise
  .then((k) => k.getVisitorData())
  .then((r) => {
    console.log(r.requestId); // billable event id — send to your server
    console.log(r.visitorId);  // persistent device id
  });
```

Replace `YOUR_PUBLIC_API_KEY` with `kv_pk_test_…` or `kv_pk_live_…`.

```html theme={null}
<script type="module">
  const keverd = await import(
    'https://cdn.keverd.com/v1/kv_pk_live_…/keverd.min.js'
  ).then((m) => m.start());

  const result = await keverd.getVisitorData();
  await fetch('/api/keverd/verify', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ eventId: result.requestId || result.event_id }),
  });
</script>
```

> [!WARNING]
>
> CDN and browser SDKs use **public** keys only. Never put `kv_sk_…` or `whsec_…` in frontend code.

> [!NOTE]
>
> `start()` can also take an explicit key: `start('kv_pk_…')` or `start({ apiKey: 'kv_pk_…', endpoint: 'https://api.keverd.com' })` if you are not loading from the keyed CDN path.

## Initialize (npm)

```js theme={null}
import { Keverd } from '@keverdjs/agent';

Keverd.init('kv_pk_live_…');
// or
Keverd.init({
  apiKey: 'kv_pk_test_…',
  endpoint: 'https://api.keverd.com',
});
```

## Collect

```js theme={null}
const result = await Keverd.getVisitorData();

console.log(result.event_id);     // send to your server
console.log(result.requestId);    // same billable id (CDN-friendly alias)
console.log(result.fingerprint);  // persistent device id
console.log(result.visitorId);    // alias of fingerprint
console.log(result.action);       // allow | soft_challenge | hard_challenge | block
console.log(result.risk_score);
```

### Response JSON

```json theme={null}
{
  "fingerprint": "kvd_…",
  "visitorId": "kvd_…",
  "event_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "requestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "session_id": "…",
  "risk_score": 12,
  "score": 0.12,
  "action": "allow",
  "reason": [],
  "similarity": 0.98,
  "is_new": false,
  "times_seen": 3,
  "first_seen": "2026-07-01T09:00:00.000000",
  "last_seen": "2026-07-25T12:00:00.000000"
}
```

Send this to your backend (JSON body example):

```json theme={null}
{
  "eventId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

Your server then calls [POST /v2/verify](https://developer.keverd.com/api-reference/verify.md) with `{ "event_id": "…" }`.

> [!WARNING]
>
> Do not use `Keverd.get()` for the verify flow. It returns a **string**, not an object with `event_id`.

## Optional use-case helpers (public key — still collection)

```js theme={null}
await Keverd.verifyLogin({ /* … */ });
await Keverd.verifyCheckout(amount, currency);
await Keverd.verifyRegistration();
await Keverd.verifyPasswordReset();
await Keverd.verifyAccountChange();
```

These return the same collect JSON shape. They do **not** replace server `verify()`.

## Next

* [Quickstart](https://developer.keverd.com/quickstart.md)
* [Verify on the server →](https://developer.keverd.com/server/overview.md)
* [API keys](https://developer.keverd.com/api-keys.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.