POST /hooks/anthropic-inference, so your existing TrueFoundry guardrails decide whether each prompt reaches the model.
Because the hook runs on Anthropic’s servers, one configuration governs claude.ai, Cowork, and Claude Code at once, with nothing to install on user devices.
This is complementary to the Claude Code hooks integration. That runs client-side, is opt-in per developer, and can rewrite tool inputs and outputs. This page is org-wide, server-side, and allow/deny only. You can use either or both.
How it works
- A user submits a prompt in claude.ai, Cowork, or Claude Code.
- Anthropic
POSTs the conversation transcript to your configured endpoint — the AI Gateway’sPOST /hooks/anthropic-inference. - The AI Gateway authenticates the request with the
x-tfy-api-keycustom header, flattens the transcript into a scan target, and runs the guardrails nominated inx-tfy-hook-guardrails. - The AI Gateway returns
{"action": "allow"}or{"action": "deny", ...}. A denied prompt never reaches the model, and the user sees yourdeny_reason.
What you can and can’t do
Inference Hooks support validation only. Anthropic’s protocol has no mechanism to substitute a modified prompt, so mutating guardrails cannot be used here.
Which pipeline your guardrails run through is derived from what the transcript ends with:
Choosing which guardrails run
As with the other hook endpoints, guardrails are nominated via thex-tfy-hook-guardrails header — a flat JSON array of group/guardrail-name selectors. The endpoint does not read tenant Guardrail Config rules.
- Header absent — no guardrails are nominated and the prompt is allowed. Nothing was checked.
- Header present but malformed (not a JSON array of strings) — fail closed: the prompt is denied.
Limiting how much of the transcript is scanned
Anthropic sends the full, untruncated transcript on every turn — up to 10 MB. By default the AI Gateway scans all of it. Use the optionalx-tfy-guardrails-scope custom header to narrow the window:
Narrowing the scope reduces guardrail latency and cost on long conversations. Routing is unaffected — whether the turn is treated as an LLM-input or tool-result scan is always decided from the last message of the full transcript, not the scan window.
Prerequisites
- A Claude Enterprise organization, and a user with the
organization:managepermission. - A guardrail group and at least one validation guardrail integration — see Create a guardrail. Note the selector, e.g.
security/email-regex. - A TrueFoundry virtual account API key with access to that guardrail group. This key is pasted into Anthropic’s admin console, so it should be a dedicated service credential, not a personal token.
- A gateway host that meets Anthropic’s endpoint requirements:
https://on port 443, publicly routable, a certificate that validates against the public CA trust store, and no redirects — the configured URL must be the final destination.
Configure the hook in Anthropic’s console
Go to claude.ai → Organization settings → Data and privacy → Inference hooks.-
Endpoint URL —
https://<your-gateway-host>/hooks/anthropic-inferenceThis is your gateway host root, without the/api/llmsuffix used for model traffic. -
Custom request headers — add:
- Prompt verdict timeout — 1–10,000 ms, default 5,000 ms. This budget covers connection, TLS handshake, request, and response, so size it against your guardrails’ p99, not just their average.
- Failure handling — start in Shadow mode, then move to Block the request (fail closed) or Allow the request (fail open) once you’ve confirmed the endpoint is healthy.
- Rollout % — begin below 100 to limit blast radius. Anthropic rolls the dice once per conversation turn, so a single conversation can be partly inspected.
- Enforce verdicts — the master switch. Changes take roughly a minute to propagate.
Verify
You can exercise the endpoint directly before enabling enforcement:{"action": "allow"}.
Response contract
The AI Gateway always responds HTTP 200, including for denials, authentication failures, and internal errors. This is required by the protocol: any non-200 response is treated by Anthropic as a webhook failure, not a deny, and sustained failures trip the org-wide circuit breaker.
Behaviour in each case:
- Guardrail blocked —
action: "deny". - Invalid or missing API key —
action: "deny"withdeny_reason: "Unauthorized"(still HTTP 200). - Malformed body, or internal AI Gateway error —
action: "deny". Fail closed. - Mutator guardrail nominated —
action: "deny"with a message telling you to remove mutators fromx-tfy-hook-guardrails. - A turn made up entirely of content-block types the AI Gateway doesn’t recognize —
action: "deny", because nothing could be scanned safely. This is a protocol-churn safeguard. - Unknown top-level frame
type—action: "allow". Anthropic may add new event types (onlypromptexists today); allowing them is required so a future event doesn’t trip the circuit breaker.
Observability
Every request produces a trace with Inference-Hook-specific attributes, including Anthropic’srequest_id and tenant_id, the source.application (claude-ai, claude-code, or config-test), the model, session ID, whether an actor was present along with its ID and email, the transcript size in bytes, the message count, and which content-block types were scanned. Run in shadow mode first and read these traces to size real transcripts and latency before you turn on enforcement. Aggregate guardrail pass/block rates are also available in Metrics.
Caveats
- Enforcement adds a round trip to every governed prompt in the org. Your guardrails must complete inside Anthropic’s verdict timeout (5,000 ms by default), including TLS setup. Measure in shadow mode first.
- Request signatures are not verified today. Anthropic signs each delivery with a Standard Webhooks HMAC header, but the AI Gateway currently authenticates using the
x-tfy-api-keycustom header alone. Restrict the endpoint to Anthropic’s outbound range160.79.106.0/24at your ingress, and treat fields in the request body —actor.email_addressin particular — as untrusted: they are recorded on traces for attribution, but are not used to make identity or authorization decisions. actor.email_addresscan be null. Connection tests (source.application: "config-test") carry no human actor, machine-credential traffic is always inspected, and future actor types are only guaranteed to have atype. Don’t write guardrail logic that assumes an email is present.source.applicationis advisory, not a trust boundary. It is an open string — new values can appear — and Anthropic explicitly warns against resting a security-critical decision on it alone.- The circuit breaker is org-wide and recovers manually. Sustained failures attributable to your endpoint stop enforcement for the entire organization, and an admin has to re-enable Enforce verdicts after the endpoint is fixed. Alert on gateway hook errors rather than relying on Anthropic’s monitoring panel, which is best-effort and shows zero rather than erroring.
- Transcripts can reach 10 MB. Check that every proxy and ingress in front of the AI Gateway accepts bodies that large — a rejected body is a webhook failure, so under Allow the request an oversized prompt reaches the model completely uninspected.
- No coverage of voice mode, system prompts, tool definitions, or raw file bytes. Anthropic does not send these. Attachments arrive as extracted text only.
- Prompts are only inspected once per inference call. Tool calls execute on the client between calls, so this cannot stop a dangerous tool from running the way Claude Code’s
PreToolUsehook can. Use both integrations if you need that.