Every host and framework
Set up Constile on CloudFront
Constile's gate runs in front of your pages. An AI agent fetching a page for a person gets an offer; people, search engines, and subscribers get your site as they do today.- Install the package
npm install https://constile.app/install/constile-gate-0.6.0.tgz
- Add the gate as a Lambda@Edge origin-request functionDeploy it in us-east-1. Forward User-Agent and the Signature headers in the origin request policy. In the cache policy, set the minimum TTL to 0 and leave User-Agent out of the cache key, so CloudFront never caches an offer. An agent that gets a cached page gets no offer.
import { constileGate } from "constile-gate/cloudfront"; export const handler = constileGate({ siteId: "your-site-id", secret: "…", // from your build's secret store; don't commit it networkUrl: "https://constile.app", siteUrl: "https://your-site.example", }); - Set your site's settingsLambda@Edge has no environment variables: build these values into the handler above from your build's secret store.Your site's page shows its ID, and shows the secret once, when you add the site.
CONSTILE_SITE_ID=your-site-id CONSTILE_SITE_SECRET=your-site-secret CONSTILE_NETWORK_URL=https://constile.app
- Check the installDeploy, then select Check install on your site's page. The network asks your domain for
/.well-known/constile, and the gate answers with your site secret. Then Test my site shows what a person, a search crawler, and an AI agent each get.
Turn it off
Fastest, from your dashboard: once the gate is installed, select Pause offers under Manage on your site's page. The network stops making offers, and the gate passes every request through within a minute. Nothing changes on your server.On your site: Remove the Lambda@Edge association from the cache behavior and deploy the distribution. CloudFront takes a few minutes, so pause offers here first.To take it out: Delete the Lambda@Edge function once no distribution uses it.Off or paused, people, search crawlers, subscribers, and your other ads get your site exactly as before.