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

# Install the Dedica Cloudflare Worker

> Deploy the Dedica middleware as a Cloudflare Worker in front of your site, with the one-click Deploy to Cloudflare button or by hand with Wrangler.

If your site is on Cloudflare, the Dedica Cloudflare Worker is the quickest way to connect it. It serves `/.well-known/dedica.json`, sends a heartbeat every 5 minutes, fetches your policy, recognises agents and serves them content from Dedica. In `report` mode it passes everything through.

## Before you start

In the Dedica dashboard, start onboarding and create a middleware token. Note the **token** and the **site id**.

> [!WARNING]
>
> The token is shown once. Store it as a secret. Once the middleware is connected, its token can't be changed.

## Install with one click

**1. Deploy the worker**

Click **Deploy to Cloudflare** on the middleware step in Dedica. Cloudflare copies the worker into your GitHub or GitLab account and asks for `DEDICA_SITE_ID`, `DEDICA_API_URL` and the `DEDICA_MIDDLEWARE_TOKEN` secret, then builds and deploys it.

**2. Route your site through it**

In the Cloudflare dashboard, add routes for the worker in front of your site: `example.com/*` and `www.example.com/*`. Make sure your DNS records are proxied (orange cloud).

**3. Run the check**

Back in Dedica, run the middleware check. The first heartbeat or policy fetch marks the worker live.

## Install by hand

**1. Get the code**

Clone [dedica-relay-cloudflare-worker](https://github.com/prathameshbhalekar/dedica-relay-cloudflare-worker) and install its dependencies.

```bash theme={null}
git clone https://github.com/prathameshbhalekar/dedica-relay-cloudflare-worker.git
cd dedica-relay-cloudflare-worker
npm install
```

**2. Configure and deploy**

Set `DEDICA_SITE_ID` (and `DEDICA_API_URL` if needed) in `wrangler.toml`, then add the token as a secret and deploy.

```bash theme={null}
npx wrangler secret put DEDICA_MIDDLEWARE_TOKEN
npx wrangler deploy
```

**3. Route and check**

Add a route so the worker runs in front of your site, then run the middleware check in Dedica.

## Configuration

| Variable | Description |
| - | - |
| `DEDICA_SITE_ID` | Your site id. Not a secret. |
| `DEDICA_API_URL` | Dedica's API, `https://api.getdedica.com`. |
| `DEDICA_MIDDLEWARE_TOKEN` | Your middleware token. A secret: set it with `wrangler secret put`. |
| `DEDICA_QUERY_ORIGIN` | Optional. The only origin `/ask` and `/mcp` may be proxied to. Defaults to the origin of `DEDICA_API_URL`. |
| `DEDICA_SALT` | Optional secret. The salt for the daily visitor pseudonym in traffic reports. Defaults to your middleware token. Set it with `wrangler secret put`. |

## Traffic reporting

From version 1.3.0, the worker reports every page load to Dedica, from people, AI agents and bots alike, so Dedica can show how much of your traffic is agents. Static files, the requests a page makes for images, scripts and data, and prefetches aren't reported.

Each report holds the time, method, host, path, status, response time, what the worker did, whether Dedica served it, the agent it recognised, the user agent, the referring page (origin and path only), the visitor's country and a few request headers. It keeps only the attribution parameters of the URL (`utm_source`, `utm_medium`, `utm_campaign`, `ref`, `source`).

> [!NOTE]
>
> No IP address leaves your edge. A visitor is reported as a daily pseudonym made from their IP address, user agent, the day and a secret salt. Set your own salt with `npx wrangler secret put DEDICA_SALT`; otherwise the worker uses your middleware token, which Dedica only stores in hashed form. Cookies and your token are never sent.

Reports are sent in batches in the background, so they never slow down or change a response. If Dedica is briefly unavailable, the worker keeps the batch and sends it with the next one. See [Report traffic](https://docs.getdedica.com/middleware/protocol.md#7-report-traffic) for the format.

## Check the worker

`GET https://<your domain>/__dedica/status` shows whether the worker is configured. It never shows secrets.

The worker logs with the prefix `[dedica]`. Watch them with:

```bash theme={null}
npx wrangler tail
```


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