# How the BobaBanana API works: jobs, inputs, results and credits

Source: https://bobabanana.com/docs/api/concepts/

> How the BobaBanana API works: every create call is a job, inputs are files, URLs or base64, results are signed links, and credits are held then charged.

**Every BobaBanana create call (`POST /v1/images`, `/v1/videos`, `/v1/speech`, `/v1/sound-effects`, `/v1/jobs/{job_id}/upscale`) returns a job at once, and you collect the result when the job finishes.** This page is the mental model behind every other page: jobs, inputs, library handles, results, credits, retries and what a key can see.

**At a glance**

- **Base URL:** `https://bobabanana.com/api/v1`
- **Create calls:** answer `202 Accepted` with a [job](https://bobabanana.com/docs/api/reference/objects/#job)
- **Wait:** `GET /v1/jobs/{job_id}?wait=30`, or a [webhook](https://bobabanana.com/docs/api/webhooks/)
- **Inputs:** upload id, public `https://` URL, or base64 `data`
- **Results:** signed links in `output`, no key needed, at least 24 hours
- **Money:** credits, held when accepted, charged when delivered

## The model in five sentences

1. **A create call makes a job.** The answer is `202` with a job id; the work happens in the background.
2. **A job has steps.** A video may first make its picture, its speech and its sound, then the clip.
3. **Inputs are files you send** as an upload id, a URL or base64, or **library assets** by `@handle`.
4. **Results are signed links** in the job's `output`, which anyone with the link can download.
5. **Credits pay for it:** the estimate is held when the job is accepted, delivered steps are charged and the rest is released.

## Every generation is a job

A job moves through these states. Only the last three are final.

1. `queued`: accepted, waiting its turn in the studio.
2. `running`: at least one step is being made.
3. `succeeded`: finished; `output` holds the result links.
4. `failed`: it could not be made; `error.code` is `render_failed` and `error.message` says why.
5. `canceled`: you canceled it with `POST /v1/jobs/{job_id}/cancel`.

| Field | What it tells you |
|---|---|
| `status` | Where the job is: `queued`, `running`, `succeeded`, `failed`, `canceled` |
| `eta_seconds`, `poll_after_seconds` | Unfinished jobs: the estimated time left, and a good wait before the next poll |
| `output` | Result links by kind: `image`, `video`, `speech`, `sound_effect` |
| `cost` | Credits held, charged and released |
| `input` | What the job was made from; inline inputs are shown as the upload ids they became |
| `error` | Why a job failed or was canceled |

The full field list is in the [Job object](https://bobabanana.com/docs/api/reference/objects/#job); paging and canceling are in [Jobs](https://bobabanana.com/docs/api/jobs/).

## Three ways to send a file

| Form | Example | Best for |
|---|---|---|
| Upload id | `{"file_id": "file_3f9c2a1b7d4e"}` | A picture or recording used in many requests ([Files](https://bobabanana.com/docs/api/files/)) |
| Public URL | `{"url": "https://example.com/sofa.jpg"}` | Files already online; BobaBanana downloads them |
| Base64 | `{"data": "data:image/png;base64,..."}` | Small files, up to about 25 MB |

A plain string works too: `"file_..."` is an upload id, `"data:..."` is base64, anything else is a URL. Add a `label` to a reference (`"the red leather sofa"`) so the prompt can name it. Inputs are checked when the request arrives, so a bad file is refused with `400` before any credit is held.

## Library assets and @handles

A workspace's approved characters, objects, places, scenes and voices are usable by `@handle`, for example `"assets": ["@maya"]` or `"voice": "@storyteller"`. `GET /v1/assets` and `GET /v1/voices` list them. The API uses assets but cannot change them; they are made and approved in the studio. See [Assets](https://bobabanana.com/docs/api/assets/).

## Results and signed links

When a job succeeds, each result is a signed link such as `output.video.url`. A signed link:

1. needs no API key, so you can hand it to a browser, a player or another service;
2. works for at least 24 hours; fetch the job again for a fresh link;
3. is private: anyone with the link can download the file, so do not publish it unless you mean to.

Store results you want to keep. `DELETE /v1/jobs/{job_id}` deletes a job's results.

## Credits: hold, charge, release

1. **Accepted:** the job's estimate is held from your balance. Without enough credits the request gets `402 insufficient_credits` and nothing is made.
2. **Delivered:** each step is charged at the price it was held at, never more.
3. **Not delivered:** steps that fail or are canceled are released.

Price a request before sending it with `dry_run: true` (free, makes nothing), or cap it with `max_credits`. See [Credits](https://bobabanana.com/docs/api/credits/).

## Safe retries with idempotency keys

Send an `Idempotency-Key` header (a UUID) on every create call. If the connection drops and you retry with the same key and the same body within 24 hours, you get the first job back instead of a second one. The same key with a different body is `422 idempotency_key_reused`. Keys can be up to 255 characters.

## Polling, long-polling or webhooks

| Method | How | Use when |
|---|---|---|
| Long-poll | `GET /v1/jobs/{job_id}?wait=30` in a loop | Scripts and agents: one call per 30 seconds, answers as soon as the job finishes |
| Poll | `GET /v1/jobs/{job_id}` every `poll_after_seconds` | Simple clients that cannot hold a request open |
| Webhook | `webhook_url` in the create call | Servers with many jobs: BobaBanana POSTs a signed event when each job finishes |

## What a key and a workspace can see

1. A key belongs to one workspace and spends that workspace's credits.
2. **Jobs** are private to the key that made them; another key gets `404 job_not_found`.
3. **Uploads** are shared by every key of the workspace.
4. **Library assets and voices** of the workspace are usable by every key.
5. Ids from another workspace look exactly like ids that do not exist.

## Glossary

The [glossary](https://bobabanana.com/docs/api/glossary/) defines every term used here, for example [job](https://bobabanana.com/docs/api/glossary/#job), [hold](https://bobabanana.com/docs/api/glossary/#hold), [signed link](https://bobabanana.com/docs/api/glossary/#signed-link) and [idempotency key](https://bobabanana.com/docs/api/glossary/#idempotency-key).

## Frequently asked questions

### Why is every generation asynchronous?
Images, speech and especially videos take from seconds to minutes, longer than an HTTP request should stay open. A job lets you send many requests at once, follow each one, and collect results by long-poll or webhook.

### Does a request that is refused cost anything?
No. A request refused with any `4xx` or `5xx` makes no job and holds no credits. A job that fails later releases the credits of every step that was not delivered.

### Can I use a result as the input of the next job?
Yes. Download the result and upload it with `POST /v1/files`, or pass its signed link as a URL input while the link is valid. Upload ids are the most reliable choice for chains of jobs.

### What is the difference between a reference image and a start frame?
A reference image (`reference_images`) shows what to keep consistent, and a new picture is made from it. A start frame (`image` in `POST /v1/videos`) is animated as it is: it becomes the first frame of the video.
