Skip to content

Asynchronous Requests

For the following services we are allowing to call requests in asynchronous way:

Why asynchronous requests? You can call/create much more requests at once in asynchronous way than with synchronous way. You just need to store the id of the requests and then later query them and check the results. Some of the synchronous endpoints can take a lot of time for completed processing (upscaler). That is why the asynchronous requests are better.

Each createad request is identified by id (UUID). When submitting request you will need to specify type of requests. After submitting the request via REST API (POST), the request is stored in our database with the state CREATED. Once the specific worker take the request for analysis the request changed it's state to PROCESSING. Completed request has state DONE. Processing of request can take several seconds to minutes (depends on number of requests in queue). Please store id of the submitted request for getting results.

BETA

Asynchronous requests are righ now in BETA release mode. We are testing this part of service. Feel free to send us a feedback at tech@ximilar.com.

Querying Requests

For getting list of all asynchronous requests (pagindated results) submitted by user, you can call:

curl --request GET \
  --url https://api.ximilar.com/account/v2/request/ \
  --header 'Authorization: Token __AUTH_TOKEN__' \
  --header 'Content-Type: application/json'
from ximilar.client.asyncr import AsyncRClient

client = AsyncRClient(__API_TOKEN__)
requests, next_page, status = client.get_requests(page_url=None)
CLICK TO SHOW JSON RESULT

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": "2e9b43f2-61be-4aaa-8a6a-a74fc0f80b57",
            "status": "PROCESSING",
            "type": "upscaler",
            "created": "2022-03-02T13:38:22.784359Z",
            "workspace": "88431559-20ea-4d43-98a6-7a1cb38160e3"
        },
        {
            "id": "1abea671-400c-4fa3-9f30-be29a5cdea32",
            "status": "DONE",
            "type": "upscaler",
            "created": "2022-03-02T13:03:59.176871Z",
            "workspace": "88431559-20ea-4d43-98a6-7a1cb38160e3"
        }
    ]
}

For getting list of all asynchronous request submitted by user, with filtering on type and status:

curl --request GET \
  --url 'https://api.ximilar.com/account/v2/request/?status=DONE&type=UPSCALER' \
  --header 'Authorization: Token __AUTH_TOKEN__' \
  --header 'Content-Type: application/json'
from ximilar.client.asyncr import AsyncRClient

client = AsyncRClient(__API_TOKEN__)
requests, next_page, status = client.get_requests(page_url=None, type="upscaler", status="DONE")
CLICK TO SHOW JSON RESULT

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": "2e9b43f2-61be-4aaa-8a6a-a74fc0f80b57",
            "status": "DONE",
            "type": "upscaler",
            "created": "2022-03-02T13:38:22.784359Z",
            "workspace": "88431559-20ea-4d43-98a6-7a1cb38160e3"
        },
        {
            "id": "1abea671-400c-4fa3-9f30-be29a5cdea32",
            "status": "DONE",
            "type": "upscaler",
            "created": "2022-03-02T13:03:59.176871Z",
            "workspace": "88431559-20ea-4d43-98a6-7a1cb38160e3"
        }
    ]
}

Get status of request with specific ID:

curl --request GET \
  --url https://api.ximilar.com/account/v2/request/__REQUEST_ID__/status \
  --header 'Authorization: Token __AUTH_TOKEN__' \
  --header 'Content-Type: application/json'
from ximilar.client.asyncr import AsyncRClient

client = AsyncRClient(__API_TOKEN__)
request, _ = client.get_request(__ID__)
print(request.check_status())
CLICK TO SHOW JSON RESULT

{
    "status": "DONE"
}

Get result of request (result in response field is present only if the request is in status DONE):

curl --request GET \
  --url https://api.ximilar.com/account/v2/request/__REQUEST_ID__ \
  --header 'Authorization: Token __AUTH_TOKEN__' \
  --header 'Content-Type: application/json'
from ximilar.client.asyncr import AsyncRClient

client = AsyncRClient(__API_TOKEN__)
request, _ = client.get_request(__ID__)
CLICK TO SHOW JSON RESULT

