> For the complete documentation index, see [llms.txt](https://docs.mozilla.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mozilla.ai/any-guardrail/api-reference/providers/zero-din.md).

# 0DIN Defense API

Execution provider for 0DIN's hosted SusFactor scoring API.

Pass it as `AnyGuardrail.create(GuardrailName.SUSFACTOR, provider=ZeroDinProvider())` to run the `Susfactor` guardrail against 0DIN Defense instead of the gated local ONNX model — the guardrail class, its `threshold`, and its `GuardrailOutput` shape are unchanged.

Authentication is a two-step exchange. A long-lived 0DIN Portal API key is posted to `https://0din.ai/api/v1/access_tokens` to mint a JWT valid for 900 seconds, and that JWT is sent as a bearer token to `https://defense.0din.ai/api/v1/sus`. The provider caches the JWT, renews it a minute before expiry, and re-mints once if the service rejects it anyway (clock skew, revocation, key rotation).

Unlike the REST guardrails in this codebase, requests carry an explicit `request_timeout`: this provider sits in the request path, where hanging forever on a half-open connection is the worst available failure mode.

Behavioral note: 0DIN chunks long prompts server-side with unpublished size/stride parameters and returns only the maximum score, whereas the local ONNX path uses a 510-token window with 50-token overlap and exposes every chunk score. The two backends can therefore disagree on very long inputs.

## Constructor

| Parameter         | Type    | Required | Default                                  | Description                                                            |
| ----------------- | ------- | -------- | ---------------------------------------- | ---------------------------------------------------------------------- |
| `api_key`         | \`str   | None\`   | No                                       | `None`                                                                 |
| `jwt`             | \`str   | None\`   | No                                       | `None`                                                                 |
| `base_url`        | `str`   | No       | `"https://defense.0din.ai"`              | Scoring host. Defaults to `https://defense.0din.ai`.                   |
| `auth_endpoint`   | `str`   | No       | `"https://0din.ai/api/v1/access_tokens"` | Token-minting URL. Defaults to `https://0din.ai/api/v1/access_tokens`. |
| `request_timeout` | `float` | No       | `30.0`                                   | Per-request timeout in seconds. Defaults to 30.                        |

Configure the provider. Performs no network I/O — see `load_model`.

## load\_model

Resolve credentials and mint an initial JWT, so a bad key fails at construction.

**Parameters**

| Parameter  | Type  | Required | Default | Description                                                             |
| ---------- | ----- | -------- | ------- | ----------------------------------------------------------------------- |
| `model_id` | `str` | Yes      | —       | The service identifier this provider serves; must be `"susfactor-api"`. |

**Returns:** `None`

## pre\_process

Wrap the prompt into the scoring request body.

0DIN tokenizes and chunks server-side, so the only client-side preparation is shaping the JSON payload.

**Parameters**

| Parameter    | Type  | Required | Default | Description          |
| ------------ | ----- | -------- | ------- | -------------------- |
| `input_text` | `str` | Yes      | —       | The prompt to score. |

**Returns:** `GuardrailPreprocessOutput[AnyDict]`

## infer

POST the prompt to `/api/v1/sus` and return its suspicion score.

**Parameters**

| Parameter      | Type                                 | Required | Default | Description                                               |
| -------------- | ------------------------------------ | -------- | ------- | --------------------------------------------------------- |
| `model_inputs` | `GuardrailPreprocessOutput[AnyDict]` | Yes      | —       | The wrapped `{"prompt": ...}` payload from `pre_process`. |

**Returns:** `GuardrailInferenceOutput[AnyDict]`

## close

Close the underlying HTTP session. Idempotent.

**Returns:** `None`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mozilla.ai/any-guardrail/api-reference/providers/zero-din.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
