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

# Jobs and polling

> How long running work is started, polled and refunded.

Videos, snack packs, memes, carousels and transcriptions take minutes, not milliseconds. So the API does not make you wait. You start the work, get a job ID straight away, and check back until it is done.

## How it works

**1. Start the work**

A `POST`, like `POST /api/v1/snacks`, reserves the credits and returns `201` with a `jobId` and a `pollUrl`.

**2. Poll the job**

Call `GET /api/v1/jobs/{id}` every 5 to 10 seconds.

**3. Read the result**

Stop when `status` is `completed`, `failed` or `cancelled`. On `completed`, the output is in `result`.

```json Start response theme={null}
{
  "jobId": "6f1c...",
  "status": "queued",
  "pollUrl": "/api/v1/jobs/6f1c...",
  "creditsReserved": 25
}
```

`pollUrl` is a path. Put `https://www.vidguy.ai` in front of it.

> [!NOTE]
>
> A few endpoints have their own poll URL instead of the jobs endpoint, for example Studio and Seedance generations, AI Edit projects and dubs. The start response always tells you where to poll.

## Job states

| Status | What it means |
| - | - |
| `queued` | Accepted and waiting to start |
| `processing` | VidGuy is working on it |
| `awaiting_selection` | Waiting for you to pick an option before it can go on |
| `completed` | Done. Read `result` |
| `failed` | It did not work. Read `error`. Your credits come back |
| `cancelled` | You cancelled it. Your credits come back |
| `payment_required` | Transcriptions only. The audio ran longer than the credits reserved. Top up and poll again |

## Credits and refunds

* **Reserved up front.** The start call holds the credits in `creditsReserved`.
* **Settled at the end.** `creditsFinal` shows what you paid. On the first poll after `completed` it can still be `null`. The next poll shows the number.
* **Refunded on failure.** A failed job gives its credits back. You do not need to do anything.
* **Timeouts.** A snack job still not done after 15 minutes is marked `failed` and refunded. A TikTok carousel batch gets 10 minutes.

## Example in Node.js

```js theme={null}
const KEY = process.env.VIDGUY_API_KEY;
const BASE = "https://www.vidguy.ai";

const start = await fetch(`${BASE}/api/v1/snacks`, {
  method: "POST",
  headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ brandId: "YOUR_BRAND_ID" }),
}).then((r) => r.json());

while (true) {
  const job = await fetch(`${BASE}${start.pollUrl}`, {
    headers: { Authorization: `Bearer ${KEY}` },
  }).then((r) => r.json());

  if (job.status === "completed") { console.log(job.result); break; }
  if (job.status === "failed" || job.status === "cancelled") throw new Error(job.error);
  await new Promise((r) => setTimeout(r, 5000));
}
```

> [!WARNING]
>
> If a start call times out on your side, check `GET /api/v1/videos` or `GET /api/v1/snacks` before you send it again. A second `POST` starts a second job and spends credits twice.

Each poll counts toward your [rate limit](https://docs.vidguy.ai/api/rate-limits.md). Polling every 5 seconds uses 12 requests a minute.


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