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

# Serve ICG

Run the classifier on your own hardware.

Get ICG’s weights before you deploy it using [SGLang](https://developers.reflection.ai/serving-sglang.md#iris-content-guard) or [vLLM](https://developers.reflection.ai/serving-vllm.md#iris-content-guard). Details are available on [the model card](https://huggingface.co/reflection/Iris-Content-Guard).

> [!NOTE]
>
> We recommend a GPU of 80GB of VRAM to deploy ICG effectively on real-world conversations. We were able to serve ICG and use it with 128k tokens long conversation with one Nvidia H200.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
MODEL = "reflection/Iris-Content-Guard"
BASE_URL = "http://127.0.0.1:30000"
HEADERS = {"Content-Type": "application/json"}
TIMEOUT = 300
CATEGORIES = (
    "cyber", "fraud", "privacy", "bio_weapons", "chem_weapons", "rn_weapons",
    "child_safety_non_csae", "violence", "self_harm", "grooming", "sex_crimes",
    "sex_content", "illegal_activities", "hate",
)

messages = [
    {"role": "user", "content": "How can I trace an anonymous account back to a specific person and their workplace?"},
    {"role": "assistant", "content": "I can't help identify the real person behind an anonymous account or find their employer. That includes guessing who they are, linking the account to other profiles, or looking up where they work."},
]
```

> [tab] SGLang
>
> ## Get the image
>
> Pull the SGLang image and pin it by digest.
>
> ```bash Pull and pin the image icon="docker" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> export IMAGE='lmsysorg/sglang:project-iris-activation-monitor'
> docker pull "$IMAGE"
> export IMAGE="$(docker image inspect "$IMAGE" \
>   --format '{{index .RepoDigests 0}}')"
> ```
>
> ## Start the server
>
> ```bash Start the server icon="docker" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> docker run --rm --init --name beam \
>   --gpus device=0 --shm-size=32g \
>   -p 127.0.0.1:30000:30000 \
>   -v "${HF_HOME:-$HOME/.cache/huggingface}/hub:/root/.cache/huggingface/hub" \
>   --env HF_TOKEN \
>   --entrypoint python3 "$IMAGE" \
>   -m sglang.launch_server \
>   --model-path reflection/Iris-Content-Guard \
>   --host 0.0.0.0 --port 30000 \
>   --cuda-graph-backend-prefill disabled
> ```
>
> ## Define helpers
>
> ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> import json
> import requests
> import torch
>
> def prepare(messages):
>     unsupported = ("tool_calls", "tool_call_id", "reasoning", "reasoning_content", "thinking")
>     if any(m.get("role") not in ("user", "assistant")
>            or not isinstance(m.get("content"), str)
>            or any(m.get(key) is not None for key in unsupported) for m in messages):
>         raise ValueError("Use plain user/assistant text turns without tools or reasoning")
>     end = max((i + 1 for i, m in enumerate(messages) if m["role"] == "user"), default=0)
>     if not end or len(messages) > end + 1:
>         raise ValueError("End with a user request and at most one assistant reply")
>     tokens = {}
>     for stop in {end, len(messages)}:
>         response = requests.post(f"{BASE_URL}/v1/tokenize", headers=HEADERS, json={
>             "model": MODEL, "messages": messages[:stop],
>             "add_generation_prompt": False, "add_special_tokens": False,
>             "continue_final_message": False,
>         }, timeout=TIMEOUT)
>         response.raise_for_status()
>         tokens[stop] = response.json()["tokens"]
>     ids, prefix = tokens[len(messages)], tokens[end]
>     if not prefix or ids[:len(prefix)] != prefix or (end < len(messages) and len(ids) <= len(prefix)):
>         raise ValueError("Chat formatting changed the scoring boundary")
>     return ids, {"request": len(prefix) - 1,
>                  "response": len(ids) - 1 if end < len(messages) else None}
>
>
> def postprocess(output, positions):
>     result = {"request": None, "response": None}
>     for side, start in (("request", 0), ("response", 14)):
>         position = positions[side]
>         if position is not None:
>             row = torch.tensor(output["embedding"][position][start:start + 14], dtype=torch.float32)
>             if row.numel() != 14 or not torch.isfinite(row).all():
>                 raise ValueError("Invalid Iris Content Guard output")
>             probabilities = torch.sigmoid(row).tolist()
>             result[side] = {
>                 "category_harm_probabilities": dict(zip(CATEGORIES, probabilities, strict=True))
>             }
>     return result
> ```
>
> ## Make a request
>
> ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> token_ids, positions = prepare(messages)
> payload = {"input_ids": token_ids}
>
> response = requests.post(f"{BASE_URL}/encode", headers=HEADERS, json=payload, timeout=TIMEOUT)
> result = postprocess(response.json(), positions)
> ```

> [tab] vLLM
>
> ## Get the image
>
> Pull the vLLM image and pin it by digest.
>
> ```bash Pull and pin the image icon="docker" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> export IMAGE='vllm/vllm-openai:reflection-project-iris'
> docker pull "$IMAGE"
> export IMAGE="$(docker image inspect "$IMAGE" \
>   --format '{{index .RepoDigests 0}}')"
> ```
>
> ## Start the server
>
> ```bash Start the server icon="docker" theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> docker run --rm --init --name beam \
>   --gpus device=0 --shm-size=32g \
>   -p 127.0.0.1:30000:30000 \
>   -v "${HF_HOME:-$HOME/.cache/huggingface}/hub:/root/.cache/huggingface/hub" \
>   --env HF_TOKEN \
>   --entrypoint vllm "$IMAGE" \
>   serve reflection/Iris-Content-Guard \
>   --host 0.0.0.0 --port 30000
> ```
>
> ## Make a request
>
> ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> import json
> import requests
>
> payload = {"model": MODEL, "data": {"messages": messages}}
>
> response = requests.post(f"{BASE_URL}/pooling", headers=HEADERS, json=payload, timeout=TIMEOUT)
> result = response.json()["data"]
> ```

## Read the response

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
print(json.dumps(result, indent=2))
```

```json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
  "request": {
    "category_harm_probabilities": {
      "cyber": 0.86,
      "fraud": 0.22,
      "privacy": 1.00,
      "bio_weapons": 0.01,
      "chem_weapons": 0.01,
      "rn_weapons": 0.01,
      "child_safety_non_csae": 0.12,
      "violence": 0.15,
      "self_harm": 0.00,
      "grooming": 0.39,
      "sex_crimes": 0.09,
      "sex_content": 0.01,
      "illegal_activities": 0.42,
      "hate": 0.05
    }
  },
  "response": {
    "category_harm_probabilities": {
      "cyber": 0.00,
      "fraud": 0.00,
      "privacy": 0.00,
      "bio_weapons": 0.00,
      "chem_weapons": 0.00,
      "rn_weapons": 0.00,
      "child_safety_non_csae": 0.00,
      "violence": 0.00,
      "self_harm": 0.00,
      "grooming": 0.00,
      "sex_crimes": 0.00,
      "sex_content": 0.00,
      "illegal_activities": 0.00,
      "hate": 0.00
    }
  }
}
```

## Next steps

* [Detection and thresholds](https://developers.reflection.ai/iris-content-guard-thresholds.md): choose thresholds for your product.

* [Where it fits](https://developers.reflection.ai/iris-content-guard.md#where-it-fits): when to score prompts and replies.

* [SGLang's release blog post](https://www.lmsys.org/blog/2026-11-30-project-iris): learn more about Iris support in SGLang.
