Qwen Image API Documentation

Text To Image Request - Request Code

POST https://gateway.pixazo.ai/qwen-image/v1/generateMultimodeTextToImageRequest HTTP/1.1
Content-Type: application/json
Cache-Control: no-cache
Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY

{
  "model": "qwen-image",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "text": "An elegant and solemn couplet hangs in a hall. The room has a quiet and classic Chinese decor. The left scroll reads 'Righteousness is the root of innate knowledge; humans and machines share the same path and excel in new thinking.' The right scroll reads 'Connecting clouds grants wisdom; the universe reveals numbers, inspiring lofty ambitions.' The horizontal scroll reads 'Wisdom enlightens Tongyi.' The calligraphy is flowing. A Chinese-style painting of Yueyang Tower hangs in the middle."
          }
        ]
      }
    ]
  },
  "parameters": {
    "negative_prompt": "",
    "prompt_extend": true,
    "watermark": true,
    "size": "1328*1328"
  }
}
import requests
import json

url = "https://gateway.pixazo.ai/qwen-image/v1/generateMultimodeTextToImageRequest"

headers = {
    "Content-Type": "application/json",
    "Cache-Control": "no-cache",
    "Ocp-Apim-Subscription-Key": "YOUR_SUBSCRIPTION_KEY"
}

data = {
    "model": "qwen-image",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "text": "An elegant and solemn couplet hangs in a hall. The room has a quiet and classic Chinese decor. The left scroll reads 'Righteousness is the root of innate knowledge; humans and machines share the same path and excel in new thinking.' The right scroll reads 'Connecting clouds grants wisdom; the universe reveals numbers, inspiring lofty ambitions.' The horizontal scroll reads 'Wisdom enlightens Tongyi.' The calligraphy is flowing. A Chinese-style painting of Yueyang Tower hangs in the middle."
                    }
                ]
            }
        ]
    },
    "parameters": {
        "negative_prompt": "",
        "prompt_extend": true,
        "watermark": true,
        "size": "1328*1328"
    }
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
const url = 'https://gateway.pixazo.ai/qwen-image/v1/generateMultimodeTextToImageRequest';

const data = {
  model: 'qwen-image',
  input: {
    messages: [
      {
        role: 'user',
        content: [
          {
            text: 'An elegant and solemn couplet hangs in a hall. The room has a quiet and classic Chinese decor. The left scroll reads \'Righteousness is the root of innate knowledge; humans and machines share the same path and excel in new thinking.\' The right scroll reads \'Connecting clouds grants wisdom; the universe reveals numbers, inspiring lofty ambitions.\' The horizontal scroll reads \'Wisdom enlightens Tongyi.\' The calligraphy is flowing. A Chinese-style painting of Yueyang Tower hangs in the middle.'
          }
        ]
      }
    ]
  },
  parameters: {
    negative_prompt: '',
    prompt_extend: true,
    watermark: true,
    size: '1328*1328'
  }
};

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Cache-Control': 'no-cache',
    'Ocp-Apim-Subscription-Key': 'YOUR_SUBSCRIPTION_KEY'
  },
  body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
curl -v -X POST "https://gateway.pixazo.ai/qwen-image/v1/generateMultimodeTextToImageRequest" \
-H "Content-Type: application/json" \
-H "Cache-Control: no-cache" \
-H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY" \
--data-raw '{
  "model": "qwen-image",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "text": "An elegant and solemn couplet hangs in a hall. The room has a quiet and classic Chinese decor. The left scroll reads \"Righteousness is the root of innate knowledge; humans and machines share the same path and excel in new thinking.\" The right scroll reads \"Connecting clouds grants wisdom; the universe reveals numbers, inspiring lofty ambitions.\" The horizontal scroll reads \"Wisdom enlightens Tongyi.\" The calligraphy is flowing. A Chinese-style painting of Yueyang Tower hangs in the middle."
          }
        ]
      }
    ]
  },
  "parameters": {
    "negative_prompt": "",
    "prompt_extend": true,
    "watermark": true,
    "size": "1328*1328"
  }
}'
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class QwenImageExample {
    public static void main(String[] args) throws Exception {
        String url = "https://gateway.pixazo.ai/qwen-image/v1/generateMultimodeTextToImageRequest";
        
        String jsonBody = "{" + "\n" +
            "  \"model\": \"qwen-image\"," + "\n" +
            "  \"input\": {" + "\n" +
            "    \"messages\": [" + "\n" +
            "      {" + "\n" +
            "        \"role\": \"user\"," + "\n" +
            "        \"content\": [" + "\n" +
            "          {" + "\n" +
            "            \"text\": \"An elegant and solemn couplet hangs in a hall. The room has a quiet and classic Chinese decor. The left scroll reads 'Righteousness is the root of innate knowledge; humans and machines share the same path and excel in new thinking.' The right scroll reads 'Connecting clouds grants wisdom; the universe reveals numbers, inspiring lofty ambitions.' The horizontal scroll reads 'Wisdom enlightens Tongyi.' The calligraphy is flowing. A Chinese-style painting of Yueyang Tower hangs in the middle.\"" + "\n" +
            "          }\n" +
            "        ]\n" +
            "      }\n" +
            "    ]\n" +
            "  }," + "\n" +
            "  \"parameters\": {" + "\n" +
            "    \"negative_prompt\": \"\"," + "\n" +
            "    \"prompt_extend\": true," + "\n" +
            "    \"watermark\": true," + "\n" +
            "    \"size\": \"1328*1328\"" + "\n" +
            "  }\n" +
            "}";

        HttpClient client = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(10))
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(url))
            .header("Content-Type", "application/json")
            .header("Cache-Control", "no-cache")
            .header("Ocp-Apim-Subscription-Key", "YOUR_SUBSCRIPTION_KEY")
            .POST(HttpRequest.BodyPublishers.ofString(jsonBody))
            .build();

        HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode());
        System.out.println(response.body());
    }
}
<?php
$url = 'https://gateway.pixazo.ai/qwen-image/v1/generateMultimodeTextToImageRequest';

