> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abliteration.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming policy metadata

> On `/policy/*` endpoints, abliteration.ai injects a policy object into every streaming frame so clients can render compliance UI.

<Note>
  Policy metadata injection only runs on `/policy/*` endpoints and requires a [Policy Gateway](/policy-gateway/overview) plan.
</Note>

When you stream from a `/policy/*` endpoint, every SSE frame carries a `policy` field describing the current enforcement state. This lets clients render compliance UI (warning banners, "why was this blocked" tooltips, audit links) without a second API call.

## Enabling

Metadata injection is automatic on any `/policy/*` streaming response. `/v1/*` endpoints never inject.

## Frame shape

Standard Anthropic SSE frame, unmodified:

```http theme={"system"}
event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello"}}
```

Same frame on `/policy/messages`:

```http theme={"system"}
event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello"}, "policy": {
  "policy_id": "support-bot",
  "decision": "allow",
  "effective_decision": "allow",
  "reason_code": "ALLOW",
  "rollout_mode": "enforced",
  "enforced": true,
  "triggered_categories": [],
  "allowlist_hits": ["refund policy"],
  "denylist_hits": [],
  "policy_target": "support-bot"
}}
```

The `policy` object appears on every SSE `data:` line — `message_start`, `content_block_start`, `content_block_delta`, `message_delta`, `message_stop`. The values are stable across the stream unless a rule fires mid-stream (e.g., output classifier).

## Fields

See the [event shape](/policy-gateway/connectors#event-shape) for the full field list — the streaming `policy` object is a subset of the enforcement event.

## Client example

```javascript theme={"system"}
const res = await fetch("https://api.abliteration.ai/policy/messages", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ABLIT_KEY}`,
    "X-Policy-Project": "proj_support_bot",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "abliterated-model",
    stream: true,
    max_tokens: 1024,
    messages: [{ role: "user", content: "Hello" }],
  }),
});

const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });

  for (const line of buffer.split("\n")) {
    if (!line.startsWith("data: ")) continue;
    const frame = JSON.parse(line.slice(6));
    if (frame.policy?.effective_decision !== "allow") {
      console.warn("Policy intervention:", frame.policy);
    }
    // ...render content as usual
  }
}
```
