Integration capabilities
Before you start
Start with the policy in Observe mode. Findings appear in Activity without
affecting traffic. Switch to Enforce after reviewing the results. See
Policies.
1. Create a collector API key
On the Fastly collector, open Auth and create a key. It is shown once. The key identifies the collector and its assigned policy; the request body does not need a collector ID.2. Scaffold the Compute service
src/index.js. Configure the remaining settings on the
service backends.
3. Declare the backends and store the key
A Compute service can fetch only declared backends. Declare two:
The handler passes these names as
backend. If a name is wrong or undeclared,
the corresponding fetch does not leave the edge.
Put the tgk_… key in a Fastly Secret Store and read it from there in the
handler. The snippet uses the literal <collector-api-key> for clarity. Replace
it with a Secret Store lookup.
4. Evaluate the request body
The handler clones the request, sends the body toPOST /v1/evaluate over the trustguard backend
with the collector key as a bearer token, and forwards to origin only if the
verdict is not block:
req.clone(): read the clone, not the request. Consuming the original body stream leaves nothing to forward, and the origin receives an empty body.req.method === "POST": other methods pass through without evaluation. Update the condition if an endpoint accepts prompts through another method.payload.inputis the complete body: the raw POST body as a string, JSON scaffolding, model name and message roles included. Detectors see one blob with no role boundaries: retrieved text, your system prompt and the user’s turn are indistinct.payloadalso accepts a complete OpenAI, Anthropic, or Gemini provider body, so parse and send that object if you need the distinction.
block returns 403 with Blocked by TrustGuard, and the origin is not called.
The finding is available in Activity. allow, report, and
ask all pass through to origin. Use a block gate for enforcement.
The sample omits error handling around the request to TrustGuard. Catch failures and
choose whether to return fetch(req, { backend: "origin" }) (fail open) or a 403
(fail closed). Without a catch, the request fails at the edge.
5. Publish the service
6. Verify
- Put the policy in Enforce and
POSTa prompt to a guarded endpoint that trips a rule. - Confirm that the caller receives
403with the bodyBlocked by TrustGuard. - Confirm the event in TrustGuard Activity, under the
consumer_idyou sent asx-user-id. - Send a clean
POSTand confirm that the origin receives the original body. This verifies that the handler reads the clone rather than consuming the request stream.
Reference
Coverage
The handler evaluates POST bodies before forwarding them to the origin. It does
not inspect model responses, expose individual tool calls, or support redaction.
Each evaluated request adds one round trip to
{TRUSTGUARD_URL}.
What is evaluated
The call is
POST /v1/evaluate with the collector
tgk_… key as a bearer token, and the policy’s
detectors decide the verdict. direction
selects which detector phase runs; this handler only ever sends input.
Verdict handling
Configuration
Configure the integration in the Fastly service:Attributes
consumer_id: read from thex-user-idrequest header,""when absent. It is what per-consumer policy routing keys on, so without it every caller shares the collector’s default policy.session_id: read fromx-session-id. The sample sends""when the header is absent. Send a stable, verified conversation ID if you need reliable grouping in Activity.- Both are client-supplied headers. The edge does not derive either one, and a caller can set either value. Replace them with values from an authenticated identity if policy decisions have to be trustworthy.
- The sample sends no
attributesblock, so gates matching onmodel,source.applicationorcollector.typehave nothing to match. Add the dimensions you gate on to the evaluate body.
Troubleshooting
Related
- Evaluate API: request and response contract for the endpoint the handler calls
- Policies: Observe and Enforce modes, including gate configuration
- Collectors: collector keys and policy resolution
- Other edge collectors: Cloudflare · CloudFront · Akamai
- Fastly documentation: Compute services, backends, and the Secret Store