> For an index of all Botscent documentation, see https://botscent.nibnalin.me/llms.txt.

# SvelteKit

Add both halves of Botscent to a SvelteKit app and check the install.

Add Botscent to a SvelteKit app. The page half runs in the browser from `src/hooks.client.ts`. The server half runs in your server hooks or routes, where you call `inspect`.

## Before you start

You need:

* SvelteKit with Svelte 4 or 5.
* Node.js 22.12 or later.

## 1. Install the package

Install `botscent` from npm.

```sh title="Terminal"
npm install botscent
```

With pnpm, yarn or bun, use their `add` command.

## 2. Add the page half

In `src/hooks.client.ts`, import `botscent/auto`. If the file exists, add the line to the existing file.

```ts title="src/hooks.client.ts"
import 'botscent/auto'
```

The page half now starts once, in the browser.

## 3. Add the server half

Botscent has no server adapter for SvelteKit. In `src/hooks.server.ts` or in a route, call `inspect` from `botscent/server` with the request.

```ts title="src/routes/api/visit/+server.ts"
import { json } from '@sveltejs/kit'
import { inspect } from 'botscent/server'
import type { RequestHandler } from './$types'

export const POST: RequestHandler = async ({ request }) => {
  const verdict = await inspect(request)
  return json(verdict)
}
```

The route now returns the request's own verdict as JSON.

Without a server adapter, the request's own verdict does not reach the page. See [From the server to the page](/docs/server-to-page).

> **Warning:** Do not use `agent_name` or the page verdict to allow access. Anyone can send the headers that produce a name, and the browser computes the page verdict. Use `isVerified` on the request's own verdict, as [The trust model](/docs/trust-model) describes.

## 4. Read the verdict

In any component, import the `botscent` store from `botscent/svelte`. Read the page verdict as `$botscent`.

```svelte title="src/routes/+page.svelte"
<script lang="ts">
  import { botscent } from 'botscent/svelte'
</script>

<pre>{JSON.stringify($botscent)}</pre>
```

The server renders `{"type":"human","reasons":[]}`, and after hydration the store follows the page verdict.

## 5. Check the install

Start the dev server. Then run the check against its URL.

```sh title="Terminal"
npx botscent check http://localhost:5173/
```

The `page-script` check prints `pass`, and the command exits with code 0.

The `server-half` check prints `unknown`, because no server adapter sends the request's own verdict to the page. If a check fails, see [Verify your install](/docs/verify).

## Next steps

* [The verdict](/docs/verdict): Read what `type`, `agent_name` and `reasons` mean.
* [From the page to the server](/docs/page-to-server): Send the page verdict to a route with `reportHeaders`.
* [Server API (TypeScript)](/docs/server-api#inspect): Read every option of `inspect`.
* [examples/sveltekit](https://github.com/nalinbhardwaj/botscent/tree/main/examples/sveltekit): Run a SvelteKit app with both halves.
