/v1/guard, and returns a 403 when content
is flagged — clean traffic forwards to your origin unchanged.
Create an API key on the collector’s Auth tab first. WAF rules can’t call external
services themselves, so the worker/function is the integration point.
Cloudflare Workers
- Create a Worker (
npm create cloudflare@latest) and paste the code below intosrc/index.js. - Store the key as a secret:
wrangler secret put TRUSTGUARD_API_KEY. - Route the worker in front of your AI endpoints via
routesinwrangler.toml— zone WAF rules keep running before it. wrangler deployand send a test request.- Optional: push repeat offenders into a Cloudflare IP List and block them with a WAF custom rule before they even reach the Worker.
AWS CloudFront (Lambda@Edge)
AWS WAF can’t call external services, so a Lambda@Edge function on the viewer request trigger is the integration point.- Create a Node.js Lambda in us-east-1 and deploy it as Lambda@Edge on your distribution.
- Associate it with the viewer request event and check “Include Body” — the body isn’t exposed by default.
- Lambda@Edge has no environment variables: load the key from Secrets Manager / SSM Parameter Store at cold start, or embed it at deploy time.
- Deploy and test. Note: CloudFront truncates the exposed body above the viewer-request size limit.
Fastly Compute
- Create a Compute service (
npm create @fastly/compute) and paste the code intosrc/index.js. - Add the TrustGuard host as a backend named
trustguardand your app as a backend namedorigin. - Store the key in a Fastly Secret Store rather than hardcoding it.
fastly compute publishand test — Next-Gen WAF rules keep running before it.
Akamai EdgeWorkers
EdgeWorkers sub-requests can only reach hostnames served through Akamai, so the TrustGuard endpoint must first be mapped behind your property.- In Property Manager, route a path such as
/trustguard/*to the TrustGuard origin — sub-requests to non-Akamai hostnames fail with a 400. - Create an EdgeWorker with the
responseProviderhandler below and attach it after App & API Protector. - Keep the guard call inside the 4-second wall-time budget — set a sub-request timeout and decide fail-open vs fail-closed on timeout.
- Activate the property and test.
Considerations
- Latency — keep TrustGuard close to the edge region, or use it for input screening where the extra hop is acceptable. The same fail-open behavior applies.
- Both directions — screen the response by calling
/v1/guardwithdirection:"output"in the response phase. - Identity — forward a stable
consumer_id(andsession_idfor chat) from your auth/headers so behavioral and multi-turn detectors work. - Use a dedicated collector per edge deployment so its policies and telemetry are isolated.