# Model

## Predict

## Used to send prediction request and get result-id as response.

<mark style="color:green;">`POST`</mark> `URL:{{base_url}}/api/{{version}}/model/:id/predict`

#### Path Parameters

| Name                                 | Type   | Description                        |
| ------------------------------------ | ------ | ---------------------------------- |
| id<mark style="color:red;">\*</mark> | String | Model id of a particular ml model. |

#### Headers

| Name                                            | Type             | Description |
| ----------------------------------------------- | ---------------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | API key          |             |
| Content-Type<mark style="color:red;">\*</mark>  | application/json |             |

#### Request Body

| Name                                            | Type                | Description                                                                                                                                                                                                                                                                                                                                             |
| ----------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| file                                            | multipart/form-data | File with extensions png , jpeg and pdf. This field is used to send file for getting prediction from ml models.                                                                                                                                                                                                                                         |
| version<mark style="color:red;">\*</mark>       | multipart/form-data | <p>Used to specify the version of ml model, using which we need to get the prediction.</p><p>To get prediction using latest version of the model without specifying the correct version , give version value as 0.0. Then the api will use latest available version of the model to get prediction.</p>                                                 |
| splitDocument<mark style="color:red;">\*</mark> | multipart/form-data | It can be "true" or "false". But currently "true" value is only available for some ml models. If the chosen model could not support "true", api will send bad request response. "true" value can give more accurate result if the give pdf file contains more than one page. Please use "true" value in the case of invoice model to increase accuracy. |
| text                                            | multipart/form-data | Used to get prediction from NER type ml models.                                                                                                                                                                                                                                                                                                         |

{% tabs %}
{% tab title="200: OK Returns result\_id." %}

```javascript
{
    "data": {
        "result_id": "String"
    },
    "message": "String",
    "status": 200
}
```

{% endtab %}

{% tab title="400: Bad Request Message field can be used to identify the issue." %}

