Skip to main content
The TrustGuard REST API accepts an HTTP POST with a JSON body and bearer token and returns a JSON verdict. Use it from runtimes that do not have a supported SDK or where adding a dependency is not practical. Direct API calls are useful when the policy needs application context such as the authenticated user, tenant, or source document.

Integration capabilities

Before you start

Create the policy in Observe mode. Observe records decisions in Activity without enforcing them. Review the results, then switch the policy to Enforce. See Policies.

1. Create a collector and API key

  1. Open Runtime → Collectors → Catalog and create a collector from the Application group.
  2. On the collector’s Auth tab, create an API key. The raw tgk_… secret is shown once at creation. Store it immediately; afterward only a non-secret prefix hint is shown. Keys support an optional expiry and can be revoked.
  3. On the Policies tab, set the default policy, and per-consumer overrides if one collector serves consumers that need different policies.
A collector with no matching policy returns allow with no findings. Assign a default policy or a matching per-consumer policy before enforcement.

2. Evaluate the input

Send this before the model call and handle the verdict before forwarding the request:
payload accepts the minimal { "input": "…" } shape above or a full OpenAI, Anthropic, Gemini, or MCP provider body.
Set direction on every call. It selects which policy detector phase runs, Input or Output. It defaults to input, so a client that never sends the field never evaluates an Output-phase rule.

3. Enforce the verdict

A detection returns HTTP 200, including a block status. TrustGuard returns the verdict; your application enforces it:
If the application logs a block and continues, the integration provides monitoring only.

4. Evaluate the output

The same endpoint and the same key, with the model’s completion in payload and direction flipped:
Reuse the session_id across both halves of a turn so the prompt and the completion correlate in Activity. transformed_payload is null or absent unless a Transform rule rewrote something.

5. Handle failures yourself

Implement these behaviors in your HTTP client:
  • Fail mode. Decide whether an unreachable TrustGuard allows or denies the request. The REST API does not define a client-side default.
  • Timeouts and retries. Set explicit timeout and retry limits for the call.
  • Non-2xx is not a verdict. 401 and 403 are authentication problems, and 400 indicates a malformed body. None means allow. A 500 means a detector errored and the deployment is fail-closed; the same request returns 200 on a fail-open deployment.

6. Verify

  1. Post the input call with a prompt that should trip a rule in your policy.
  2. Confirm the finding in TrustGuard Activity, under the consumer_id you sent.
  3. Repeat with direction: "output" to confirm that the Output phase runs. The output evaluation requires a separate request.
The policy’s Test tab evaluates a sample against the last saved policy without emitting an Activity event. Use it to test the policy separately from the client request.

Reference

Coverage

Use the REST API when no SDK is available for the runtime or adding a dependency is not practical. The Python, Node.js, and Go SDKs provide a client, types, and payload handling for their respective runtimes. ⚠️ The client must implement enforcement, retries, timeouts, and failure behavior. Tool coverage requires an evaluation around the tool dispatch. Limits. Coverage is per call site. A code path that skips the evaluation is not inspected. To protect the request path by configuration, use Python middleware or Node.js middleware. To protect traffic across services, use a gateway.

What is evaluated

The REST API evaluates only the payloads your application sends. Common call sites include: protocol is available as a gate and rule condition (all · llm · mcp · a2a), so one policy can treat model traffic and tool traffic differently. For MCP tools/call, tool.name is read first from payload.params.name, which is the last segment of mcp__server__tool, rather than from attributes.

Configuration

Endpoint
The collector is resolved from the key, so you do not send a collector id in the body. Request fields. Strict decoding. Unknown top-level fields are rejected with 400. Do not send input, metadata, collector_id, or detector_id at the top level. The content belongs inside payload. Response fields. status is the reduced verdict, most restrictive wins: block > ask > transform > report > allow. findings[] carries one entry per gate or detector that fired, transformed_payload the rewritten payload, and trace_id / request_id the correlation IDs that also appear in logs and telemetry. Full finding shape: Evaluate API. Attachments. Each entry in payload.attachments provides either base64 data or a url. URL fetches are HTTPS-only and bounded by timeout, size cap and redirect limit, and a strict SSRF guard resolves DNS before dialing, rejecting loopback, private, link-local, multicast, CGNAT (100.64/10), 0.0.0.0/8 and cloud-metadata (169.254.169.254) targets. Attachment bytes are never persisted. Status codes. Error responses carry { "error", "trace_id", "request_id" }. Service tokens. A caller that authenticates with a service token instead of a collector API key must also send exactly one of gateway_id or collector_key to select the collector. With a collector API key, the collector is identified by the key.

Attributes

Include the application context required by your policy:
Every decision appears in Activity under that consumer_id. Set source.application when several services share a collector so events can be filtered by service.

Troubleshooting