# Classify Content

`POST /rampart/classify` · Core · AI Safety

Classifies the submitted content and returns its classification, a risk score and a confidence (both in basis points, 0 to 10000), any categories, and the classifier's calibration version.

The classification (`clear`, `suspicious` or `malicious`) is a risk signal for your own decision: `malicious` is not an instruction to block, and `suspicious` is not a reason to block automatically. Weigh it with what you know about the request, for example route it for review or ask the user to confirm.

Body: `input` (an object, required) and an optional `label` (1 to 128 characters) naming the context.

The response also carries a signed `classificationReceipt`: a compact JWS with the protected-header `typ` `k9o.rampart.classify.v1`, signed with EdDSA.

It binds the SHA-256 of the input's canonical JSON (RFC 8785), the result, the project, the calibration version and `windows`, the number of windows scored.

Verify it against the key whose `kid` the receipt names, published at `GET /rampart/jwks`.

The receipt is advisory: a record of what the classifier answered, not an authorization.

Long input is never truncated: it is scored in overlapping windows of up to 512 tokens (128 tokens of overlap), and the result is the window with the highest risk.

Input that needs more than 16 windows (about 6,000 tokens) answers `413 K9O_RAMPART_INPUT_TOO_LONG` with no classification. If the classifier is unreachable or returns an unusable result for any window, the request fails closed with `503 K9O_RAMPART_CLASSIFIER_UNAVAILABLE`; no classification is invented, and no partial result is returned.

Requires membership in the project; an organization-level role alone does not grant access.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `input` | object | yes | The content to classify, as a JSON object. Rampart scores it for prompt injection: text written to make a model ignore its instructions. Send anything you want checked in one object: a prompt, a tool call's arguments, a retrieved document, an incoming email, or a prompt together with the content it pulled in. To classify plain text, send `{"text": "..."}`. Rules: - `input` must be an object. A string, array or null gets 400 `K9O_INVALID_FIELD_VALUE` with `context.reason` `not_an_object`. - Numbers must be integers up to 2^53-1. A fraction or a larger integer gets 400 naming the field's path, for example `input.items[2].price`, because the receipt hashes the exact input. - Up to about 6,000 tokens. Longer input gets 413 `K9O_RAMPART_INPUT_TOO_LONG` and no verdict. How it is read: the object is flattened to one `key: value` line per value. Keys are sorted at every level, and keys are read as well as values, because a key can carry an injection too. Each array item is its own line under the array's key. A nested object puts its key on its own line, then its members. Numbers, booleans and null appear as their JSON literal. Long input is scored in overlapping 512-token windows, and the highest-scoring window decides. An empty object is `clear`, and its receipt records that no window was scored. |
| `label` | string | no | A short label naming where the content came from, such as a tool name. It is not scored. Default `rampart_classify`. |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The classifier's verdict on the content, with its signed receipt. |
| `data.classification` | enum ("clear", "suspicious", "malicious") | yes | The verdict on the riskiest window. It is advisory: Rampart blocks nothing, and your code decides what to do with the content. |
| `data.riskScore` | integer | yes | The likelihood that the content is a prompt injection, in basis points (0 to 10000, where 10000 is certain). |
| `data.confidence` | integer | yes | How sure the classifier is of the verdict it gave, in basis points (0 to 10000). |
| `data.categories` | array of string | yes | Labels for the kind of risk found. The current classifier only distinguishes injection from safe, so this is empty. |
| `data.calibrationVersion` | string | yes | The version of the score thresholds that produced the verdict. It is signed into the receipt. |
| `data.projectId` | string | yes | The project the receipt is bound to (`proj_...`). Verifying the receipt compares this with its signed claim. |
| `data.classificationReceipt` | string | yes | A signed record of this verdict: a compact EdDSA JWS with `typ` `k9o.rampart.classify.v1`. It carries the SHA-256 of the canonical input, the verdict, the scores, the project, the calibration version and how many windows were scored. Verify it against the keys at `GET /rampart/jwks`. It is a record, not an authorization. |
| `meta` | object | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_UNAUTHENTICATED` | The caller is not signed in; authenticate before requesting a classification. |
| 400 | `K9O_INVALID_FIELD_VALUE` | The request body failed validation (input must be an object; optional label 1-128 chars). |
| 403 | `K9O_ACCESS_DENIED` | The caller is not a member of this project. Classification is a project data surface: an organization-level role alone does not grant access. |
| 413 | `K9O_RAMPART_INPUT_TOO_LONG` | The input needs more than 16 windows of 512 tokens (about 6,000 tokens), or the classifier refused it as too long (reason rampart_input_too_long). No classification is made; send a shorter input. |
| 503 | `K9O_RAMPART_CLASSIFIER_UNAVAILABLE` | The Rampart classifier could not be reached or returned an unusable result. The request fails closed and never returns an invented classification; retry later. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/rampart/classify' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/rampart/classify', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({}),
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.rampart.classify({})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.rampart.classify({})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Rampart.Classify(ctx, map[string]any{})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.rampart.classify(json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.rampart().classify(Map.of())
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Rampart.ClassifyAsync(new Dictionary<string, object> {  })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.rampart.classify({  })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->rampart->classify([])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/classify-content
