# Qwen Image 2.1

> Alibaba's 7B open-weight unified text-to-image and editing model with native RGBA transparency, up to 10 reference images, and 2K resolution.

## Overview

- Submit: `https://api.poyo.ai/api/generate/submit`
- Status: `https://api.poyo.ai/api/generate/status/{task_id}`
- Page: https://poyo.ai/models/qwen-image-2-1
- Model page ID: `qwen-image-2-1`
- API model ID: `qwen-image-2.1`
- Category: Image
- Auth: `Authorization: Bearer $POYO_API_KEY`
- Create a key at https://poyo.ai/dashboard/api-key

This model uses PoYo's unified async API. POST the JSON body below, then poll status with the returned `task_id` or receive a webhook on `callback_url`. Failed tasks are not charged.

## Pricing

- 1K: 6 credits ($0.030) per generation
- 2K: 10 credits ($0.050) per generation

For more details, see https://poyo.ai/models/qwen-image-2-1.

## API Information

The request envelope is always `{ model, input, callback_url? }`. Input fields below are nested under `input`.

### Request envelope

- `model` (`ModelEnum`, required):
  - Options: `"qwen-image-2.1"`
- `callback_url` (`string`, optional):

### Input Schema

The API accepts the following `input` parameters:

- `prompt` (`string`, required):
  Describe the desired image or the changes to make. The prompt must not consist only of whitespace.
  - Length: 1 to 5000 characters
- `image_urls` (`list`, optional):
  Omit or use an empty array for text-to-image. Otherwise provide 1-10 publicly accessible HTTP(S) reference URLs in prompt order. JPEG, PNG and WebP; up to 30MB and 25MP per image. Media limits are checked during generation.
  - Array of string
  - Length: 0 to 10
- `size` (`SizeEnum`, optional):
  Output aspect ratio. Defaults to 1:1 for text-to-image and auto for reference images. auto requires at least one reference image. Ignored when mask_url is supplied.
  - Options: `"1:1"`, `"4:3"`, `"3:4"`, `"3:2"`, `"2:3"`, `"16:9"`, `"9:16"`, `"21:9"`, `"9:21"`, `"auto"`
- `resolution` (`ResolutionEnum`, optional):
  - Default: `"1K"`
  - Options: `"1K"`, `"2K"`
- `output_format` (`OutputFormatEnum`, optional):
  - Default: `"png"`
  - Options: `"png"`, `"webp"`, `"jpeg"`
- `prompt_extend` (`boolean`, optional):
  Enhance the prompt before generation. Ignored when mask_url is supplied.
  - Default: `true`
- `enable_safety_checker` (`boolean`, optional):
  - Default: `true`
- `background` (`BackgroundEnum`, optional):
  Transparent output requires png or webp and cannot be combined with mask_url.
  - Default: `"opaque"`
  - Options: `"opaque"`, `"transparent"`
- `mask_url` (`string`, optional):
  HTTP(S) URL of a local-edit mask used with exactly one reference image and an opaque background. White areas change; black areas stay unchanged. Match the reference aspect ratio; the mask is scaled to the reference dimensions. Output follows the reference ratio; size and prompt_extend are ignored.
- `seed` (`integer`, optional):
  Optional random seed. Omit to use a random seed.

Required Parameters Example:

```json
{
  "model": "qwen-image-2.1",
  "input": {
    "prompt": "A bilingual technology poster with the headline Future Vision, precise typography, blue and silver palette",
    "size": "3:4",
    "resolution": "1K"
  }
}
```

Full Example:

```json
{
  "model": "qwen-image-2.1",
  "input": {
    "prompt": "A bilingual technology poster with the headline Future Vision, precise typography, blue and silver palette",
    "size": "3:4",
    "resolution": "1K",
    "output_format": "png",
    "prompt_extend": true,
    "enable_safety_checker": true,
    "background": "opaque"
  }
}
```

Combine reference images:

```json
{
  "model": "qwen-image-2.1",
  "input": {
    "prompt": "Combine the product in the first image with the colors and lighting of the second image",
    "image_urls": [
      "https://example.com/product.png",
      "https://example.com/style.jpg"
    ],
    "size": "auto",
    "resolution": "2K",
    "prompt_extend": false
  }
}
```

Transparent WebP asset:

```json
{
  "model": "qwen-image-2.1",
  "input": {
    "prompt": "A playful corgi sticker, isolated subject",
    "background": "transparent",
    "output_format": "webp",
    "seed": 20260921
  }
}
```

