qwen-image

This documentation is valid for the following list of our models:

  • alibaba/qwen-image

Model Overview

Setup your API Key

If you don’t have an API key for the AI/ML API yet, feel free to use our Quickstart guide.

API Schema

post
Authorizations
Body
modelundefined · enumRequiredPossible values:
promptstring · max: 4000Required

The text prompt describing the content, style, or composition of the image to be generated.

output_formatstring · enumOptional

The format of the generated image.

Default: jpegPossible values:
num_imagesnumber · min: 1 · max: 4Optional

The number of images to generate.

Default: 1
seedinteger · min: 1Optional

The same seed and the same prompt given to the same version of the model will output the same image every time.

enable_safety_checkerbooleanOptional

If set to True, the safety checker will be enabled.

Default: true
guidance_scalenumber · min: 1 · max: 20Optional

The CFG (Classifier Free Guidance) scale is a measure of how close you want the model to stick to your prompt when looking for a related image to show you.

sync_modebooleanOptional

If set to true, the function will wait for the image to be generated and uploaded before returning the response. This will increase the latency of the function but it allows you to get the image directly in the response without going through the CDN.

Default: false
negative_promptstringOptional

The description of elements to avoid in the generated image.

Responses
201

Successfully generated image

application/json
post
POST /v1/images/generations HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 184

{
  "model": "alibaba/qwen-image",
  "prompt": "text",
  "output_format": "jpeg",
  "num_images": 1,
  "seed": 1,
  "enable_safety_checker": true,
  "guidance_scale": 1,
  "sync_mode": false,
  "negative_prompt": "text"
}
201

Successfully generated image

{
  "status": "text",
  "prompt": [
    "text"
  ],
  "model": "text",
  "model_owner": "text",
  "tags": {
    "ANY_ADDITIONAL_PROPERTY": null
  },
  "num_returns": 1,
  "args": {
    "model": "text",
    "prompt": "text",
    "n": 1,
    "steps": 1,
    "size": "text"
  },
  "subjobs": [],
  "output": {
    "choices": [
      {
        "image_base64": "text"
      }
    ]
  }
}

Quick Example

Let's generate an image of the specified size using a simple prompt.

import requests
import json


def main():
    response = requests.post(
        "https://api.aimlapi.com/v1/images/generations",
        headers={
            # Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
            "Authorization": "Bearer <YOUR_AIMLAPI_KEY>",
            "Content-Type": "application/json",
        },
        json={
            "model": "alibaba/qwen-image",
            "prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."
        }
    )

    # response.raise_for_status()
    data = response.json()

    print(json.dumps(data, indent=2, ensure_ascii=False))


if __name__ == "__main__":
    main()
Response
{
  "images": [
    {
      "url": "https://cdn.aimlapi.com/eagle/files/kangaroo/0WBwo2ruHEK9vpmtxu04G.jpeg",
      "width": 1024,
      "height": 768,
      "content_type": "image/jpeg"
    }
  ],
  "timings": {
    "inference": 5.732342581963167
  },
  "seed": 4128479875,
  "has_nsfw_concepts": [
    false
  ],
  "prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."
}

We obtained the following 1024x768 image by running this code example:

'A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses.'

Last updated

Was this helpful?