<!-- https://bobabanana.com/docs/api/upscale/ · Upscale a finished BobaBanana image or video job: images at 2x or 4x, videos at 2x, 2.25x (480p to 1080p) or 4x with sound kept. Prices, limits. -->

# Upscale images and videos

**Any finished image or video job can be upscaled into a sharper, larger version with `POST /v1/jobs/{job_id}/upscale`.** The result is a new job of type `image_upscale` or `video_upscale` whose `source_job_id` names the original; the original job is never changed. A video keeps its own sound, frames and frame rate.

## Sizes

| Source | Factors | Example | Largest result |
|---|---|---|---|
| Image job | `2`, `4` | 1024 × 1024 → 2048 × 2048 (2x) or 4096 × 4096 (4x) | 4096 px on the long side, 16.8 megapixels |
| Video job | `2`, `2.25`, `4` | 832 × 480 → 1664 × 960 (2x) or 1872 × 1080 (2.25x, HD); 4x for small clips, e.g. 480 × 270 → 1920 × 1080 | 3 megapixels per frame (for example 2304 × 1296); clips up to 15 s, up to 30 frames a second |

A factor that would go past these limits is refused with `400 invalid_request` and a reason. [`GET /v1/jobs/{job_id}/upscale-options`](#check-the-options-first) tells you in advance which factors a job allows and what each costs.

## Check the options first

```bash
curl https://bobabanana.com/api/v1/jobs/x_8d21c0f4a9b3/upscale-options \
  -H "Authorization: Bearer $BOBABANANA_API_KEY"
```

```json
{
  "object": "upscale_options",
  "job_id": "x_8d21c0f4a9b3",
  "media": "video",
  "width": 832,
  "height": 480,
  "seconds": 5.0,
  "available": true,
  "reason": "",
  "notice": "",
  "estimate_seconds": 330,
  "options": [
    {"factor": 2.0, "available": true, "reason": "", "width": 1664, "height": 960, "credits": 60},
    {"factor": 2.25, "available": true, "reason": "", "width": 1872, "height": 1080, "credits": 60},
    {"factor": 4.0, "available": true, "reason": "", "width": 3328, "height": 1920, "credits": 150}
  ]
}
```

## Upscale a job

```bash
curl -X POST https://bobabanana.com/api/v1/jobs/x_8d21c0f4a9b3/upscale \
  -H "Authorization: Bearer $BOBABANANA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: upscale-x_8d21c0f4a9b3-2.25" \
  -d '{"factor": 2.25, "max_credits": 60, "webhook_url": "https://example.com/hooks/bobabanana"}'
```

The answer is `202 Accepted` with the new job:

```json
{
  "id": "x_51f0aa93c2d7",
  "object": "job",
  "type": "video_upscale",
  "status": "queued",
  "source_job_id": "x_8d21c0f4a9b3",
  "output_size": {"width": 1872, "height": 1080},
  "input": {"source_job_id": "x_8d21c0f4a9b3", "factor": 2.25},
  "output": {},
  "cost": {"credits_estimate": 60, "credits_charged": 0, "credits_released": 0, "status": "held"}
}
```

Poll it with [`GET /v1/jobs/{id}`](https://bobabanana.com/docs/api/jobs/) or wait for its [webhook](https://bobabanana.com/docs/api/webhooks/). When it succeeds, `output.image` (PNG) or `output.video` (MP4 with the original sound) holds the result.

| Body field | Type | Notes |
|---|---|---|
| `factor` | number | `2` or `4` for an image job; `2`, `2.25` or `4` for a video job. Default `2` |
| `max_credits` | integer | Refuse (`400 cost_above_max`) if the upscale would cost more |
| `webhook_url` | string | `https://` URL for the signed result notification |
| `metadata` | object | Up to 16 string keys echoed back on the job |
| `name` | string | Label shown in the studio |

The `Idempotency-Key` header works as for every create request.

## When upscaling cannot start yet

Upscaling is sometimes not available straight away. The job is still accepted and held its price; it starts as soon as it can, and until then it carries a `notice`: `"Upscale isn't available right now. Your upscale will start as soon as it can."` `estimate_seconds` on the options includes that start-up time. You can [cancel](https://bobabanana.com/docs/api/jobs/) a waiting job at no cost.

## Prices

| Price key | What | Credits |
|---|---|---|
| `upscale_image` | One image at 2x or 4x | 30 |
| `upscale_video` | A video whose upscaled frame is at most 2.2 megapixels (HD, e.g. 2x or 2.25x of 480p) | 30 + 6 per second |
| `upscale_video_4k` | A larger video result (e.g. 4x of 480p, or 2x / 2.25x of 720p) | 30 + 24 per second |

Seconds are counted per started second of the source clip. The credits are held when the job is accepted, charged when it succeeds and given back in full when it fails or is canceled. [`GET /v1/prices`](https://bobabanana.com/docs/api/credits/) always shows the prices in force.

## Errors

| Status | Code | When |
|---|---|---|
| 400 | `invalid_request` | The job is not finished, is not an image or video, the factor is not allowed for it, the video is longer than 15 s, or your workspace has not switched on "Make work quickly at busy times" (the message names what to change) |
| 400 | `cost_above_max` | The upscale costs more than `max_credits` |
| 402 | `insufficient_credits` | Not enough credits for the hold |
| 404 | `job_not_found` | No such job for this API key |

See [Errors](https://bobabanana.com/docs/api/errors/) for the error object.
