# Operation

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

```erlang
[POST] /api/v2/products/api/operations
[GET] /api/v2/products/api/operations/:id
[POST] /api/v2/products/api/operations/upload
```

{% endtab %}
{% endtabs %}

## The operation object

### Attributes

**status** `string`\
Current operation status. One of `ready`, `pending`, `running`, `failed`,`invalid`, or `done`.

**query** `hash`\
Query of operation request.\
\
&#x20;   query.**type** `string`\
&#x20;   Type of contents. Accepted values:\
&#x20;   \- `text`: textual type contents.\
&#x20;   \- `file`: file type contents (audio, images, or videos).\
\
&#x20;   query.**analyses** `array of strings`\
&#x20;   The analysis types applied to the operation. Accepted values: \
&#x20;   \- `sentiment-simple`\
&#x20;   \- `sentiment-real`\
&#x20;   \- `topic`\
&#x20;   \- `spam-detection`\
&#x20;   \- `personality-mb`\
&#x20;   \- `intention`\
&#x20;   \- `face-id`\
&#x20;   \- `object-id`\
&#x20;   \- `activity-id`\
&#x20;   \- `logo-id`\
&#x20;   \- `caption`\
&#x20;   More info on [supported analysis type](/tutorials/operation-supported-analysis-types.md).

&#x20;   query.**contents** `array of strings` *or* `array of integers`\
&#x20;   Contents to be analyzed depending on query.**type**.\
&#x20;   \-  Must be list of text entries if query.**type** is `text`.\
&#x20;   \-  Must be list of file IDs obtained through [upload](/resources/operation.md#upload-file-content) route or list of AWS S3 URLs for each file (publicly available) if query.**type** is `file`. Must be either file IDs or URLs per the same request.

&#x20;   query.**contents\_groups** `optional array of strings`\
&#x20;   A list where each entry represents a group of indexes in query.**contents**.\
&#x20;   If not present, query.**contents** are treated as one group.\
&#x20;   Only works on analysis type `personality-mb`.

**data** `hash` (only if **status** is `done`, otherwise null)\
Results of analyzed **query.contents**.\
\
&#x20;   data.**contents\_count** `integer`\
&#x20;   Total number of analyzed contents.\
\
&#x20;   data.**contents** `array of hashes`\
&#x20;   List of analyzed [content ](/resources/operation.md#the-content-object)object.

{% tabs %}
{% tab title="JSON EXAMPLE" %}

```javascript
{
    "status": "done",
    "query": {
        "type": "text",
        "analyses": [
            "spam-detection", "topic", "intention"
        ],
        "contents": [
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        ]
    },
    "data": {
        "contents": [
            {
                "type": "text",
                "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
                "analyses": [
                    {
                        "data": {
                            "prob": 0.6,
                            "value": "spam"
                        },
                        "type": "spam-detection",
                        "source": "content",
                        "dimension": "textual"
                    },
                    {
                        "data": [
                            {
                                "value": "thesis",
                                "sub_type": null,
                                "topic_type": "noun-chunk"
                            }
                        ],
                        "type": "topic",
                        "source": "content",
                        "dimension": "textual"
                    },
                    {
                        "data": {
                            "prob1": 0.88,
                            "prob2": 0.74,
                            "prob3": 0.78,
                            "value": "palinode"
                        },
                        "type": "intention",
                        "source": "content",
                        "dimension": "textual"
                    }
                ],
                "dimensions": [
                    "textual"
                ],
                "analysis_types": [
                    "spam-detection",
                    "topic",
                    "intention"
                ]
            }
        ],
        "contents_count": 1
    }
}
```

{% endtab %}
{% endtabs %}

## The content object

### Attributes

**type** `string`\
Type of content. One of `text` or `file`.

**content** `string` *or* `integer`\
Analyzed content. One of text entry, file ID or file URL.

**dimensions** `array of strings`\
Dimensions involved in this content. At least one of \
\- `textual`\
\- `audial`\
\- `visual-image`\
\- `visual-gif`\
\- `visual-video`

&#x20;**analysis\_type** `array of strings`\
The analysis types applied to this content. At least one of \
\- `sentiment-simple`\
\- `sentiment-real`\
\- `spam-detection`\
\- `personality-mb`\
\- `topic`\
\- `intention`\
\- `face-id`\
\- `object-id`\
\- `activity-id`\
\- `logo-id`\
\- `caption`

**analyses** `array of hashes`\
Content's result on **analysis\_type**, if any.\
\
&#x20;   analyses\[].**source** `string`\
&#x20;   Reference source leading to this result.

&#x20;   analyses\[].**type** `string`\
&#x20;   Analysis type applied to this result. One of \
&#x20;   \- `sentiment-simple`\
&#x20;   \- `sentiment-real`\
&#x20;   \- `spam-detection`\
&#x20;   \- `personality-mb`\
&#x20;   \- `topic`\
&#x20;   \- `intention`\
&#x20;   \- `face-id`\
&#x20;   \- `object-id`\
&#x20;   \- `activity-id`\
&#x20;   \- `logo-id`\
&#x20;   \- `caption`\
\
&#x20;   analyses\[].**dimension** `string`\
&#x20;   Dimension involved in this result. One of \
&#x20;   \- `textual`\
&#x20;   \- `audial`\
&#x20;   \- `visual-image`\
&#x20;   \- `visual-gif`\
&#x20;   \- `visual-video`