### Output Schema

Submit returns a `task_id`. Poll `GET /api/generate/status/{task_id}` until `status` is `finished` or `failed`. Completed media is in `data.files`.

Response fields:

- `code` (`CodeEnum`, required):
  Business status code. `200` means success; any other value means the request failed. Always check this field: some validation errors return HTTP 200 with `code: 400` in the body.
  
  - `200`: Success
  - `400`: Invalid request parameters
  - `401`: Missing or invalid API key
  - `402`: Insufficient credits
  - `403`: Permission denied
  - `404`: Resource not found
  - `408`: Request timeout
  - `429`: Rate limit exceeded
  - `500`: Internal server error
  - `502`: Upstream service error
  - `503`: Service unavailable
  
  See [Error Codes](/api-manual/error-codes) for details.
  - Options: `200`, `400`, `401`, `402`, `403`, `404`, `408`, `429`, `500`, `502`, `503`
  - Examples: `200`
- `data` (`object`, required):

Example Response:

```json
{
  "code": 200,
  "data": {
    "task_id": "task_example",
    "status": "finished",
    "files": [
      {
        "file_url": "https://storage.poyo.ai/models/qwen-image-2-1/examples/moon-phases-output-attempt-3-8c9581769ef0.png",
        "file_type": "image"
      }
    ]
  }
}
```

## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://api.poyo.ai/api/generate/submit \
  --header "Authorization: Bearer $POYO_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"model":"qwen-image-2.1","input":{"prompt":"A bilingual technology poster with the headline Future Vision, precise typography, blue and silver palette","size":"3:4","resolution":"1K"}}'
```

### Python

```python
import json
import os
import time
import requests

API = "https://api.poyo.ai"
headers = {
    "Authorization": f"Bearer {os.environ['POYO_API_KEY']}",
    "Content-Type": "application/json",
}
payload = json.loads("{\n  \"model\": \"qwen-image-2.1\",\n  \"input\": {\n    \"prompt\": \"A bilingual technology poster with the headline Future Vision, precise typography, blue and silver palette\",\n    \"size\": \"3:4\",\n    \"resolution\": \"1K\"\n  }\n}")

submit = requests.post(f"{API}/api/generate/submit", headers=headers, json=payload)
submit.raise_for_status()
task_id = submit.json()["data"]["task_id"]

while True:
    status = requests.get(f"{API}/api/generate/status/{task_id}", headers=headers)
    status.raise_for_status()
    data = status.json()["data"]
    if data["status"] in ("finished", "failed"):
        print(data)
        break
    time.sleep(2)
```

### JavaScript

```javascript
const headers = {
  Authorization: `Bearer ${process.env.POYO_API_KEY}`,
  "Content-Type": "application/json",
};

const submit = await fetch("https://api.poyo.ai/api/generate/submit", {
  method: "POST",
  headers,
  body: JSON.stringify({
  "model": "qwen-image-2.1",
  "input": {
    "prompt": "A bilingual technology poster with the headline Future Vision, precise typography, blue and silver palette",
    "size": "3:4",
    "resolution": "1K"
  }
}),
});

const submitted = await submit.json();
const taskId = submitted.data.task_id;

while (true) {
  const statusResponse = await fetch(`https://api.poyo.ai/api/generate/status/${taskId}`, { headers });
  const status = await statusResponse.json();
  if (["finished", "failed"].includes(status.data.status)) {
    console.log(status.data);
    break;
  }
  await new Promise((resolve) => setTimeout(resolve, 2000));
}
```

## Additional Resources

### Documentation

- [Model Playground](https://poyo.ai/models/qwen-image-2-1)
- [API Documentation](https://docs.poyo.ai/api-manual/image-series/qwen-image-2-1)
- [API Documentation (Markdown)](https://docs.poyo.ai/api-manual/image-series/qwen-image-2-1.md)
- [Task status](https://docs.poyo.ai/api-manual/task-management/query-task-status)
- [Webhooks](https://docs.poyo.ai/api-manual/task-management/webhooks)

### Other agent-readable surfaces

- [Platform overview](https://poyo.ai/llms.txt)
- [Documentation index](https://docs.poyo.ai/llms.txt)
- [Full documentation text](https://docs.poyo.ai/llms-full.txt)
- Any other model: `https://poyo.ai/models/<model-id>/llms.txt`
