# Check text

Source: [Check text](<https://docs.gptunnel.ru/en/moderation/text-moderation/>)

<a id="_top"></a>
<a id="moderate-text"></a>
## Moderate text

`POST https://gptunnel.ru/v1/moderations`

The endpoint takes one text input and returns an overall flag and category results. To get a separate result for each text, send separate requests. A test request with an array of two strings returned one entry in `results`. The service chooses the model. In the example below, the response field `model` is `omni-moderation-latest`.

### Request headers

| Parameter | Type | Required? | Description |
| --- | --- | --- | --- |
| `Authorization` | `string` | Required | GPTunneL API key |

### Request body

| Parameter | Type | Required? | Description |
| --- | --- | --- | --- |
| `input`<a id="moderation-request-input"></a> | `string` | Required | Text to check. Send one non-empty string |
| `useWalletBalance`<a id="moderation-request-useWalletBalance"></a> | `boolean` | Optional | Set to true to use your personal balance |

<a id="example-request"></a>
### Example request

Set your [API key](<https://docs.gptunnel.ru/en/#get-an-api-key>) in the `GPTUNNEL_API_KEY` environment variable.

<a id="tab-panel-0-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

body = {
    'input': 'A blue sky.',
}
request = Request(
    'https://gptunnel.ru/v1/moderations',
    headers={
        'Authorization': os.environ['GPTUNNEL_API_KEY'],
        'Content-Type': 'application/json',
    },
    data=json.dumps(body).encode('utf-8'),
    method='POST',
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

<a id="tab-panel-0-1"></a>
**cURL**

```bash
curl --fail-with-body --silent --show-error \
  --url 'https://gptunnel.ru/v1/moderations' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --json '{
  "input": "A blue sky."
}'
```

<a id="tab-panel-0-2"></a>
**JavaScript (Node.js)**

```javascript
const response = await fetch('https://gptunnel.ru/v1/moderations', {
  method: 'POST',
  headers: {
    Authorization: process.env.GPTUNNEL_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "input": "A blue sky."
  }),
})
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

<a id="example-response"></a>
### Example response

The text `A blue sky.` returned one result with `flagged: false`. Read the category flags in `categories` and their numeric scores in `category_scores`. The example shows two of the returned categories. Moderation is billed per call. The `usage.prompt_tokens` field reports the input token count for reference. Text length does not affect the per-call rate. The `usage.total_cost` field shows the cost of the call in rubles after any discount.

```json
{
  "model": "omni-moderation-latest",
  "results": [
    {
      "flagged": false,
      "categories": {
        "harassment": false,
        "illicit": false
      },
      "category_scores": {
        "harassment": 0,
        "illicit": 0
      }
    }
  ],
  "usage": {
    "prompt_tokens": 4,
    "completion_tokens": 0,
    "prompt_cost": 0.24,
    "completion_cost": 0,
    "total_cost": 0.24
  }
}
```

<a id="errors"></a>
### Errors

| HTTP | What to check |
| --- | --- |
| 401 | Send a valid API key in the `Authorization` header. |
| 402 | Check the [balance of the selected account](<https://docs.gptunnel.ru/en/getting-started/balance/>). |
| 422 | If the `input` field is missing or empty, provide [text to check](<https://docs.gptunnel.ru/en/moderation/text-moderation/#moderation-request-input>). |

The endpoint returned the following HTTP 422 response:

```json
{
  "error": {
    "message": "input must be not empty",
    "type": "invalid_input",
    "param": null,
    "code": null
  }
}
```