{
    "id": "2e9b43f2-61be-4aaa-8a6a-a74fc0f80b57",
    "created": "2022-03-02T13:38:22.784359Z",
    "modified": "2022-03-02T13:38:22.784359Z",
    "request": {
        "type": "upscaler",
        "records": [
            {
                "_id": "2e9b43f2-61be-4aaa-8a6a-a74fc0f80b57",
                "_url": "https://images.ximilar.com/examples/fashion_products/01_1149810256_SI_00.jpeg"
            }
        ],
        "endpoint": "upscale_2x"
    },
    "response": {
        "records": [
            {
                "_id": "2e9b43f2-61be-4aaa-8a6a-a74fc0f80b57",
                "_url": "https://images.ximilar.com/examples/fashion_products/01_1149810256_SI_00.jpeg",
                "_width": 800,
                "_height": 1200,
                "_status": {
                    "code": 200,
                    "text": "OK",
                    "request_id": "b61e7879-8038-445b-a617-de4be5b2e447"
                },
                "_upscaled_width": 1600,
                "_upscaled_height": 2400,
                "_upscaled_image_url": "https://s3-eu-west-1.amazonaws.com/ximilar-tmp-images/upscale/dce17b2c-e9ad-4870-9fa8-470ba633ea0a.jpg"
            }
        ]
    },
    "type": "upscaler",
    "status": "DONE",
    "workspace": "88431559-20ea-4d43-98a6-7a1cb38160e3"
}

Upscaler Requests

The required fields for request are type, endpoint and records. Optionally you can specify mode. The endpoint field must one of [upscale_2x,upscale_4x,upscale_8x]. Be aware that the result field _upscaled_image_url has limited expiration of one day. If you want to use GAN (Generative) model please include field model_type with value gan in request. If you want to use classic model then omit the field.

For creating the asynchronous request you will need to call the API endpoint in following way:

curl --request POST \
  --url https://api.ximilar.com/account/v2/request \
  --header 'Authorization: Token __AUTH_TOKEN__' \
  --header 'Content-Type: application/json' \
  --data '{
    "type": "upscaler",
    "endpoint": "upscale_2x",
    "mode": "high_fidelity",
    "model_type": "gan",
    "records": [
        {
            "_url": "__URL_PATH__"
        }
    ]
}'
from ximilar.client.asyncr import AsyncRClient

client = AsyncRClient(__API_TOKEN__)
request, _ = client.submit({"records":[{"_url":"__URL_PATH__"}]}, "upscaler", endpoint="upscale_2x")

time.sleep(20) # lets wait
request.update()
print(request.response)
CLICK TO SHOW JSON RESULT

{
    "id": "2e9b43f2-61be-4aaa-8a6a-a74fc0f80b57",
    "request": {
        "type": "upscaler",
        "endpoint": "upscale_2x",
        "records": [
            {
                "_url": "https://images.ximilar.com/examples/fashion_products/01_1149810256_SI_00.jpeg"
            }
        ]
    },
    "type": "upscaler",
    "status": "CREATED",
    "created": "2022-03-02T13:38:22.784359Z",
    "workspace": "88431559-20ea-4d43-98a6-7a1cb38160e3"
}

Flows Requests

The required fields for request is flow identification and records.

For creating the asynchronous request you will need to call the API endpoint in following way:

curl --request POST \
  --url https://api.ximilar.com/account/v2/request \
  --header 'Authorization: Token __AUTH_TOKEN__' \
  --header 'Content-Type: application/json' \
  --data '{
    "type": "flows",
    "flow": "__ID__",
    "records": [
        {
            "_url": "__URL_PATH__"
        }
    ]
}'
from ximilar.client.asyncr import AsyncRClient
import time
client = AsyncRClient(__API_TOKEN__)
request, _ = client.submit({"records":[{"_url":"__URL_PATH__"}]}, "flows", flow="__FLOW_ID__")

time.sleep(10)
request.update()
print(request.response)
CLICK TO SHOW JSON RESULT

{
    "id": "2e9b43f2-61be-4aaa-8a6a-a74fc0f80b57",
    "request": {
        "flow": "__ID__",
        "records": [
            {
                "_url": "https://images.ximilar.com/examples/fashion_products/01_1149810256_SI_00.jpeg"
            }
        ]
    },
    "type": "flows",
    "status": "CREATED",
    "created": "2022-03-02T13:38:22.784359Z",
    "workspace": "88431559-20ea-4d43-98a6-7a1cb38160e3"
}