> **Reading as an AI agent?** This is the Markdown version of https://docs.meshy.ai/api/v2/image-to-image, part of the Meshy API v2 docs.
>
> - v2 docs index: https://docs.meshy.ai/api/v2/llms.txt
> - All v2 pages in one file: https://docs.meshy.ai/api/v2/llms-full.txt
> - OpenAPI spec for v2: https://docs.meshy.ai/api/v2/openapi.yaml

---

# Image to Image API

Generate a new image from one to five reference images and a prompt, for example the same character in a new style. By default, Meshy removes the background, so the image is ready to use as the input for Image to 3D.

> **Note:** Moving from v1? The main changes for Image to Image:
>   * `remove_background` is replaced by `background`. The default is `transparent`, so Meshy removes the background unless you send `background: "opaque"`. A request with `remove_background` returns `400`.
>   * The images are in `output.image_urls`.
>   * The `ai_model` and `prompt` you sent are in `input`.
>
>   See [what changed for Image to Image](/api/migrate-to-v2/reference#image-generation).

This endpoint makes **images**. To make a 3D model of what's in an image, use [Image to 3D](https://docs.meshy.ai/api/v2/image-to-3d.md). To make an object you can hold or print from a photo, for example a keychain or a figure, use the [Creative Lab APIs](/api/creative-lab-keychain).

---

## POST /openapi/v2/image-to-image -- Create an Image to Image task

Creates an Image to Image task and returns the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object). The task runs in the background. To read its result, see [Get the result](#get-the-result). For how long a task usually takes, see [Processing times](/api/task-lifecycle#processing-times).

### Parameters

  - `reference_image_urls` · *string[]* · **required**

  Required unless you send `input_task_id`. One to five images to work from, each a public URL or a data URI (`data:image/png;base64,...`). An empty array, or more than five images, returns `400`.

  Each image must be a JPG, JPEG, PNG, or WebP file of at most 20 MB, and at least 32 pixels on each side.

  - `input_task_id` · *string* · **required**

  Required unless you send `reference_image_urls`. The ID of a Text to Image or Image to Image task whose images to use as the references. The task must be one you created with the API and have the status `SUCCEEDED`. If you send both `reference_image_urls` and `input_task_id`, Meshy uses `input_task_id`.

  Meshy uses every image the task produced. That's one image, or up to three for a multi-view task.

  - `ai_model` · *string* · **required**

  The model that generates the image. Prices differ by model. See [Pricing](/api/pricing).

  Available values:
  * `nano-banana`
  * `nano-banana-2`
  * `nano-banana-2-lite`
  * `nano-banana-2-1`: costs 4 credits per request
  * `nano-banana-pro`: needs a Pro plan or higher. On a lower plan, it returns `402`.
  * `gpt-image-2`: OpenAI GPT Image 2
  * `gpt-image-2-5-flare`: OpenAI GPT Image 2.5 (Flare)
  * `gpt-image-2-5-sunburst`: OpenAI GPT Image 2.5 (Sunburst)
  * `gpt-image-2-6-flare`: OpenAI GPT Image 2.6 (Flare)
  * `gpt-image-2-6-sunburst`: OpenAI GPT Image 2.6 (Sunburst)

  - `prompt` · *string* · **required**

  Text that describes what to make from the reference images, for example `turn it into a clay figurine`.

  - `aspect_ratio` · *string* · default: `1:1`

  The shape of the image.

  Available values:
  * `1:1`
  * `16:9`
  * `9:16`
  * `4:3`
  * `3:4`
  * `3:2`: GPT Image models only
  * `2:3`: GPT Image models only

  With a `nano-banana` model, `3:2` and `2:3` return `400`. You can't send `aspect_ratio` with `generate_multi_view: true`. Sending both returns `400`.

  The result doesn't follow the shape of the reference images. To match them, set `aspect_ratio` to their shape.

  - `background` · *string* · default: `transparent`

  The background of the image.

  Available values:
  * `transparent`: Meshy removes the background and returns a transparent PNG.
  * `opaque`: Meshy returns the image with the background it was generated with.

  With `generate_multi_view: true`, every view has a transparent background. Sending `opaque` with it returns `400`.

  - `generate_multi_view` · *boolean* · default: `false`

  Whether to generate the subject from the front, the side, and the back. `true` returns each view as a separate image with a transparent background in `output.image_urls`, and `false` returns one image.

### Returns

`202 Accepted` with the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object). The task starts as `PENDING`, with your request in `input` and `output` set to `null`.

Two response headers help you read the task:
* `Location`: the task's URL on [Tasks](https://docs.meshy.ai/api/v2/tasks.md#how-a-task-runs)
* `Retry-After`: how many seconds to wait before you first read it