&#x20;   analyses\[].**group\_index** `optional integer`\
&#x20;   Index in query.**contents\_groups**.

&#x20;   analyses\[].**data** `hash` *or* `array of hashes`\
&#x20;   Analyzed result, if any. Data format varies from analyses\[].**type**.

{% tabs %}
{% tab title="sentiment-real" %}
analyses\[].data.**value** `string`\
Sentiment label. One of `acceptance_self`, `acceptance`, `anger`, `annoyance`, `anxiety`, `calmness`, `contentment`, `disgust_self`, `disgust`, `dislike_self`, `dislike`, `eagerness`, `fear`, `joy`, `melancholy`, `pleasantness_self`, `pleasantness`, `responsiveness`, `sadness` or `serenity`.\
\
analyses\[].data.**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}

{% tab title="sentiment-simple" %}
analyses\[].data.**value** `string`\
Simple sentiment label. One of `positive`, `neutral`, or `negative`.\
\
analyses\[].data.**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}

{% tab title="spam-detection" %}
analyses\[].data.**value** `string`\
Spam label. One of `spam` or `ham`.\
\
analyses\[].data.**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}

{% tab title="personality-mb" %}
analyses\[].data.**value** `string`\
Personlity Myers-Brigg label. Classified by focus: *extraversion(E) or introversion(I)*, information input: *sensing(S) or intuition(N)*, decision making: *thinking(T) or feeling(F)* and lifestyle: *judging(J) or perceiving(P)*. One of `ESTJ`, `ENTJ`, `ESFJ`, `ENFJ`, `ISTJ`, `ISFJ`, `INTJ`, `INFJ`, `ESTP`, `ESFP`, `ENTP`, `ENFP`, `ISTP`, `ISFP`, `INTP`, or `INFP`.\
\
analyses\[].data.**prob1** `integer`\
Probability of preferring extraversion or introversion depending on **value**. In range (0.0, 1.0).\
\
analyses\[].data.**prob2** `integer`\
Probability of preferring sensing or intuition depending on **value**. In range (0.0, 1.0).\
\
analyses\[].data.**prob3** `integer`\
Probability of preferring thinking or feeling depending on **value**. In range (0.0, 1.0).\
\
analyses\[].data.**prob4** `integer`\
Probability of preferring judging or perceiving depending on **value**. In range (0.0, 1.0).\
\
analyses\[].data.**group** `boolean`\
whether if **value** result is based on contents grouped in query.**contents\_groups**
{% endtab %}

{% tab title="topic" %}
analyses\[].data\[].**value** `string`\
Topic label. Word or phrase derived from content.\
\
analyses\[].data\[].**topic\_type** `string`\
Type of **value.** One of `entity` or `noun-chunk`.\
\
analyses\[].data\[].**sub\_type** `integer`\
Classification of **topic\_type**, if any.\
\- If **topic\_type** is `entity`, one of `PERSON`, `NORP`, `FAC`, `ORG`, `GPE`, `LOC`, `PRODUCT`, `EVENT`, `WORK_OF_ART`, `LAW`, or `LANGUAGE`.\
\- If **topic\_type** is `noun-chunk`, one of `POS`, `ADJ`, `ADV`, `ADP`, `VERB`, `NOUN`, `PROPN`, `INTJ`, `SCONJ`, `AUX`, `CONJ`, `CCONJ`, `INTJ`.
{% endtab %}

{% tab title="intention" %}
analyses\[].data.**value** `string`\
Intention label. Classified by affect: *affective or denotative*, time: *present/past or future* and description: *descriptive or prescriptive*. One of `assertion`, `valuation`, `palinode`, `contrition`, `forecast`, `wish`, `proposal`, `inducement`, or `none`.\
\
Intention Label Classification\
\- `assertion` (denotative, present/past, descriptive)\
\- `valuation` (affective, present/past, descriptive)\
\- `palinode` (denotative, present/past, prescriptive)\
\- `contrition` (affective, present/past, prescriptive)\
\- `forecast` (denotative, future, descriptive)\
\- `wish` (affective, future, descriptive)\
\- `proposal` (denotative, future, prescriptive)\
\- `inducement` (affective, future, prescriptive)\
\
analyses\[].data.**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="face-id" %}
analyses\[].data\[].**value** `string`\
Detected face label.\
\
analyses\[].data\[].**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}

{% tab title="object-id" %}
analyses\[].data\[].**value** `string`\
Detected object label.\
\
analyses\[].data\[].**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}

{% tab title="activity-id" %}
analyses\[].data\[].**value** `string`\
Detected activity label.\
\
analyses\[].data\[].**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}

