# `POST /v1/images`: create an image job

Source: https://bobabanana.com/docs/api/reference/create-image/

> POST /v1/images: create an image job. Parameters, body fields, example request and response, and errors. BobaBanana API reference with curl, Python and...

**`POST /v1/images` is the endpoint to create an image job.** Makes one image from `prompt` and up to 10 reference pictures (`reference_images`, `assets`). Label each reference so the prompt can name it. Answers 202 with a queued job; wait with `GET /v1/jobs/{job_id}?wait=30`. With `dry_run: true` it answers 200 with the price and makes nothing.

**At a glance**

- **Endpoint:** `POST /v1/images`
- **Base URL:** `https://bobabanana.com/api/v1`
- **Auth:** `Authorization: Bearer bb_...`
- **Success:** `202` (or `200` with `dry_run: true`)
- **Safe to retry:** yes, with an `Idempotency-Key` header
- **Guide:** [Images](https://bobabanana.com/docs/api/images/)

## Request

### Headers

| Header | Required | Description |
|---|---|---|
| `Authorization` | yes | `Bearer bb_...`: your API key (or send `X-API-Key: bb_...`) |
| `Content-Type` | yes | `application/json` |
| `idempotency-key` | no | Any unique string up to 255 characters (a UUID is ideal). A retry with the same key and the same body within 24 hours returns the first job instead of making a second one; the same key with a different body is 422 idempotency_key_reused. |

### Body (JSON)



| Field | Type | Required | Default | Limits | Description |
|---|---|---|---|---|---|
| `webhook_url` | string | no |  | 0 to 500 characters | https:// URL that receives a signed POST when the job finishes |
| `metadata` | object of string | no |  | at most 16 keys | Up to 16 keys (40 characters each) with string values (500 characters each), echoed back on the job and its webhook |
| `name` | string | no |  | 0 to 80 characters | Label shown in the BobaBanana studio |
| `max_credits` | integer | no |  | at least 0 | Refuse the job (400 cost_above_max, nothing held) if it would cost more than this |
| `dry_run` | boolean | no | `false` |  | true: answer 200 with what the job would cost (credits_estimate) and make nothing: nothing is queued, held or stored, and no Idempotency-Key is used |
| `prompt` | string | yes |  | 1 to 1500 characters | What to create |
| `reference_images` | list of string or [Media](https://bobabanana.com/docs/api/reference/objects/#media) | no |  | at most 10 items | Up to 10 pictures to keep consistent: characters, products, places, styles |
| `assets` | list of string | no |  | at most 10 items | Approved library assets by handle, e.g. ['@maya', '@red_sofa'] |
| `aspect_ratio` | one of `16:9`, `9:16`, `1:1`, `4:3`, `3:4` | no | `"16:9"` |  |  |

## Example request

One product in a new scene:

```bash
curl https://bobabanana.com/api/v1/images \
  -H "Authorization: Bearer $BOBABANANA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "prompt": "the sofa in a sunlit loft, morning light, wide shot",
    "reference_images": [
      {
        "url": "https://example.com/sofa.jpg",
        "label": "a mustard yellow three-seat sofa"
      }
    ],
    "aspect_ratio": "16:9"
  }'
```

```python
import os
import uuid

import requests

r = requests.post(
    "https://bobabanana.com/api/v1/images",
    headers={"Authorization": f"Bearer {os.environ['BOBABANANA_API_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
        "prompt": "the sofa in a sunlit loft, morning light, wide shot",
        "reference_images": [
            {
                "url": "https://example.com/sofa.jpg",
                "label": "a mustard yellow three-seat sofa",
            },
        ],
        "aspect_ratio": "16:9",
    },
    timeout=60,
)
r.raise_for_status()
print(r.json())
```

```javascript
const res = await fetch("https://bobabanana.com/api/v1/images", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.BOBABANANA_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    "prompt": "the sofa in a sunlit loft, morning light, wide shot",
    "reference_images": [
      {
        "url": "https://example.com/sofa.jpg",
        "label": "a mustard yellow three-seat sofa"
      }
    ],
    "aspect_ratio": "16:9"
  }),
});
if (!res.ok) throw new Error(JSON.stringify(await res.json()));
console.log(await res.json());
```

### More request bodies


**Several labelled references** (`multi_reference`):

```json
{
  "prompt": "the woman sits on the sofa reading, cosy evening light",
  "reference_images": [
    {
      "url": "https://example.com/maya.jpg",
      "label": "Maya, a woman with short red hair"
    },
    {
      "file_id": "file_3f9c2a1b7d4e",
      "label": "a mustard yellow three-seat sofa"
    }
  ],
  "aspect_ratio": "4:3",
  "max_credits": 20
}
```

**Library assets by @handle** (`handles`):

```json
{
  "prompt": "@maya and @captain_fox share a picnic in a meadow",
  "assets": [
    "@maya",
    "@captain_fox"
  ],
  "aspect_ratio": "16:9",
  "webhook_url": "https://example.com/hooks/bobabanana",
  "metadata": {
    "order": "1234"
  }
}
```

**Text only, no references** (`text_only`):

```json
{
  "prompt": "a lighthouse on a cliff at dusk, oil painting",
  "aspect_ratio": "1:1"
}
```

**Price it first, make nothing** (`dry_run`):

```json
{
  "prompt": "the sofa in a sunlit loft",
  "reference_images": [
    {
      "url": "https://example.com/sofa.jpg"
    }
  ],
  "dry_run": true
}
```

## Response

**200** ([DryRunEstimate](https://bobabanana.com/docs/api/reference/objects/#dry-run-estimate)): dry_run: true: the price of this request. Nothing is queued, held or stored.

```json
{
  "object": "estimate",
  "dry_run": true,
  "type": "image",
  "credits_estimate": 4,
  "credits_available": 950,
  "enough_credits": true,
  "billing_mode": "credits"
}
```

**202** ([Job](https://bobabanana.com/docs/api/reference/objects/#job)): Successful Response

```json
{
  "id": "x_8d21c0f4a9b3",
  "object": "job",
  "type": "image",
  "status": "queued",
  "created": 1764950400,
  "input": {
    "reference_images": [
      {
        "file_id": "file_3f9c2a1b7d4e",
        "label": "a mustard yellow three-seat sofa"
      }
    ],
    "assets": [],
    "prompt": "the sofa in a sunlit loft, morning light, wide shot",
    "aspect_ratio": "16:9"
  },
  "output": {},
  "eta_seconds": 60,
  "poll_after_seconds": 15,
  "cost": {
    "credits_estimate": 4,
    "credits_charged": 0,
    "credits_released": 0,
    "status": "held"
  }
}
```

## Errors

Errors use the [error object](https://bobabanana.com/docs/api/reference/objects/#error). The codes this endpoint can return (what to do about each is in [Error codes](https://bobabanana.com/docs/api/errors/)):

| Status | Code | Meaning |
|---|---|---|
| 400 | [`bad_request`](https://bobabanana.com/docs/api/errors/#bad_request) | The `Content-Length` header is not a number. |
| 400 | [`cost_above_max`](https://bobabanana.com/docs/api/errors/#cost_above_max) | The job would cost more than `max_credits`. `credits_estimate` gives the price. |
| 400 | [`fetch_failed`](https://bobabanana.com/docs/api/errors/#fetch_failed) | Downloading a URL input failed or returned an HTTP error. |
| 400 | [`fetch_timeout`](https://bobabanana.com/docs/api/errors/#fetch_timeout) | Downloading a URL input took too long. |
| 400 | [`file_too_large`](https://bobabanana.com/docs/api/errors/#file_too_large) | A file or inline data is over its size limit. |
| 400 | [`invalid_base64`](https://bobabanana.com/docs/api/errors/#invalid_base64) | `data` is not valid base64. |
| 400 | [`invalid_image`](https://bobabanana.com/docs/api/errors/#invalid_image) | The image could not be opened, or it has too many pixels. |
| 400 | [`invalid_metadata`](https://bobabanana.com/docs/api/errors/#invalid_metadata) | `metadata` has more than 16 keys, a key over 40 characters or a value over 500. |
| 400 | [`invalid_request`](https://bobabanana.com/docs/api/errors/#invalid_request) | A field is missing, has the wrong type or breaks a rule. `param` names the field. Type and range problems found while reading the body are 422 with the same code. |
| 400 | [`invalid_url`](https://bobabanana.com/docs/api/errors/#invalid_url) | The URL is not `https://`, its host cannot be found, or it points to a private address. |
| 400 | [`too_many_references`](https://bobabanana.com/docs/api/errors/#too_many_references) | More than 10 reference pictures in total (a character asset counts as two). |
| 400 | [`unsupported_file`](https://bobabanana.com/docs/api/errors/#unsupported_file) | The file is not a supported image, audio or video format. |
| 400 | [`wrong_asset_kind`](https://bobabanana.com/docs/api/errors/#wrong_asset_kind) | The asset is the wrong kind for this field (for example a voice used as a picture). |
| 400 | [`wrong_file_type`](https://bobabanana.com/docs/api/errors/#wrong_file_type) | An image was given where audio is needed, or the other way round. |
| 401 | [`invalid_api_key`](https://bobabanana.com/docs/api/errors/#invalid_api_key) | The key is wrong, revoked or belongs to no workspace. |
| 401 | [`missing_api_key`](https://bobabanana.com/docs/api/errors/#missing_api_key) | No API key was sent. |
| 402 | [`insufficient_credits`](https://bobabanana.com/docs/api/errors/#insufficient_credits) | The workspace's available credits are less than the job's estimate. `required` and `available` give both numbers. |
| 403 | [`workspace_suspended`](https://bobabanana.com/docs/api/errors/#workspace_suspended) | The workspace that owns the key is suspended. |
| 404 | [`asset_not_found`](https://bobabanana.com/docs/api/errors/#asset_not_found) | No approved library asset with this @handle or id. |
| 404 | [`file_not_found`](https://bobabanana.com/docs/api/errors/#file_not_found) | No live upload with this id in the workspace (expired or deleted). |
| 409 | [`asset_not_ready`](https://bobabanana.com/docs/api/errors/#asset_not_ready) | The asset has no approved version yet. |
| 409 | [`idempotency_in_progress`](https://bobabanana.com/docs/api/errors/#idempotency_in_progress) | A request with this `Idempotency-Key` is still being processed. `Retry-After`: 5 s. |
| 413 | [`too_large`](https://bobabanana.com/docs/api/errors/#too_large) | The request body is over the limit for this endpoint (JSON bodies 100 MB, uploads 64 MB). |
| 422 | [`idempotency_key_reused`](https://bobabanana.com/docs/api/errors/#idempotency_key_reused) | This `Idempotency-Key` was already used with a different request. |
| 422 | [`invalid_json`](https://bobabanana.com/docs/api/errors/#invalid_json) | The body is not valid JSON. |
| 429 | [`daily_limit_reached`](https://bobabanana.com/docs/api/errors/#daily_limit_reached) | This key has used its jobs for the last 24 hours. `Retry-After`: 3600 s. |
| 429 | [`network_busy`](https://bobabanana.com/docs/api/errors/#network_busy) | Every download slot is busy. `Retry-After`: 5 s. |
| 429 | [`queue_full`](https://bobabanana.com/docs/api/errors/#queue_full) | The workspace has too many steps waiting. |
| 429 | [`too_many_active_jobs`](https://bobabanana.com/docs/api/errors/#too_many_active_jobs) | This key already has its maximum of unfinished jobs. `Retry-After`: 30 s. |
| 429 | [`too_many_attempts`](https://bobabanana.com/docs/api/errors/#too_many_attempts) | Too many requests with wrong keys came from your address. `Retry-After` is set. |
| 429 | [`too_many_downloads`](https://bobabanana.com/docs/api/errors/#too_many_downloads) | Two URL inputs are already being downloaded for this workspace. `Retry-After`: 10 s. |
| 500 | [`internal_error`](https://bobabanana.com/docs/api/errors/#internal_error) | Something went wrong on our side. |
| 503 | [`engine_unavailable`](https://bobabanana.com/docs/api/errors/#engine_unavailable) | This kind of generation is not available right now. `Retry-After`: 300 s. |
| 503 | [`maintenance`](https://bobabanana.com/docs/api/errors/#maintenance) | BobaBanana is being updated; changes are paused for a few minutes. Reads still work. `Retry-After` is set. |
| 507 | [`storage_quota_exceeded`](https://bobabanana.com/docs/api/errors/#storage_quota_exceeded) | The workspace has used its storage. |

## Related

- Guide: [Images](https://bobabanana.com/docs/api/images/)
- [All endpoints](https://bobabanana.com/docs/api/reference/)
- [Objects](https://bobabanana.com/docs/api/reference/objects/)
- [Error codes](https://bobabanana.com/docs/api/errors/)
