# Creative Lab API overview

Source: [Creative Lab API overview](<https://docs.gptunnel.ru/en/creative-lab/>)

<a id="_top"></a>
Create image, video and audio tasks through a single Creative Lab API. The [model catalog](<https://docs.gptunnel.ru/en/creative-lab/models/>) lists each model’s result type, supported parameters and input file roles.

 <a id="opportunities"></a>
 
<a id="features"></a>
## Features

Use `POST /api/v2/media/tasks` to create a task for any model. The machine-readable schema from `GET /api/v2/media/models` describes model-specific parameters, so you can add models without changing the integration.

Additional features include a [price quote](<https://docs.gptunnel.ru/en/creative-lab/price/>) before generation (`POST /api/v2/media/price`), an idempotency key for safe retries, webhook delivery, and optional short synchronous waiting (`wait`).

<a id="base-url"></a>
## Base URL

```plaintext
https://gptunnel.ru/api/v2/media
```

Send your API key in the `Authorization` header with or without the `Bearer` prefix.

```plaintext
Authorization: YOUR_API_KEY
```

<a id="how-it-works"></a>
## How it works

1. (Optional) List models and their parameters with `GET /api/v2/media/models`.
2. (Optional) Get an estimate with `POST /api/v2/media/price`.
3. Create a task with `POST /api/v2/media/tasks`. The response contains a task object with its `id` and status.
4. Get the result using one of these options. 
   
   - Poll `GET /api/v2/media/tasks/:id` until the status is `done` or `failed`.
   - Pass `webhook_url` when creating the task. GPTunneL sends a notification when the task finishes.
   - Pass `wait: true` when creating the task. If the status is still `queued` or `running` after the wait, poll using the same `id`.

<a id="status-of-the-task"></a>
## Status of the task

| Status | Meaning |
| --- | --- |
| `queued` | Task accepted and waiting to run |
| `running` | Generation is in progress |
| `done` | Generation finished. See the links in `result`. |
| `failed` | Generation failed. See `error` for details. |

> **Caution: Save the result files**
>
> When the status is `done`, download the files 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.

<a id="what-happens-if-the-model-is-removed-from-service"></a>
## What happens if the model is removed from service?

If a retired model has a designated replacement, tasks run on the replacement at the originally requested model’s rate. Without a replacement, task creation returns `410` with `code: 21`. See the [model catalog](<https://docs.gptunnel.ru/en/creative-lab/models/>) for retirement dates and replacements, and [Deprecated models](<https://docs.gptunnel.ru/en/getting-started/deprecated-models/>) for how to detect a replacement.

<a id="sections"></a>
## Sections

- [Model catalog](<https://docs.gptunnel.ru/en/creative-lab/models/>) — `GET /media/models`
- [Calculation of price](<https://docs.gptunnel.ru/en/creative-lab/price/>) — `POST /media/price`
- [Creation of the task](<https://docs.gptunnel.ru/en/creative-lab/create-task/>) — `POST /media/tasks`
- [Getting a Task](<https://docs.gptunnel.ru/en/creative-lab/get-task/>) — `GET /media/tasks/:id`
- [Webhooks](<https://docs.gptunnel.ru/en/creative-lab/webhooks/>) — Delivering the result and verifying the signature
- [Error Directory](<https://docs.gptunnel.ru/en/creative-lab/errors/>)