{% tab title="  logo-id  " %}
analyses\[].data\[].**value** `string`\
Detected logo label.\
\
analyses\[].data\[].**prob** `integer`\
Probability of **value** occurrence. In range (0.0, 1.0).
{% endtab %}

{% tab title="caption" %}
analyses\[].data\[].**description** `optional string`\
Text description of image.\
\
analyses\[].data\[].**duration** `optional string`\
Video length\
\
analyses\[].data\[].**descriptions** `optional array of hashes`\
Text descriptions of video moments.

&#x20;   analyses\[].data\[].descriptions\[].**timestamp** `string`\
&#x20;   Specific video moment

&#x20;   analyses\[].data\[].descriptions\[].**description** `string`\
&#x20;   Video description at this moment
{% endtab %}
{% endtabs %}

## Create an operation

Creates and places new operation into queue. To check the status of an operation, use [show](/resources/operation.md#retrieve-an-operation) route.

### Request

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

```erlang
[POST] /api/v2/products/api/operations
```

{% endtab %}
{% endtabs %}

#### **Payload**

**type** `string`\
Type of contents. Accepted values:\
\- `text`: textual type contents.\
\- `file`: file type contents (audio, images, or videos).

**analyses** `array of strings`\
The analysis types applied to the operation. Accepted values: \
\- `sentiment-simple`\
\- `sentiment-real`\
\- `spam-detection`\
\- `personality-mb`\
\- `topic`\
\- `intention`\
\- `face-id`\
\- `object-id`\
\- `activity-id`\
\- `logo-id`\
\- `caption`\
More info on [supported analysis type](/tutorials/operation-supported-analysis-types.md).\
\
**contents** `array of strings` *or* `array of integers`\
Contents to be analyzed depending on **type**.\
\-  Must be list of text entries if **type** is `text`.\
\-  Must be list of file IDs obtained through [upload](/resources/operation.md#upload-file-content) route or list of AWS S3 URLs for each file (publicly available) if query.**type** is `file`. Must be either file IDs or URLs per the same request.\
\
**contents\_groups** `optional array of strings`\
A list where each entry represents a group of indexes in **contents**.\
If not present, **contents** are treated as one group.\
Only works on analysis type `personality-mb`.

{% hint style="info" %}
Indexing starts from 0.&#x20;
{% endhint %}

{% tabs %}
{% tab title="TYPE TEXT JSON EXAMPLE" %}

```javascript
{
    "type": "text",
    "analyses": [
        "spam-detection",
        "sentiment-real",
        "topic",
        "personality-mb"
    ],
    "contents_groups": [
        "1,2,3",
        "0,4,5"
    ],
    "contents": [
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "Praesent eget purus vel metus hendrerit vestibulum.",
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "Praesent eget purus vel metus hendrerit vestibulum.",
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "Praesent eget purus vel metus hendrerit vestibulum."
    ]
}
```

{% endtab %}

{% tab title="TYPE FILE JSON EXAMPLE" %}

```javascript
{
    "type": "file",
    "analyses": [
        "face-id",
        "sentiment-real",
        "topic"
    ],
    "contents": [
        1, 2, 3
    ]
}
```

{% endtab %}
{% endtabs %}

#### Example

```bash
curl -i -X POST 'https://product-api.redflagai.co/api/v2/products/api/operations' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer {{JWT_TOKEN}}' \
-d '{
    "type": "text",
    "analyses": [
        "spam-detection",
        "sentiment-real",
        "topic"
    ],
    "contents": [
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "Praesent eget purus vel metus hendrerit vestibulum."
    ]
}'
```

### Response

The operation ID. To be used when [retrieving operation](/resources/operation.md#retrieve-an-operation).

```bash
{
    "id": 1
}
```

## Retrieve an operation

Retrieves the operation with given operation ID.

### Request

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

```erlang
[GET] /api/v2/products/api/operations/:id
```

{% endtab %}
{% endtabs %}

#### Example

```bash
curl -i -X GET 'https://product-api.redflagai.co/api/v2/products/api/operations/1' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H'Authorization: Bearer {{JWT_TOKEN}}' \
```

### Response

The [operation ](/resources/operation.md#the-operation-object)object.<br>

## Upload file content

Upload file as operation request's content. Only PNG, JPG, MP3 or MP4 is allowed.

### Request

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

```erlang
[POST] /api/v2/products/api/operations/upload
```

{% endtab %}
{% endtabs %}

#### Example

```bash
curl -i -X POST 'https://product-api.redflagai.co/api/v2/products/api/operations/upload' \
-H 'Content-Type: multipart/form-data' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer {{JWT_TOKEN}}' \
-F 'file=@"{{FILE_LOCATION}}"'
```

### Response

The file content ID. To be used when [creating operation](/resources/operation.md#create-an-operation).

```bash
{
    "id": 1
}
```

{% hint style="warning" %}
Once file is used in an operation, it cannot be reused.
{% endhint %}


---

# 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.redflagai.co/resources/operation.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.
