Skip to content

Download image

This document will introduce how to download the generated result image without using our SDK.

Task Object

The task object looks like it will be the following struct.

{
"id": "1749902216266450789",
"userId": "1541182147551506853",
"parameters": { ... },
"outputs": {
"duration": 1.26,
"detailParameters": {
// ...
},
"mediaId": "459602685899547043",
"extra": { ... }
},
"status": "completed",
"startedAt": "2024-05-22T06:16:57.124Z",
"endAt": "2024-05-22T06:16:59.422Z",
"createdAt": "2024-05-22T06:16:56.946Z",
"updatedAt": "2024-05-22T06:16:56.946Z",
}

When the status of the task is completed, task.outputs will have a value that contains the result. You can notice that there is a mediaId field in the outputs object. This mediaId is the ID of the generated image. For batch generation scenarios, the IDs of multiple images will be outputs.batch[].mediaId.

{
"id": "1749903535747486198",
"userId": "1541182147551506853",
"parameters": { ... },
"outputs": {
"duration": 4.83,
"detailParameters": { ... },
"mediaId": "459604021635814417",
"batch": [
{
"seed": 3283868009760115,
"mediaId": "459604023097100648",
"extra": { ... }
},
...
]
},
"status": "completed",
"startedAt": "2024-05-22T06:22:12.240Z",
"endAt": "2024-05-22T06:22:18.229Z",
"createdAt": "2024-05-22T06:22:11.557Z",
"updatedAt": "2024-05-22T06:22:11.557Z"
}

After obtaining the mediaId, you need to use our GraphQL API to obtain the specific image download link. You need to access the Query.media query and pass the mediaId as the parameter. And you should access the Media.urls field to get the download link.

query getMediaById($id: String!) {
media(id: $id) {
urls {
variant
url
}
}
}

The variant field in the Media.urls object is the type of the image. The url field is the download link of the image.

We will provide multiple variants of the image at the same time. If you want to access the original image after generation, you usually need to select the URL which variant is PUBLIC.

{
"data": {
"media": {
"urls": [
{
"variant": "PUBLIC",
"url": "..."
},
{
"variant": "THUMBNAIL",
"url": "..."
},
{
"variant": "STILL_THUMBNAIL",
"url": "..."
}
]
}
}
}

You can use a GraphQL batch query to fetch multiple images at once. The GraphQL query similar to belows.

query {
media(id: "459604023097100648") {
urls {
variant
url
}
}
media(id: "459604023097100649") {
urls {
variant
url
}
}
media(id: "459604023097100650") {
urls {
variant
url
}
}
}