# Standard & Premium: Policy Classification endpoints

The Policy Classification endpoints will serve you two products: Unitary Standard and Unitary Premium. The table below shows more details for each:

<table><thead><tr><th width="120">Product</th><th width="391">Categories covered</th><th>How it works</th></tr></thead><tbody><tr><td><strong>Standard</strong></td><td><p>• <strong>Adult &#x26; Sexual.</strong> Explicit sexual activity, nudity, detailed explanations of sexual encounters…</p><p><strong>• Non-medical Drugs.</strong> Pills, coke, marihuana, minors drinking or smoking, paraphernalia…</p><p><strong>• Violence and Injury.</strong> People killing or sexually assaulting other people, violent fights in uncontrolled settings, animal abuse, physical threats, suicide, self-injury or eating disorders and their glorification, graphic injuries...</p><p><strong>• Weapons and Firearms.</strong> Firearms, ammunition, explosives, non-kitchen knives or homemade weapons in dangerous settings, instructional content on weapons…</p><p><strong>• Hate Speech and Hate Symbols.</strong> Symbols from hate organisations, discrimination of people based on their identity…</p></td><td><p>The Standard product works "off the shelf". It does not require any input from your side. Please let us know if you need help analysing Untiary's model responses to set up decision thresholds.</p><p></p><p>To see improved performance over time, you can also get in contact to share false negatives and positives and make Unitary's models better for your use case.</p></td></tr><tr><td><strong>Premium</strong></td><td>All Standard categories tweaked based on your content guidelines + any other categories you may need e.g. cosmetic products.</td><td>The Premium product will give you greater accuracy by understanding your content guidelines and getting fine-tuned with your data.<br><br>You can benefit from Unitary's Premium offering category by category. Please get in contact if you are interested in this.</td></tr></tbody></table>

For both the Standard and Premium products, Unitary will return in the classification results a raw score that you can use to set thresholds and determine if data is safe, harmful or ambiguous.&#x20;

