> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Dapatkan Status Task

> Ambil status dan hasil dari task async apa pun menggunakan poll_url yang dikembalikan oleh endpoint create

## Gambaran Umum

Gunakan endpoint ini untuk polling async terpadu di berbagai jenis task seperti pembuatan video, gambar, musik, dan 3D.

Jika respons create menyertakan `poll_url`, panggil path tersebut secara persis. Untuk alur kerja async yang lebih baru, `poll_url` dapat mengarah ke `/v1/tasks/{id}`.

## Parameter Path

<ParamField path="id" type="string" required>
  ID task yang dikembalikan oleh permintaan create.
</ParamField>

## Respons

<ResponseField name="id" type="string">
  Pengidentifikasi task.
</ResponseField>

<ResponseField name="task_id" type="string">
  Alias pengenal tugas asinkron.
</ResponseField>

<ResponseField name="poll_url" type="string">
  URL polling yang diutamakan saat respons pembuatan menyediakannya.
</ResponseField>

<ResponseField name="status" type="string">
  Status task seperti `pending`, `processing`, `completed`, atau `failed`. Task yang dibatalkan direpresentasikan sebagai `failed` dengan `cancelled: true`.
</ResponseField>

<ResponseField name="cancelled" type="boolean">
  `true` ketika async task yang masih antre dibatalkan sebelum eksekusi.
</ResponseField>

<ResponseField name="cancellation_status" type="string">
  Penanda pembatalan. Ada sebagai `cancelled` ketika pembatalan berhasil.
</ResponseField>

<ResponseField name="data" type="array">
  Untuk task gambar yang selesai, hasil gambar yang dibuat dikembalikan di sini. Task gambar mengembalikan URL di `data[].url`.
</ResponseField>

<ResponseField name="progress" type="number">
  Nilai progres opsional. Hanya dikembalikan saat nilai progres nyata tersedia; gunakan `status` untuk menentukan penyelesaian.
</ResponseField>

<ResponseField name="video_url" type="string">
  URL aset hasil ketika task selesai dan menghasilkan video.
</ResponseField>

<ResponseField name="error" type="string">
  Pesan error ketika task gagal.
</ResponseField>

## Perilaku Error

Jika tugas sudah tidak ada, telah kedaluwarsa, atau tidak lagi tersedia di catatan tugas publik, TokenLab mengembalikan:

```json theme={null}
{
  "error": {
    "message": "Task not found or no longer available.",
    "type": "invalid_request_error",
    "code": "async_task_not_found"
  }
}
```

## Contoh

<RequestExample>
  ```bash cURL theme={null}
  curl "https://api.tokenlab.sh/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
    -H "Authorization: Bearer sk-your-api-key"
  ```
</RequestExample>

```python Python theme={null}
import requests

poll_url = "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
response = requests.get(
    f"https://api.tokenlab.sh{poll_url}",
    headers={"Authorization": "Bearer sk-your-api-key"},
)
print(response.json())
```

```javascript JavaScript theme={null}
const pollUrl = '/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const response = await fetch(`https://api.tokenlab.sh${pollUrl}`, {
  headers: { Authorization: 'Bearer sk-your-api-key' },
});
console.log(await response.json());
```
