If you already use OpenAI Images or DashScope, keep the model name and request body. Set your client's base URL to the one below and use your gateway API key. Send it as Authorization: Bearer $API_KEY in HTTP requests. Use Content-Type: application/json for POST requests.
| Client | Base URL |
|---|---|
| OpenAI SDK | https://mm-internal-cn.leonecloud.com/compatible-mode/v1 |
| DashScope SDK | https://mm-internal-cn.leonecloud.com/api/v1 |
OpenAI-compatible synchronous API
POST /compatible-mode/v1/images/generations supports text-to-image and image editing. Omit image for text-to-image. For editing, pass one image string or an array of 1–3 image strings in the desired order. Each string is a public HTTP(S) URL or a data:image/...;base64,... data URL. Do not pass null or an empty array.
# pip install -U openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://mm-internal-cn.leonecloud.com/compatible-mode/v1",
api_key=os.environ["API_KEY"],
timeout=600.0,
)
result = client.images.generate(
model="qwen-image-3.0-pro",
prompt="Illustrate a bookshop with warm lights on a rainy evening",
size="1024x1024",
n=1,
# For image editing, add:
# extra_body={"image": os.environ["REFERENCE_IMAGE_URL"]},
)
for item in result.data:
print(item.url)
print(result._request_id)| Field | Description |
|---|---|
model, prompt | Required. Use qwen-image-3.0-pro and a nonempty prompt. |
n | Integer from 1 to 6, defaults to 1. |
size | WIDTHxHEIGHT, auto, or omitted to let the model choose. Total area: 512×512 to 2048×2048 pixels. Aspect ratio: 1:8 to 8:1. |
response_format | url (default) or b64_json. |
negative_prompt, seed | Negative prompt and integer seed from 0 to 2147483647. |
prompt_extend, prompt_extend_mode | Toggle prompt rewriting and choose direct or agent. agent is for text-to-image only. |
enable_thinking, watermark | Toggle thinking when prompt rewriting is enabled, or add a watermark. |
In the OpenAI SDK, pass image, negative_prompt, seed, prompt_extend, prompt_extend_mode, enable_thinking, and watermark through extra_body. In raw JSON, put them at the top level. Reference images must be at most 10 MB each, with sides from 1 to 8000 pixels and an aspect ratio no greater than 10:1.
Success returns created, data, and usage. Read data[].url or data[].b64_json (plain Base64). Errors use error.message, error.type, error.code, and error.param. The request ID is in the x-request-id response header. Streaming, partial images, /images/edits, multipart uploads and masks are unsupported.
DashScope protocol
Set dashscope.base_http_api_url to the DashScope base URL above and provide the gateway key as api_key in your existing MultiModalConversation.call call. The synchronous HTTP equivalent is:
curl -sS 'https://mm-internal-cn.leonecloud.com/api/v1/services/aigc/multimodal-generation/generation' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-image-3.0-pro",
"input": {"messages": [{"role": "user", "content": [
{"text": "Render the reference as a watercolor"},
{"image": "https://example.com/reference.png"}
]}]},
"parameters": {"size": "1024*1024", "n": 1}
}'Replace the example reference URL with a public image URL or image data URL. Use one user message containing exactly one text item, and add 1–3 image items for editing. Put generation options in parameters. Use WIDTH*HEIGHT or omit size for automatic sizing.
Read images from output.choices[].message.content[].image. With b64_json, this field is a data URL including the MIME prefix. The response includes request_id; errors include code and message.
For an asynchronous task, submit the same JSON to POST /api/v1/services/aigc/image-generation/generation with X-DashScope-Async: enable. Async output is URL only. Save output.task_id and poll with the same gateway and API key:
curl -sS "https://mm-internal-cn.leonecloud.com/api/v1/tasks/$TASK_ID" \
-H "Authorization: Bearer $API_KEY"Continue polling for PENDING or RUNNING. For SUCCEEDED, read the same image fields as the synchronous response. For FAILED, check output.code and output.message. Stop for CANCELED or UNKNOWN. Task IDs can be queried for 24 hours. Temporary PNG URLs are also valid for 24 hours.
Usage and billing
The usage object reports input_image_count, output_image_count, output_width, output_height, input_image_type, and output_image_type. Both billing tiers use the actual output area: up to and including 2,250,000 pixels is 1K; larger images are 2K. The corresponding usage values are qima_input_1k / qima_input_2k and qima_output_1k / qima_output_2k.
Input and output images are billed separately according to the actual counts. Automatic sizing reserves the maximum charge. The remaining amount is released after settlement. See the console pricing page for per-image rates.
Existing asynchronous API
The previous POST /api/v2/open/aigc/qwen-image-3-pro and GET /api/v2/open/aigc/{taskId} endpoints remain available. The original guide includes the request fields, batch queries and callbacks.