# Qwen Image Generation

OpenAI compatible: `POST /v1/images/generations`. Native path: `/api/v1/services/aigc/multimodal-generation/generation`. [Image Generation API](https://help.aliyun.com/zh/model-studio/qwen-image-generation-and-editing-api-reference?spm=a2c4g.11186623.help-menu-2400256.d_2_2_0_0.4ef45598uDMl78)

> Refer to the platform's "Open Models List" for exact model IDs. On the OpenAI-compatible path, use **`prompt` + `image` / `image_urls`**; `messages`, `style`, and `quality` are not supported.

---

## 1. OpenAI-Compatible Integration (POST)

* **Path**: `https://www.tokenpad.ai/v1/images/generations`
* **Auth**: `Authorization: Bearer sk-your_token`

### A. Text-to-Image

```bash
curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-image-3.0-pro",
    "prompt": "Cyberpunk city nightscape, neon reflections, ultra-clear photorealism, cinematic composition",
    "size": "1024*1024",
    "n": 1,
    "response_format": "url"
  }'
```

### B. Single Image Reference / Image-to-Image

```bash
curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-image-3.0-pro",
    "prompt": "The character from the reference image standing by a library window looking out into the distance, cinematic natural lighting",
    "image": "https://example.com/assets/character_face.jpg",
    "size": "1024*1024",
    "n": 1
  }'
```

### C. Multi-Image Reference Generation

```bash
curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-image-3.0-pro",
    "prompt": "Use the character appearance from image 1 and scene atmosphere from image 2, unified illustration style, warm natural light",
    "image_urls": [
      "https://example.com/character.png",
      "https://example.com/scene.png"
    ],
    "size": "1280*720",
    "n": 2
  }'
```

### D. Negative Prompt

```bash
curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-image-3.0-pro",
    "prompt": "Cyberpunk city nightscape, neon reflections, ultra-clear photorealism",
    "negative_prompt": "blurry, low quality, deformed, watermark",
    "size": "1024*1024",
    "n": 1
  }'
```

---

## 2. OpenAI-Compatible Parameter Dictionary

| Param | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `model` | `string` | Yes | e.g., `qwen-image-3.0-pro` |
| `prompt` | `string` | Yes | Visual description |
| `negative_prompt` | `string` | No | Negative prompt |
| `image` | `string / array` | No | Reference image URL; single string or URL array |
| `image_urls` | `array` | No | Multi-image reference URL array (equivalent to `image` array; use either) |
| `size` | `string` | No | e.g., `1024*1024`, `1280*720`; `1024x1024` is automatically converted to `*` |
| `n` | `integer` | No | Number of images to generate, default `1` |
| `response_format` | `string` | No | `"url"` or `"b64_json"` |

---

## 3. Alibaba Bailian Native Routes (Brief)

| Capability | Path |
| :--- | :--- |
| Image submit | `POST /api/v1/services/aigc/multimodal-generation/generation` |
| Async query | `GET /api/v1/tasks/{task_id}` |

Payloads already containing the official `input` / `parameters` structure are passed through verbatim; async tasks require header `X-DashScope-Async: enable`.

---

## 4. Response Example (200 OK)

```json
{
  "created": 1719441600,
  "data": [
    { "url": "https://example.com/output/qwen_img_1.png" },
    { "url": "https://example.com/output/qwen_img_2.png" }
  ]
}
```



### 5. Common Error Codes & Troubleshooting

HTTP codes, error body format, and troubleshooting are **maintained in one dedicated page** (not duplicated under each example).

👉 **[Gateway Error Codes & Troubleshooting](/docs/errors/error-codes)**

**Quick reference**:

| Code | Meaning |
| :---: | :--- |
| **400** | Invalid parameters / content moderation or copyright block |
| **402** | Insufficient account balance (**not** 429) |
| **429** | RPS/RPM limits or in-flight task cap (low balance) |
| **403** | Token / IP / model permission (balance → 402; content filter → 400) |
| **200 + `status: failed`** | Async video/long-task business failure on poll |

HTTP status matches call log `status_code` for traceability by `log_id`.

> **Maintenance**: update the `error-codes` article only; this appendix links to it.
