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

# Tasks and waiting

> How a generation moves from submitted to completed, and how to wait for it without a polling loop.

Every generation is a task with an id like `task_0a17552fb8dbea3a74bc42048e5212e1`.

## Status

| Status | Meaning |
| - | - |
| `submitted` | Returned by the create call when you did not ask to wait |
| `pending` | Accepted, not started yet |
| `processing` | The model is running |
| `completed` | Finished. `result` holds the output link |
| `failed` | Ended without a result. `error` says why, and nothing was charged |

## Waiting without a loop

Add `?wait=<seconds>` to the create call or to `GET /v1/tasks/{id}`. The service holds the call open until the task finishes or the time runs out, up to 60 seconds, and then returns the task as it stands.

```bash theme={null}
# Create and wait in one call
curl -sS 'https://one-api.ai/v1/images/generations?wait=30' \
  -H "Authorization: Bearer $ONE_API_TOKEN" \
  -d '{"model":"z-image-turbo","prompt":"a lighthouse at dusk"}'

# Wait on an existing task
curl -sS "https://one-api.ai/v1/tasks/$TASK_ID?wait=60" \
  -H "Authorization: Bearer $ONE_API_TOKEN"
```

The header `Prefer: wait=30` does the same as the query parameter.

For a video that takes several minutes, repeat the status call with `?wait=60` until `status` is `completed` or `failed`. Each call returns as soon as the task finishes, so there is no delay to tune.

```bash theme={null}
while :; do
  task=$(curl -sS "https://one-api.ai/v1/tasks/$TASK_ID?wait=60" -H "Authorization: Bearer $ONE_API_TOKEN")
  status=$(echo "$task" | jq -r .data.status)
  [ "$status" = completed ] || [ "$status" = failed ] && break
done
echo "$task" | jq .data
```

The [command-line tool](https://docs.one-api.ai/cli.md) runs this loop for you.

## The task object

```json theme={null}
{
  "id": "task_30f89ae89b9343f0f383d66cbf708b69",
  "status": "completed",
  "type": "video",
  "model": "p-video",
  "cost": 0.005473684,
  "credits_cost": 5.473684,
  "created": 1795787621,
  "completed": 1795787657,
  "actual_time": 36,
  "result": { "videos": [{ "url": ["https://…"] }] }
}
```

| Field | Notes |
| - | - |
| `type` | `image` or `video` |
| `cost` | Price in US dollars. `0` for a failed task |
| `credits_cost` | The same price in credits. One credit is \$0.001 |
| `created`, `completed` | Unix time in seconds |
| `actual_time` | Seconds from creation to the end |
| `result` | Present when completed: `images` or `videos`, each with a `url` list |
| `error` | Present when failed: `code` is `generation_failed` or `timed_out` |

## Output links

The link in `result` is a temporary signed link to the file. Download the file soon after the task completes and keep your own copy. Do not store the link as a permanent address.

## Listing tasks

`GET /v1/tasks` returns your 20 most recent tasks, newest first.

## What is not kept

The prompt is removed from the task record as soon as the task ends.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.