Qwen Image
curl --request POST \
--url https://api.mixroute.ai/v1/images/generationsimport requests
url = "https://api.mixroute.ai/v1/images/generations"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.ai/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mixroute.ai/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.mixroute.ai/v1/images/generations"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.mixroute.ai/v1/images/generations")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.ai/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body圖像系列
Qwen Image
Qwen Image 圖片生成欄位、模型限制與請求示例。
Qwen Image
curl --request POST \
--url https://api.mixroute.ai/v1/images/generationsimport requests
url = "https://api.mixroute.ai/v1/images/generations"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.ai/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mixroute.ai/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.mixroute.ai/v1/images/generations"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.mixroute.ai/v1/images/generations")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.ai/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body
Qwen 圖片生成按模型使用兩種請求格式,均呼叫同一個 MixRoute 端點。不要混用 input.prompt 與 input.messages。
參考圖編輯請使用 Qwen Image 編輯 頁面中的 qwen-image-edit* 模型。請求不增加 metadata 或 asset 包裝。
POST https://api.mixroute.ai/v1/images/generations
模型選擇
| 模型 | 輸入格式 | 圖片 URL 位置 |
|---|---|---|
qwen-image, qwen-image-plus | input.prompt | output.results[].url |
qwen-image-2.0, qwen-image-2.0-pro, qwen-image-max | input.messages | output.choices[].message.content[].image |
基礎文生圖
使用 qwen-image 或 qwen-image-plus。input 物件中傳入 prompt,而不是 messages。參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 對應模型表中的完整模型 ID。 |
input | object | 是 | 輸入物件。 |
input.prompt | string | 是 | 文本提示詞,支援中英文混合,可描述內容、風格與構圖。 |
parameters | object | 否 | 可選生成設定。 |
parameters.size | string | 否 | 尺寸採用 寬*高 格式,例如 1024*1024 或 1664*928,使用星號而不是 x。 |
parameters.n | integer | 否 | 單次請求僅支援 1 張;需要多張時分別呼叫。 |
請求示例
將 MixRoute Key 設定為環境變數MIXROUTE_API_KEY。
curl --request POST "https://api.mixroute.ai/v1/images/generations" \
--header "Authorization: Bearer $MIXROUTE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-image-plus",
"input": {
"prompt": "A clean product photograph of a red ceramic mug on a white background."
},
"parameters": {
"size": "1024*1024",
"n": 1
}
}'
import json
import os
import requests
payload = json.loads(r'''
{
"model": "qwen-image-plus",
"input": {
"prompt": "A clean product photograph of a red ceramic mug on a white background."
},
"parameters": {
"size": "1024*1024",
"n": 1
}
}
''')
response = requests.post(
"https://api.mixroute.ai/v1/images/generations",
headers={"Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"]},
json=payload,
timeout=180,
)
response.raise_for_status()
result = response.json()
output = result.get("output") or {}
if output.get("task_status") != "SUCCEEDED":
raise RuntimeError(result.get("message") or result)
image_urls = [item["url"] for item in output.get("results", []) if item.get("url")]
if not image_urls:
raise RuntimeError(result.get("message") or result)
for url in image_urls:
print(url)
響應
成功結果的 output.task_status 為 “SUCCEEDED”。從 output.results[].url 讀取臨時圖片地址並及時儲存;usage.image_count 表示實際生成張數。{
"output": {
"task_status": "SUCCEEDED",
"results": [
{
"url": "https://example.com/generated.png"
}
]
},
"usage": {
"image_count": 1
}
}
多模態格式文生圖
qwen-image-2.0、qwen-image-2.0-pro、qwen-image-max 使用一條 user 訊息和一個文本塊。請求採用多模態結構,本頁將這些型號列為純文生圖模型。參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 對應模型表中的完整模型 ID。 |
input | object | 是 | 輸入物件。 |
input.messages | array | 是 | 有且只有一條 user 訊息。 |
input.messages[].role | string | 是 | 固定為 user。 |
input.messages[].content | array | 是 | 文生圖包含一個文本塊。本頁列出的生成模型不傳參考圖。 |
input.messages[].content[].text | string | 按內容塊 | 文本塊中的提示詞。 |
parameters | object | 否 | 可選生成設定。 |
parameters.size | string | 否 | 尺寸採用 寬*高 格式,例如 1024*1024 或 1664*928,使用星號而不是 x。 |
parameters.n | integer | 否 | 單次請求僅支援 1 張;需要多張時分別呼叫。 |
parameters.seed | integer | 否 | 隨機種子。同提示詞和同種子可產生近似結果,不保證完全相同。 |
parameters.watermark | boolean | 否 | 是否新增水印。 |
parameters.negative_prompt | string | 否 | 希望圖片中避免出現的元素。 |
parameters.prompt_extend | boolean | 否 | 是否由上游服務擴展提示詞、補充細節。 |
請求示例
curl --request POST "https://api.mixroute.ai/v1/images/generations" \
--header "Authorization: Bearer $MIXROUTE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "A clean product photograph of a red ceramic mug on a white background."
}
]
}
]
},
"parameters": {
"size": "1024*1024",
"n": 1,
"seed": 42
}
}'
import json
import os
import requests
payload = json.loads(r'''
{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "A clean product photograph of a red ceramic mug on a white background."
}
]
}
]
},
"parameters": {
"size": "1024*1024",
"n": 1,
"seed": 42
}
}
''')
response = requests.post(
"https://api.mixroute.ai/v1/images/generations",
headers={"Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"]},
json=payload,
timeout=180,
)
response.raise_for_status()
result = response.json()
output = result.get("output") or {}
image_urls = [
part["image"]
for choice in output.get("choices", [])
for part in choice.get("message", {}).get("content", [])
if part.get("image")
]
if not image_urls:
raise RuntimeError(result.get("message") or result)
for url in image_urls:
print(url)
響應
從 output.choices[].message.content[].image 讀取圖片 URL。usage.image_count、usage.height、usage.width 描述生成結果,不使用基礎介面的 output.results 路徑解析。{
"output": {
"choices": [
{
"message": {
"role": "assistant",
"content": [
{
"image": "https://example.com/generated.png"
}
]
}
}
]
},
"usage": {
"image_count": 1,
"height": 1024,
"width": 1024
}
}