# Get a media generation task

Source: [Get a media generation task](<https://docs.gptunnel.ru/en/creative-lab/get-task/>)

<a id="_top"></a>
> **Note: Authentication**
>
> You need an API key to send requests. See [Quick start](<https://docs.gptunnel.ru/en/>)

<a id="getting-a-task"></a>
## Getting a Task

`GET https://gptunnel.ru/api/v2/media/tasks/:id`

Returns the task by ID. Poll until the status is `done` or `failed`, or receive the result through a [webhook](<https://docs.gptunnel.ru/en/creative-lab/webhooks/>).

> **Note: Creative Lab Tasks Only**
>
> This endpoint returns tasks created through `POST /api/v2/media/tasks`. A task created through another API returns `404` with code `22` here. Read its result through the API that created it. For example, use `GET /v1/audio/transcriptions` for transcription.
>
>
>
> For tasks created with `POST /v1/faceswap/create`, call `GET /v1/faceswap/result?taskId=…`. When the status is `done`, `result` holds the image URL. GPTunneL saves new FaceSwap files under `temp/48h/` in temporary storage.

### Path parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Identifier from the creation response, 24 characters |

<a id="example-request"></a>
### Example request

Set `GPTUNNEL_API_KEY` to your API key and `TASK_ID` to the `id` field from the [task creation response](<https://docs.gptunnel.ru/en/creative-lab/create-task/>).

<a id="tab-panel-0-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

task_id = os.environ['TASK_ID']
url = f'https://gptunnel.ru/api/v2/media/tasks/{task_id}'
request = Request(url, headers={'Authorization': os.environ['GPTUNNEL_API_KEY']})
with urlopen(request, timeout=30) as response:
    print(json.load(response)['status'])
```

<a id="tab-panel-0-1"></a>
**cURL**

```bash
curl --fail-with-body "https://gptunnel.ru/api/v2/media/tasks/${TASK_ID:?Set TASK_ID}" \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}"
```

<a id="tab-panel-0-2"></a>
**JavaScript (Node.js)**

```javascript
const key = process.env.GPTUNNEL_API_KEY
if (!key) throw new Error('Set GPTUNNEL_API_KEY')
const id = process.env.TASK_ID
if (!id) throw new Error('Set TASK_ID')
const response = await fetch(`https://gptunnel.ru/api/v2/media/tasks/${encodeURIComponent(id)}`, { headers: { Authorization: key } })
if (!response.ok) throw new Error(await response.text())
const data = await response.json()
console.log(data.status)
```

 <a id="example-of-response-prepared"></a>
 
<a id="example-response-done"></a>
### Example response (done)

```json
{
  "code": 0,
  "id": "6a61e021a6e77553a989c41d",
  "model": "kling-v3",
  "status": "done",
  "prompt": "a red fox running through snow, cinematic",
  "params": { "resolution": "1080p", "duration": 5, "aspect_ratio": "16:9" },
  "price": 210,
  "result": [
    { "url": "https://cdn.gptunnel.com/predication/6a61e021a6e77553a989c41d_result.mp4" }
  ],
  "created_at": 1784799265
}
```

<a id="example-of-response-music-multiple-tracks"></a>
### Example of response (music, multiple tracks)

```json
{
  "code": 0,
  "id": "6a61e021a6e77553a989c41e",
  "model": "suno",
  "status": "done",
  "prompt": "lo-fi beat for late night coding",
  "price": 16.8,
  "result": [
    {
      "url": "https://cdn.gptunnel.com/suno/..._1.mp3",
      "id": "9f2c1b7a-...",
      "cover_url": "https://cdn.gptunnel.com/suno/..._1.jpg",
      "duration": 128,
      "title": "Late Night Compile",
      "lyric": "[Verse]\n...",
      "tags": "lo-fi, mellow, rainy"
    },
    {
      "url": "https://cdn.gptunnel.com/suno/..._2.mp3",
      "id": "4d81ea03-...",
      "cover_url": "https://cdn.gptunnel.com/suno/..._2.jpg",
      "duration": 131,
      "title": "Late Night Compile",
      "tags": "lo-fi, mellow, rainy"
    }
  ],
  "created_at": 1784799265
}
```

Suno returns two tracks for each task in `result`. The `id` field identifies each track at the provider.

<a id="example-of-response-failure"></a>
### Example of response (failure)

```json
{
  "code": 0,
  "id": "6a61e021a6e77553a989c41d",
  "model": "kling-v3",
  "status": "failed",
  "error": { "code": 1001, "title": "SENSITIVE_CONTENT", "message": "Sensitive content has been detected in your request or uploaded files. Please check the text and media and try again." },
  "result": [],
  "created_at": 1784799265
}
```

<a id="fields-of-task-object"></a>
### Fields of task object

| Parameter | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Task Identifier |
| `model` | `string` | ID of the requested model. If a retired model was replaced, this remains the ID you originally sent. The x-model-served header in the task creation response identifies the model that ran it. |
| `status` (required) | `string` | queued \| running \| done \| failed |
| `params` | `object` | Generation parameters applied to the task |
| `price` | `number` | Amount charged in rubles |
| `result` (required) | `array` | Array of results when status is done. Otherwise it is empty. Each item has a url. Models that produce multiple files return items in the order they become available. Music items also include id, cover\_url, duration, title, lyric and tags. |
| `error` | `object` | Failure details when status is failed. Use code as a stable value when handling failures. The title field gives a machine-readable reason that can be more specific than code. The message field is a human-readable description. |
| `webhook` | `object` | Present if the creation request included webhook\_url. The url field is the recipient URL. The status is pending, delivered, or failed. |
| `trace_id` | `string` | Trace ID, if available. Include it with the task id when contacting support. |
| `created_at` | `number` | Time of creation (Unix, seconds) |

> **Caution: Save the result files**
>
> When the status is `done`, download the files you need from `result` and save them to your own storage.
>
>
>
> The scheduled retention period for temporary GPTunneL files under `temp/48h/` is 48 hours from when they are saved. Fetching the result again does not extend this period. Older and external links may have different lifetimes.