### Failure modes

  - `400 - Bad Request`

  The request can't run. For example:
  * `ai_model` or `prompt` is missing
  * Neither `reference_image_urls` nor `input_task_id` was sent
  * A reference image can't be downloaded or isn't a supported image. The code is `input_download_failed` or `input_file_invalid`, and the message names the image, for example `reference_image_urls[1]`, and says why.
  * The input task hasn't succeeded, or isn't a Text to Image or Image to Image task
  * `ai_model` isn't a supported model
  * `aspect_ratio` was sent with `generate_multi_view: true` (`aspect_ratio cannot be set when generate_multi_view is true`)
  * `background: "opaque"` was sent with `generate_multi_view: true` (`background cannot be opaque when generate_multi_view is true`)
  * `3:2` or `2:3` was sent for a `nano-banana` model

  The error message says which problem it found. See [Errors](https://docs.meshy.ai/api/v2/errors.md#request-errors).

  - `401 - Unauthorized`

  The API key is missing or invalid. Check the `Authorization` header.

  - `402 - Payment Required`

  One of these applies:
  * The account doesn't have enough credits.
  * The account reached a credit limit.
  * The account is on the free plan.
  * The request uses `nano-banana-pro` on a plan below Pro.

  Check your credits and plan, then retry.

  - `404 - Not Found`

  `input_task_id` doesn't match any of your tasks. The message is `input_task_id does not match any of your tasks`. A task you deleted also returns `404`.

  For a task past its [retention period](https://docs.meshy.ai/api/v2/asset-retention.md), the code is `input_task_expired`. Create the input task again, and send the new task's `id`.

  - `429 - Too Many Requests`

  One of these limits was reached:
  * You sent too many requests. Wait the number of seconds in `Retry-After`, then retry.
  * Too many of your tasks are queued or running. Wait for some to finish, then retry.
  * On an unlimited plan with no credits left, you reached the number of tasks that can run without credits. Wait for a task to finish, or add credits.

**cURL**

```bash
# Restyle a reference image
curl https://api.meshy.ai/openapi/v2/image-to-image \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "ai_model": "nano-banana",
    "prompt": "turn it into a clay figurine",
    "reference_image_urls": ["https://docs.meshy.ai/images/api/quick-start/source-photo.webp"]
  }'

# Edit the images of an earlier Text to Image task
curl https://api.meshy.ai/openapi/v2/image-to-image \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "ai_model": "nano-banana",
    "prompt": "make the robot gold",
    "input_task_id": "018a210d-8ba4-705c-b111-1f1776f7f578"
  }'
```

```javascript
// Restyle a reference image
const response = await fetch("https://api.meshy.ai/openapi/v2/image-to-image", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MESHY_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    ai_model: "nano-banana",
    prompt: "turn it into a clay figurine",
    reference_image_urls: [
      "https://docs.meshy.ai/images/api/quick-start/source-photo.webp",
    ],
  }),
});
if (!response.ok) throw new Error(await response.text());
const task = await response.json();
console.log(task.id, task.status);
```

```python
import os
import requests

# Restyle a reference image
response = requests.post(
    "https://api.meshy.ai/openapi/v2/image-to-image",
    headers={"Authorization": f"Bearer {os.environ['MESHY_API_KEY']}"},
    json={
        "ai_model": "nano-banana",
        "prompt": "turn it into a clay figurine",
        "reference_image_urls": [
            "https://docs.meshy.ai/images/api/quick-start/source-photo.webp",
        ],
    },
)
response.raise_for_status()
task = response.json()
print(task["id"], task["status"])
```

**Response**

```json
{
  "id": "0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13",
  "type": "image-to-image",
  "status": "PENDING",
  "progress": 0,
  "created_at": 1790640079880,
  "started_at": null,
  "finished_at": null,
  "expires_at": null,
  "preceding_tasks": 1,
  "consumed_credits": 3,
  "task_error": null,
  "input": {
    "ai_model": "nano-banana",
    "prompt": "turn it into a clay figurine",
    "reference_image_urls": ["https://docs.meshy.ai/images/api/quick-start/source-photo.webp"]
  },
  "output": null
}
```

---

## Get the result
Read Image to Image tasks the same way as every other v2 task, through the [Tasks](https://docs.meshy.ai/api/v2/tasks.md) routes. To list only Image to Image tasks, filter by `type=image-to-image`. The filter includes multi-view tasks.

| To | Call |
| --- | --- |
| Get one task | [`GET /openapi/v2/tasks/{id}`](https://docs.meshy.ai/api/v2/tasks.md#get-a-task) |
| Wait for updates | [`GET /openapi/v2/tasks/{id}/stream`](https://docs.meshy.ai/api/v2/tasks.md#stream-a-task) or a [webhook](https://docs.meshy.ai/api/v2/webhooks.md) |
| List your tasks | [`GET /openapi/v2/tasks?type=image-to-image`](https://docs.meshy.ai/api/v2/tasks.md#list-tasks) |
| Delete a task | [`DELETE /openapi/v2/tasks/{id}`](https://docs.meshy.ai/api/v2/tasks.md#delete-a-task) |

---

## Image to Image output
When the task succeeds, `output` holds this field. The rest of the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object) is the same for every task type. The URLs in `output` stop working at `expires_at`.

  - `image_urls` · *string[]*

  Signed URLs to the generated PNG images:
  * A single image: one URL. With `background: "transparent"`, Meshy removes the image's background. If it can't, the task still succeeds, and the image keeps its background.
  * With `generate_multi_view: true`: one URL per view, usually three, each with a transparent background. If Meshy can't separate every view, it returns fewer, and the task still succeeds.

If the model provider's safety check declines the prompt or a reference image, the task fails. Its `task_error` has the type `invalid_input` and the code `provider_content_refused`. Change the prompt or the reference images, then create another task. See [Errors](https://docs.meshy.ai/api/v2/errors.md#invalid-input).

**Succeeded Image to Image task**

```json
{
  "id": "0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13",
  "type": "image-to-image",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1790640079880,
  "started_at": 1790640079886,
  "finished_at": 1790640091374,
  "expires_at": 1790899291374,
  "preceding_tasks": 0,
  "consumed_credits": 3,
  "task_error": null,
  "input": {
    "ai_model": "nano-banana",
    "prompt": "turn it into a clay figurine",
    "reference_image_urls": ["https://docs.meshy.ai/images/api/quick-start/source-photo.webp"]
  },
  "output": {
    "image_urls": [
      "https://assets.meshy.ai/***/uploads/image_0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13_0.png?Expires=***"
    ]
  }
}
```
