> **Reading as an AI agent?** This is the Markdown version of https://docs.meshy.ai/api/v2/text-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

---

# Text to Image API

Generate an image from a text prompt. 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 Text 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 Text 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/text-to-image -- Create a Text to Image task

Creates a Text 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

  - `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 the image to generate.

  - `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`.

  - `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.

  - `pose_mode` · *string*

  The pose for a standing character, `a-pose` or `t-pose`. Leave it out for no pose.

  With a `nano-banana` model, a posed image is always `3:4`, whatever you send as `aspect_ratio`. The GPT Image models keep your `aspect_ratio`.

  With `nano-banana` or `nano-banana-pro`, a pose needs a Pro plan or higher. On a lower plan, the request returns `402`.

### 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
  * `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`, or `pose_mode` with `nano-banana`, on a plan below Pro.

  Check your credits and plan, then retry.

  - `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
# Generate one image from a prompt
curl https://api.meshy.ai/openapi/v2/text-to-image \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "ai_model": "nano-banana",
    "prompt": "a small brass robot, full body"
  }'

# Generate front, side, and back views of a character
curl https://api.meshy.ai/openapi/v2/text-to-image \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "ai_model": "nano-banana",
    "prompt": "a cartoon knight in silver armor",
    "generate_multi_view": true
  }'
```

```javascript
// Generate one image from a prompt
const response = await fetch("https://api.meshy.ai/openapi/v2/text-to-image", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MESHY_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    ai_model: "nano-banana",
    prompt: "a small brass robot, full body",
  }),
});
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

# Generate one image from a prompt
response = requests.post(
    "https://api.meshy.ai/openapi/v2/text-to-image",
    headers={"Authorization": f"Bearer {os.environ['MESHY_API_KEY']}"},
    json={
        "ai_model": "nano-banana",
        "prompt": "a small brass robot, full body",
    },
)
response.raise_for_status()
task = response.json()
print(task["id"], task["status"])
```

**Response**

```json
{
  "id": "0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13",
  "type": "text-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": "a small brass robot, full body"
  },
  "output": null
}
```

---

## Get the result
Read Text 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 Text to Image tasks, filter by `type=text-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=text-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) |

---

## Text 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, the task fails. Its `task_error` has the type `invalid_input` and the code `provider_content_refused`. Change the prompt, then create another task. See [Errors](https://docs.meshy.ai/api/v2/errors.md#invalid-input).

**Succeeded Text to Image task**

```json
{
  "id": "0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13",
  "type": "text-to-image",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1790640079880,
  "started_at": 1790640079886,
  "finished_at": 1790640088941,
  "expires_at": 1790899288941,
  "preceding_tasks": 0,
  "consumed_credits": 3,
  "task_error": null,
  "input": {
    "ai_model": "nano-banana",
    "prompt": "a small brass robot, full body"
  },
  "output": {
    "image_urls": [
      "https://assets.meshy.ai/***/uploads/image_0199a8f6-3d27-7c2e-9b41-6e0c5d2f8a13_0.png?Expires=***"
    ]
  }
}
```