$data = [
    'model' => 'qwen-image',
    'input' => [
        'messages' => [
            [
                'role' => 'user',
                'content' => [
                    [
                        'text' => 'An elegant and solemn couplet hangs in a hall. The room has a quiet and classic Chinese decor. The left scroll reads \'Righteousness is the root of innate knowledge; humans and machines share the same path and excel in new thinking.\' The right scroll reads \'Connecting clouds grants wisdom; the universe reveals numbers, inspiring lofty ambitions.\' The horizontal scroll reads \'Wisdom enlightens Tongyi.\' The calligraphy is flowing. A Chinese-style painting of Yueyang Tower hangs in the middle.'
                    ]
                ]
            ]
        ]
    ],
    'parameters' => [
        'negative_prompt' => '',
        'prompt_extend' => true,
        'watermark' => true,
        'size' => '1328*1328'
    ]
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Cache-Control: no-cache',
    'Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY'
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "HTTP Code: " . $httpCode . "\n";
echo "Response: " . $response . "\n";
?>

Output

Successful API response:

{ "output": { "choices": [ { "finish_reason": "stop", "message": { "role": "assistant", "content": [ { "image": "<IMAGE_URL>" } ] } } ], "task_metric": { "TOTAL": 1, "FAILED": 0, "SUCCEEDED": 1 } }, "usage": { "width": 1328, "image_count": 1, "height": 1328 }, "request_id": "7a270c86-db58-9faf-b403-xxxxxx" }

Request Body - Text To Image Request

Parameters for /generateMultimodeTextToImageRequest:

ParameterRequiredTypeDescription
modelYesstringModel to use. Available value: "qwen-image" (Qwen text-to-image generation model).
input.messagesYesarrayArray of message objects containing the generation request. Must contain at least one user message.
input.messages[].roleYesstringRole of the message sender. Must be "user" for text-to-image generation requests.
input.messages[].contentYesarrayArray of content objects containing the text prompt for image generation.
input.messages[].content[].textYesstringText prompt describing the image to generate. Supports complex descriptions, multi-line layouts, and fine-grained details. Excels at Chinese and English text rendering.
parameters.negative_promptNostringNegative prompt to specify what should not appear in the generated image. Default: "" (empty string).
parameters.prompt_extendNobooleanWhether to extend and enhance the input prompt automatically. Default: true.
parameters.watermarkNobooleanWhether to add a watermark to the generated image. Default: true.
parameters.sizeNostringOutput image dimensions in format "WIDTHxHEIGHT". Available sizes: "1328*1328", "1024*1024", "768*768", "512*512". Default: "1328*1328".

Example Request - Text To Image Request

JSON
{ "model": "qwen-image", "input": { "messages": [ { "role": "user", "content": [ { "text": "An elegant and solemn couplet hangs in a hall. The room has a quiet and classic Chinese decor. The left scroll reads 'Righteousness is the root of innate knowledge; humans and machines share the same path and excel in new thinking.' The right scroll reads 'Connecting clouds grants wisdom; the universe reveals numbers, inspiring lofty ambitions.' The horizontal scroll reads 'Wisdom enlightens Tongyi.' The calligraphy is flowing. A Chinese-style painting of Yueyang Tower hangs in the middle." } ] } ] }, "parameters": { "negative_prompt": "", "prompt_extend": true, "watermark": true, "size": "1328*1328" } }

Response - Text To Image Request

JSON
{ "output": { "choices": [ { "finish_reason": "stop", "message": { "role": "assistant", "content": [ { "image": "https://example.com/generated-image.png" } ] } } ], "task_metric": { "TOTAL": 1, "FAILED": 0, "SUCCEEDED": 1 } }, "usage": { "width": 1328, "image_count": 1, "height": 1328 }, "request_id": "7a270c86-db58-9faf-b403-xxxxxx" }

Request Headers

HeaderDescription
Content-TypeMust be set to application/json
Cache-ControlMust be set to no-cache
Ocp-Apim-Subscription-KeyYour subscription key for authentication

Response Handling

The Qwen Image returns specific HTTP status codes and response bodies to indicate the success or failure of a request. Developers should implement error handling in their applications to manage these responses effectively.

Common Status Codes and Responses

Status CodeDescriptionResponse Body
200Success - The request was successfully processed.{ "success": true, ... }
Bad Request - The request contains invalid parameters or missing fields.{ "error": "Invalid request parameters" }
401Unauthorized - The provided subscription key is missing or invalid.{ "error": "Invalid or missing authentication" }
403Forbidden - The subscription does not have access to this API or action.{ "error": "Access denied for this operation" }
404Not Found - The requested resource or endpoint could not be found.{ "error": "Endpoint not found" }
Too Many Requests - The request rate limit has been exceeded.{ "error": "Rate limit exceeded, please retry later" }
500Internal Server Error - An unexpected error occurred on the server.{ "error": "An unexpected error occurred, please try again later" }

Example Error Response

{
  "error": "Invalid parameters"
}

Qwen Image API Pricing

Resolution Price (USD)
All Resolution$0.045

Ready to generate Qwen Image API assets?

Start with an API key, then automate your pipeline.