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

# Clerk Bot Detection

> Solutions for Clerk's bot detection system

If you see a Clerk bot detection page in one of your test failures, you likely have [Clerk Bot Detection](https://clerk.com/docs/bots/bot-detection) enabled.

Stably's AI is running in a headless browser, which is often detected as a bot by Clerk. There are two ways to resolve this:

## 1. Disable Clerk Bot Detection on staging

* Clerk does not have a granular way to allowlist user agents
* The best way to resolve this is to disable Clerk Bot Detection on staging

## 2. Create a simple API to return a session token to Stably

Clerk enables services to bypass bot detection by attaching a session token to the request. You can read more about it [here](https://clerk.com/docs/testing/overview).

If you want to test on production or keep Clerk bot detection on for staging, you can implement an API that returns a session token.

The API is necessary because session tokens are short-lived and require your Clerk tokens to generate, so only you can generate them.

Here is an example of how you can implement this API:

```
import { clerkClient } from "@clerk/clerk-express";

const clerk = clerkClient({
  secretKey: process.env.CLERK_SECRET_KEY,
}); 

app.post("/session", async (req, res) => {
  const { clerkToken } = req.body;
  const session = await clerk.sessions.create({
    userId: clerkToken,
  });
  res.json(session);
});
```

Once you have the API, you can add it in your Browser Settings.

<img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/bot-detection/clerk-bot-detection.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=056d42dfd5305650122f1ff4180d8fad" alt="" width="796" height="211" data-path="images/bot-detection/clerk-bot-detection.png" />
