<!-- https://bobabanana.com/docs/api/jobs/ · Every BobaBanana generation is an asynchronous job: statuses, the job object and its cost, long-polling, paging, canceling, deleting and idempotency keys. -->

# Jobs, status polling and long-polling

**Every generation request (`/v1/images`, `/v1/videos`, `/v1/speech`, `/v1/sound-effects`) returns `202 Accepted` with a job object straight away; the work happens in the background.** You find out it is done by polling, by long-polling with `?wait=30`, or with a [webhook](https://bobabanana.com/docs/api/webhooks/).

## Job statuses

| Status | Meaning | Final? |
|---|---|---|
| `queued` | Waiting its turn in the studio | no |
| `running` | At least one step is being made | no |
| `succeeded` | Finished; results are in `output` | yes |
| `failed` | Could not be made; see `error` | yes |
| `canceled` | Canceled by you | yes |

## The job object

```json
{
  "id": "x_8d21c0f4a9b3",
  "object": "job",
  "type": "video",
  "status": "running",
  "created": 1795660000,
  "finished": null,
  "eta_seconds": 380,
  "poll_after_seconds": 30,
  "input": {"prompt": "...", "duration_seconds": 5, "aspect_ratio": "9:16", "reference_images": [{"file_id": "file_a1", "label": "..."}]},
  "output": {},
  "error": null,
  "cost": {"credits_estimate": 30, "credits_charged": 0, "credits_released": 0, "status": "held"},
  "webhook": {"status": "pending", "attempts": 0, "last_status": null},
  "metadata": {"order_id": "1234"}
}
```

| Field | Description |
|---|---|
| `type` | `image`, `video`, `speech`, `sound_effect`, or `image_upscale` / `video_upscale` for an [upscale](https://bobabanana.com/docs/api/upscale/) (which also carries `source_job_id` and `output_size`) |
| `eta_seconds` | Estimated seconds until done, from recent measured job times (an estimate, not a promise) |
| `poll_after_seconds` | A sensible delay before polling again |
| `input` | The request as stored, with inline inputs replaced by their file IDs |
| `output` | `image`, `video`, `speech`, `sound_effect`: each `{"url", "content_type"}` |
| `error` | `{"code", "message", "steps"}` when failed or canceled |
| `warnings` | Present when a side step failed but the main result was made |
| `cost` | Credits reserved, charged and released for this job ([credits](https://bobabanana.com/docs/api/credits/)) |
| `webhook` | `{"status", "attempts", "last_status"}` when the job has a `webhook_url`, else `null` |

## Long-polling: the simplest way to wait

```bash
curl "https://bobabanana.com/api/v1/jobs/x_8d21c0f4a9b3?wait=30" -H "Authorization: Bearer $BOBABANANA_API_KEY"
```

The request returns as soon as the job reaches a final status, or after `wait` seconds (maximum 30) with the current state. Loop until the status is final. This is ideal for AI agents and scripts: no webhook server needed and no wasted polls.

## Other job endpoints

| Endpoint | Description |
|---|---|
| `GET /v1/jobs` | Newest first. Filters: `status`, `type`, `limit` (1-100), `before` (the `next_cursor` of the previous page) |
| `POST /v1/jobs/{id}/cancel` | Cancel a queued or running job; delivered steps are charged, the rest released |
| `DELETE /v1/jobs/{id}` | Delete a finished job and its result files. `409 job_active` while it is unfinished: cancel it first |
| `POST /v1/jobs/{id}/webhook/replay` | Send a finished job's webhook again ([webhooks](https://bobabanana.com/docs/api/webhooks/)) |

### Paging through jobs

A list returns `{"object": "list", "data": [...], "has_more": true, "next_cursor": "x_..."}`. Pass `next_cursor` as `?before=` to get the next page; filters apply to every page, so pages never skip or repeat a job. An unknown cursor gets `400 invalid_cursor`.

Deleting a job removes it from lists and frees its storage, but it still counts toward the key's daily limit, and what it was charged is not refunded.

## Idempotency keys: safe retries

Send an `Idempotency-Key` header (up to 255 characters) with any create request. If a network error makes you retry, the same key within 24 hours returns the original job instead of creating a duplicate.

| Situation | Result |
|---|---|
| Same key, same endpoint and body, first request finished | The original job |
| Same key while the first request is still being processed | `409 idempotency_in_progress`; retry after `Retry-After` |
| Same key with a different endpoint or body | `422 idempotency_key_reused`; use a new key |
| The first request failed (for example `402`) | The key is free again; the retry runs normally |

Keys are per API key: two keys may use the same value.

```bash
curl https://bobabanana.com/api/v1/images -H "Idempotency-Key: order-1234-hero" ...
```

## Best practices for waiting on jobs

1. **Prefer webhooks** for servers, **long-polling** for scripts and agents.
2. **Respect `poll_after_seconds`** if you poll without `wait`.
3. **Retry creates with an `Idempotency-Key`**, never blindly.
4. **Download results promptly**; links last 24 hours.
5. **Use `metadata`** to tie jobs to your own records.

## Frequently asked questions

### Why is my job still queued?
Jobs run in order in the BobaBanana studio. Check `eta_seconds` and `GET /v1/status`.

### Can I get partial results?
Yes. For a video with a generated first frame, `output.image` appears as soon as the frame is ready, before the video.

### What happens if a step fails?
If the main result cannot be made the job is `failed` with `error.steps` naming the step. If only a side step failed (for example a sound effect), the job succeeds with `warnings`.
