Outpaint Image
Extend an image to a new aspect ratio by painting around it, at a fixed price per task.
Outpaint Image (product outpaint_image) extends an image to a new aspect ratio: the original is scaled down into the middle of the frame and everything around it is painted in, rather than a strip added along the edges. One task makes one image, at a fixed price per task.
Create a task
https://api.nanoapi.ai/v1/tasksUse the shared create endpoint with model: "outpaint-image". It usually responds in under 1 second, and the price is frozen within a few seconds. Get the result once the task has finished.
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <API key>, see Authentication. |
Content-Type | Yes | application/json |
Idempotency-Key | No | A unique string for every new task, ideally a UUID (1–255 characters). See Preventing duplicate tasks. |
Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | outpaint-image. |
image_url | string | Yes | The original image. See Media. |
aspect_ratio | string | Yes | auto, 1:1, 3:2, 2:3, 4:3, 3:4, 4:5, 5:4, 9:16, 16:9 or 21:9. auto picks the one of the other ten closest to the original's ratio; the original still ends up a little smaller in the frame, with new content around it. |
webhook_url | string | No | Notified when the task succeeds or fails: https, up to 2048 characters, not a private, loopback or reserved address. See Webhooks. |
Extend a room photo to 16:9:
curl https://api.nanoapi.ai/v1/tasks \
-H "Authorization: Bearer $NANOAPI_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7a2f4c9e-1d6b-4b3a-8e5f-0c9d3a6b2e71" \
-d '{
"model": "outpaint-image",
"image_url": "https://example.com/room.jpg",
"aspect_ratio": "16:9"
}'Response: 200 OK. data is the newly created task, with only these fields; each one is described in Create a task: Response. Keep data.id to get the result. The task can still fail after it's created (for example if your balance can't cover it), so go by what retrieving the task or the webhook tells you.
{
"code": 200,
"message": "success",
"data": {
"object": "task",
"id": "tk_01jbm4c6e9g2j5k8q1t4w7y0a3",
"model": "outpaint-image",
"status": "queued",
"error": null,
"created_at": "2026-11-03T08:30:00Z"
}
}Get the result
Measured from creation to the end: about 1–1.5 minutes, slower when the generation service is busy. Once the task has finished (succeeded or failed), get the result either way:
- Webhook (recommended in production): if you passed
webhook_url, the full task is pushed to it once when the task finishes. See Webhooks. - Polling: call
GET /v1/tasks/{task_id}withdata.idat most once every 15 seconds untilstatusissucceededorfailed. Check several tasks at once withidsin List tasks.
The request above, once it has succeeded (other fields left out):
{
"status": "succeeded",
"input": {
"image_url": "https://example.com/room.jpg",
"aspect_ratio": "16:9"
},
"num_outputs": 1,
"outputs": [
{
"index": 0,
"type": "image",
"url": "https://cdn.nanoapi.ai/h/tk_01jbm4c6e9g2j5k8q1t4w7y0a3_1_1793694600.png",
"preview_url": "https://cdn.nanoapi.ai/h/tk_01jbm4c6e9g2j5k8q1t4w7y0a3_1_1793694600_compressed.jpg"
}
],
"billing": {
"currency": "USD",
"frozen": "…", // the price per task
"charged": "…", // the same
"refunded": "0.00",
"billed_seconds": null
}
}| Field | Outpaint Image |
|---|---|
outputs | One item. |
outputs[0].type | image. |
outputs[0].url | The extended image, a PNG, for downloading. Its size is set by the generation service, for example 2752×1536 for 16:9. |
outputs[0].preview_url | A JPEG preview at most 1024 pixels on the long side, for display. null if it couldn't be made. |
billing.billed_seconds | Always null: billed per task. |
input | The parameters you sent. |
On failure the frozen amount is returned in full and the reason is in data.error.type, see Errors. Every field is described in The task object.
Media
The image is passed as a public http(s) URL in image_url. There's no upload endpoint: host the file yourself. URLs are at most 4096 characters, must download directly and can't point to localhost or private, loopback or reserved addresses.
The image is read only when generation runs, after the price was frozen: if it can't be downloaded, isn't an image or can't be opened, the task fails with invalid_media and the frozen amount is returned in full. Keep the link reachable until the task finishes, including links that expire.
Pricing
cost = price per taskLoading the current prices…
aspect_ratioand the size of the original don't change the price.- It's frozen within a few seconds of creating the task and charged when the task succeeds; when the task fails, all of it is returned. How freezing and charging work in general: Billing.
Read the current price from GET /v1/products (the outpaint_image product has one prices row, billing_unit task). Prices change, so don't hard-code them; billing.frozen on the retrieved task is what counts.
Errors
Errors and failure reasons specific to this model. Every error of the create endpoint: Create a task → Errors; every failure reason: Failure reasons.
Create request errors: the request fails with an HTTP error and no task is created. param names the parameter.
| Status | error.type | When | What to do |
|---|---|---|---|
400 | invalid_request | image_url or aspect_ratio is missing (Field required, param names it). | Send both. |
400 | invalid_request | aspect_ratio isn't one of the values above (Input should be 'auto', '1:1', '3:2', '2:3', '4:3', '3:4', '4:5', '5:4', '9:16', '16:9' or '21:9' for outpaint-image), image_url isn't a public http(s) URL of at most 4096 characters, or num_outputs isn't 1. | Fix the parameter param names. |
400 | invalid_request | A parameter this model doesn't take, such as prompt (Extra inputs are not permitted). | Remove it. |
Other errors of the create endpoint (401, 402, 429 and so on): Create a task → Errors.
Task failures: the create request succeeded (200) and the task later turned failed. There's no HTTP status: the reason is the task's error.type, from retrieving the task or the webhook.
error.type | When | What to do |
|---|---|---|
insufficient_balance | Your available balance can't cover the price per task. Within a few seconds of creating the task, nothing frozen. | Top up, then create the task again. |
spend_limit_exceeded | This task's cost would go over one of the key's spend limits. Within a few seconds of creating the task, nothing frozen. | Raise the limit in Console → API keys, or wait for it to reset, then create the task again. |
invalid_media | The image can't be downloaded (The image could not be downloaded. Make sure image_url is publicly downloadable.) or read (The image could not be read. It may be corrupted or in an unsupported format.). Found when generation runs, after the price was frozen: all of it is returned. | Replace the image and create the task again. |
content_policy | The image breaks the content policy. | Resubmitting it as is fails again: use a different image. |
generation_failed | Generation failed. | Create it again later. |
queue_timeout / internal_error | Not started within 30 minutes / an error on our side. | Create it again later. |
Every failed task has its frozen amount returned in full and billing.charged "0.00". Branch on error.type: the quoted messages are for display and may change, see Messages.