# Asynchronous Inference

Asynchronous inference is the recommended way to call media models. You submit a request to a persistent queue, then retrieve results later by polling for status.&#x20;

The async approach gives you full control over the request lifecycle. You can submit many requests in parallel and process them as they complete, get real-time visibility into queue position and runner logs, and rely on automatic retries when failures occur.&#x20;

### Submit a Request

Submit generation tasks to via API.

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

```python
import http.client
import json

conn = http.client.HTTPSConnection("image.onerouter.pro")
payload = json.dumps({
   "model": "bytedance/seedance",
   "content": [
      {
         "type": "text",
         "text": "A little kitten walks along the seaside."
      }
   ],
   "generate_audio": True,
   "tools": [
      {
         "type": "web_search"
      }
   ],
   "resolution": "720p",
   "ratio": "adaptive",
   "duration": 5,
   "watermark": False
})
headers = {
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1/images/generations", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --location --request POST 'https://image.onerouter.pro/v1/images/generations' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "bytedance/seedance",
    "content": [
      {
        "type": "text",
        "text": "A little kitten walks along the seaside."
      }
    ],
    "generate_audio": true,
    "tools": [
      {
        "type": "web_search"
      }
    ],
    "resolution": "720p",
    "ratio": "adaptive",
    "duration": 5,
    "watermark": false
}'
```

{% endtab %}
{% endtabs %}

Response format

```json
{
        "code": 200,
        "message": "success",
        "data": {
            "task_id": "cgt-20260312231129-7db6s",
            "object": "video",
            "model": "bytedance/seedance",
            "status": "created|in_progress|processing|completed|failed",
            "urls": {
                "get": "https://video.onerouter.pro/v1/videos/tasks/cgt-20260312231129-7db6s"
            },
        "created_at": "2024-01-01 12:00:00.00"
}
```

### Get the Result

Retrieve results from completed tasks.

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

```python
import http.client

conn = http.client.HTTPSConnection("video.onerouter.pro")
payload = ''
headers = {
   'Authorization': 'YOUR-API-KEY'
}
conn.request("GET", "/v1/videos/tasks/{task_id}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --location --request GET 'https://video.onerouter.pro/v1/videos/tasks/{task_id}' \
--header 'Authorization: sk-3c6klPYlaBYG3cboXrEWQFuGZSDDu3kCcyBRjkl10Er8arRt'
```

{% endtab %}
{% endtabs %}

Response format

```json
{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "cgt-20260312231129-7db6s",
    "object": "video",
    "model": "bytedance/seedance",
    "status": "created|in_progress|processing|completed|failed",
    "fail_reason": "",
    "submit_time": 1773318919,
    "start_time": 1773318925,
    "finish_time": 1773319107,
    "outputs": [
      "https://storage.googleapis.com/infron_gcs/video%2Fvideo%2Fcgt-20260328120757-nw49t_69c65308.mp4"
    ],
    "created_at": "2024-01-01 12:00:00"
  }
}

```