Please read [how-to-select-thresholds-for-items-and-characteristics](https://docs.unitary.ai/api-references/how-to-select-thresholds-for-items-and-characteristics "mention")if you need help analysing the Standard scores. We'll give you custom thresholds for any premium category we fine-tune to your policy or data.

{% hint style="success" %}
You can contact <support@unitary.ai> if you wish to explore Unitary's Premium offering.
{% endhint %}

## 1. Authenticate

Please follow the [authentication](https://docs.unitary.ai/api-references/authentication "mention") instructions first in order to authenticate with Unitary's API. This will generate a token that is valid for 24 hours and must be used in subsequent API requests.

## 2. Sending your first request

Depending on your use case, pick an image or a video and then use one of the following `POST` endpoints to send your first request.

### POST endpoint reference

{% openapi src="<https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media>" path="/classify/policy/image" method="post" %}
[api-worker.autogenerated.openapi.yaml](https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media)
{% endopenapi %}

{% openapi src="<https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media>" path="/classify/policy/video" method="post" %}
[api-worker.autogenerated.openapi.yaml](https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media)
{% endopenapi %}

### Example code

{% tabs %}
{% tab title="cURL" %}

<pre class="language-bash" data-overflow="wrap"><code class="lang-bash"><strong>curl --location --request POST "https://api.unitary.ai/v1/classify/policy/image" \
</strong>--header "Authorization: Bearer {API_TOKEN}" \
--form "caption={CAPTION}" \
--form "url={RESOURCE_URL}"
</code></pre>

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_token = "your_api_token_here"
file_path = "/path/to/your/file.jpg"
caption = "your_caption_here"
url = "https://api.unitary.ai/v1/classify/policy/image"

# For sending a URL
data = {
    'caption': caption,
    'url': 'your_resource_url_here'
}
headers = {'Authorization': f'Bearer {api_token}'}

response = requests.post(url, data=data, headers=headers)
job_id = resonse.text["job_id"]

print(job_id)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs');

const apiToken = 'your_api_token_here';
const file_path = '/path/to/your/file.jpg';
const caption = 'your_caption_here';
const url = 'https://api.unitary.ai/v1/classify/image';

// For sending a URL
const dataUrl = new URLSearchParams();
dataUrl.append('caption', caption);
dataUrl.append('url', 'your_resource_url_here');

fetch(url, {
  method: 'POST',
  body: dataUrl,
  headers: {
    'Authorization': `Bearer ${apiToken}`,
    'Content-Type': 'application/x-www-form-urlencoded',
  },
})
.then(response => response.text())
.then(result => console.log(result["job_id"]))
.catch(error => console.log('error', error));
```

{% endtab %}
{% endtabs %}

## 3. Get results back via the GET endpoint

{% hint style="warning" %}
Using the GET endpoint may be inadequate for large scale! The recommendation is using the "`callback_url`" parameter instead. Please check the [integrating\_webhooks](https://docs.unitary.ai/api-references/integrating_webhooks "mention") guide for more information.
{% endhint %}

### GET endpoint reference

{% openapi src="<https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media>" path="/classify/policy/image/{job\_id}" method="get" %}
[api-worker.autogenerated.openapi.yaml](https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media)
{% endopenapi %}

{% openapi src="<https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media>" path="/classify/policy/video/{job\_id}" method="get" %}
[api-worker.autogenerated.openapi.yaml](https://1303016406-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkYGyPKqtHGZyEvMl1GP%2Fuploads%2Fgit-blob-1ea297cbed161d2a16d21ca42ffa258cb07caefb%2Fapi-worker.autogenerated.openapi.yaml?alt=media)
{% endopenapi %}

### Example code

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```bash
curl --location --request GET "https://api.unitary.ai/v1/classify/image/{JOB_ID}" \
--header "Authorization: Bearer {BEARER_TOKEN}"
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}

```python
import requests

BEARER_TOKEN = "{BEARER_TOKEN}"
JOB_ID = "{JOB_ID}
url = f"https://dev.api.unitary.ai/v1/classify/image/{JOB_ID}"

payload={}
headers = {
  'Authorization': f'Bearer {BEARER_TOKEN}'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response)

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const fetch = require("node-fetch"); 
const BEARER_TOKEN = "{BEARER_TOKEN}";
const JOB_ID = "{JOB_ID}";
const url = `https://dev.api.unitary.ai/v1/classify/image/${JOB_ID}`;

fetch(url, {
  method: "GET",
  headers: {
    'Authorization': `Bearer ${BEARER_TOKEN}`,
  },
})
.then(response => response.json())
.then(data => {
  const results = data["results"];
  console.log(results);
})
.catch((error) => {
  console.error('Error:', error);
});
```

{% endtab %}
{% endtabs %}

### Example responses

Depending on the processing status of the job at the time of request, you can get any of the following as the response from the GET endpoints:

{% tabs %}
{% tab title="Status: successful" %}

```json
{
  "status": "done",
  "results": {
    "policy_categories": [
      {
        "name": "{CATEGORY_NAME}",
        "description": "{CATEGORY_DESCRIPTION}",
        "score": 0.99
      }
    ],
    "url": "{RESOURCE_URL}"
  }
}
```

{% endtab %}

{% tab title="Status: queued" %}

```json
{
  "status": "queued"
}
```

{% endtab %}

{% tab title="Status: error" %}

```json
{
  "status": "failed",
  "msg": "the error message for the request"
}
```

{% endtab %}
{% endtabs %}

## 4. Webhooks

**(optional but encouraged)**&#x20;

In order to have a scalable end-to-end integration, the last step is to set up the receiving of webhooks as described in the following guide: [integrating\_webhooks](https://docs.unitary.ai/api-references/integrating_webhooks "mention")


---

# Agent Instructions: 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:

```
GET https://docs.unitary.ai/api-references/policy-classification.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
