Skip to main content
Edge collectors enforce at the CDN, in front of your AI application — a network-level control independent of the app and gateway. They run after your CDN’s WAF (Cloudflare WAF, AWS WAF, Fastly Next-Gen WAF, Akamai App & API Protector), so blocked web attacks never reach TrustGuard. The pattern is the same everywhere: the edge function reads the request body, calls /v1/guard, and returns a 403 when content is flagged — clean traffic forwards to your origin unchanged. Create an API key on the collector first. WAF rules can’t call external services themselves, so the worker/function is the integration point.

Cloudflare Workers

  1. Create a Worker (npm create cloudflare@latest) and paste the code below into src/index.js.
  2. Store the key as a secret: wrangler secret put TRUSTGUARD_API_KEY.
  3. Route the worker in front of your AI endpoints via routes in wrangler.toml — zone WAF rules keep running before it.
  4. wrangler deploy and send a test request.
  5. 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.
  1. Create a Node.js Lambda in us-east-1 and deploy it as Lambda@Edge on your distribution.
  2. Associate it with the viewer request event and check “Include Body” — the body isn’t exposed by default.
  3. Lambda@Edge has no environment variables: load the key from Secrets Manager / SSM Parameter Store at cold start, or embed it at deploy time.
  4. Deploy and test. Note: CloudFront truncates the exposed body above the viewer-request size limit.

Fastly Compute

  1. Create a Compute service (npm create @fastly/compute) and paste the code into src/index.js.
  2. Add the TrustGuard host as a backend named trustguard and your app as a backend named origin.
  3. Store the key in a Fastly Secret Store rather than hardcoding it.
  4. fastly compute publish and 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.
  1. In Property Manager, route a path such as /trustguard/* to the TrustGuard origin — sub-requests to non-Akamai hostnames fail with a 400.
  2. Create an EdgeWorker with the responseProvider handler below and attach it after App & API Protector.
  3. 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.
  4. 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. Your deployment’s fail-open / fail-closed setting applies on errors.
  • Both directions — screen the response by calling /v1/guard with direction:"output" in the response phase.
  • Identity — forward a stable consumer_id (and session_id for 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.