```javascript
{
    "data": {},
    "message": "String",
    "status": 400
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid API key." %}

```javascript
{
    "data": {},
    "message": "ERROR: Unauthorized",
    "status": 401
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Used to get result of a particular prediction using result id.

<mark style="color:blue;">`GET`</mark> `URL:{{base_url}}/api/{{version}}/model/result/:id`

#### Path Parameters

| Name                                  | Type   | Description                           |
| ------------------------------------- | ------ | ------------------------------------- |
| id <mark style="color:red;">\*</mark> | String | Result id of a particular prediction. |

#### Headers

| Name                                            | Type             | Description |
| ----------------------------------------------- | ---------------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | API key          |             |
| Content-Type<mark style="color:red;">\*</mark>  | application/json |             |

{% tabs %}
{% tab title="200: OK Value of result field is a dictionary that contains prediction result. Structure of result dictionary may vary with different ml models." %}

```javascript
{
    "data": {
        "message":"String",
        "status":"SUCCESS",
        "result":{}
    },
    "message": "String",
    "status": 200
}
```

{% endtab %}

{% tab title="400: Bad Request Message field can be used to identify the issue." %}

```javascript
{
    "data": {},
    "message": "String",
    "status": 400
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid api key." %}

```javascript
{
    "data": {},
    "message": "ERROR: Unauthorized",
    "status": 401
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="202: Accepted IN PROGRESS status indicates that the ml model is predicting the result. May take some time to produce the result. Try to call the API after some time to get the result." %}

```javascript
{
    "data": {
        "message":"String",
        "status":"IN PROGRESS",
        "result":{}
    },
    "message": "String",
    "status": 202
}
```

{% endtab %}

{% tab title="204: No Content FAILED status indicates that the given prediction request is failed due to some reasons. Please contact Visualyze.AI for more information." %}

```javascript
{
    "data": {
        "message":"String",
        "status":"FAILED",
        "result":{}
    },
    "message": "String",
    "status": 204
}
```

{% endtab %}
{% endtabs %}

## Model

## Used to list available models.

<mark style="color:blue;">`GET`</mark> `URL:{{base_url}}/api/{{version}}/model/view`

#### Headers

| Name                                            | Type             | Description |
| ----------------------------------------------- | ---------------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | API key          |             |
| Content-Type<mark style="color:red;">\*</mark>  | application/json |             |

{% tabs %}
{% tab title="200: OK Models field contains list of models. Each dictionary in the list is used to represent a unique ml model. Version details of pretrained models will be unavailable to the user." %}

```javascript
{
    "data": {
        "models":[]     
    },
    "message": "String",
    "status": 200
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid API key." %}

```javascript
{
    "data": {},
    "message": "ERROR: Unauthorized",
    "status": 401
}
```

{% endtab %}

{% tab title="400: Bad Request Message field can be used to identify the issue." %}

```javascript
{
    "data": {},
    "message": "String",
    "status": 400
}
```

{% endtab %}
{% endtabs %}

## Used to get model details.

<mark style="color:blue;">`GET`</mark> `URL:{{base_url}}/api/{{version}}/model/:id/view`

#### Path Parameters

| Name                                 | Type   | Description                        |
| ------------------------------------ | ------ | ---------------------------------- |
| id<mark style="color:red;">\*</mark> | String | Model id of a particular ml model. |

#### Headers

| Name                                            | Type             | Description |
| ----------------------------------------------- | ---------------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | API key          |             |
| Content-Type<mark style="color:red;">\*</mark>  | application/json |             |

{% tabs %}
{% tab title="200: OK Model details dictionary will have the details of ml model." %}

```javascript
{
    "data": {
        "model_details":{}   
    },
    "message": "String",
    "status": 200
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid API key." %}

```javascript
{
    "data": {},
    "message": "ERROR: Unauthorized",
    "status": 401
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="400: Bad Request Message field can be used to identify the issue." %}

```javascript
{
    "data": {},
    "message": "String",
    "status": 400
}
```

{% endtab %}
{% endtabs %}

## Used to get version details of particular model.

<mark style="color:blue;">`GET`</mark> `URL:{{base_url}}/api/{{version}}/model/:id/:version/info`

#### Path Parameters

| Name                                      | Type   | Description                        |
| ----------------------------------------- | ------ | ---------------------------------- |
| id<mark style="color:red;">\*</mark>      | String | Model id of a particular ml model. |
| version<mark style="color:red;">\*</mark> | Float  | Version of a particular ml model.  |

#### Headers

| Name                                            | Type             | Description |
| ----------------------------------------------- | ---------------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | API key          |             |
| Content-Type<mark style="color:red;">\*</mark>  | application/json |             |

{% tabs %}
{% tab title="200: OK Info field contains version based details of a particular ml model. But we do not provide version details of PRETRINED ml models. You may get an empty dictionary in the case of PRETRINED models." %}

```javascript
{
    "data": {
        "info": {}
    },
    "message": "successfully retrieved details",
    "status": 200
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid API key." %}

```javascript
{
    "data": {},
    "message": "ERROR: Unauthorized",
    "status": 401
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="400: Bad Request Message field can be used to identify the issue." %}

```javascript
{
    "data": {},
    "message": "String",
    "status": 400
}
```

{% endtab %}
{% endtabs %}

## Used to delete latest model version.

<mark style="color:red;">`DELETE`</mark> `URL:{{base_url}}/api/{{version}}/model/:id/delete`

#### Path Parameters

| Name                                  | Type   | Description                        |
| ------------------------------------- | ------ | ---------------------------------- |
| id <mark style="color:red;">\*</mark> | String | Model id of a particular ml model. |

#### Headers

| Name                                            | Type             | Description |
| ----------------------------------------------- | ---------------- | ----------- |
| Authorization<mark style="color:red;">\*</mark> | API key          |             |
| Content-Type<mark style="color:red;">\*</mark>  | application/json |             |

{% tabs %}
{% tab title="200: OK Deleted the latest version of model." %}

```javascript
{
    "data": {},
    "message": "deleted successfully",
    "status": 200
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid API key." %}

```javascript
{
    "data": {},
    "message": "ERROR: Unauthorized",
    "status": 401
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="400: Bad Request Message field can be used to identify the issue." %}

```javascript
{
    "data": {},
    "message": "String",
    "status": 400
}
```

{% endtab %}
{% endtabs %}

{% hint style="danger" %}
You cannot delete PRETRIAINED models using Delete API
{% endhint %}
