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
通過包含文本塊與圖片塊的單條 user 訊息,使用 Qwen Image 編輯參考圖片。
qwen-image、qwen-image-plus、qwen-image-2.0、qwen-image-2.0-pro、qwen-image-max 的生成請求見 Qwen Image。
POST https://api.mixroute.ai/v1/images/generations
支援模型
| 模型 ID | 輸入 |
|---|---|
qwen-image-edit | 一個文本塊及 1-3 個參考圖片塊。 |
qwen-image-edit-plus | 一個文本塊及 1-3 個參考圖片塊。 |
qwen-image-edit-max | 一個文本塊及 1-3 個參考圖片塊。 |
請求參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 對應模型表中的完整模型 ID。 |
input | object | 是 | 輸入物件。 |
input.messages | array | 是 | 有且只有一條 user 訊息。 |
input.messages[].role | string | 是 | 固定為 user。 |
input.messages[].content | array | 是 | 包含一個文本塊及 1-3 個圖片塊,每個塊只使用 text 或 image,不能同時包含兩者。 |
input.messages[].content[].text | string | 按內容塊 | 文本塊中的提示詞。 |
input.messages[].content[].image | string | 按內容塊 | 參考圖片的公網 HTTPS URL,由上游服務下載;請求包含 1-3 個圖片塊。 |
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 | 否 | 是否由上游服務擴展提示詞、補充細節。 |
text 和 image 必須分別放在不同內容塊中。參考圖使用上游可訪問的公網 HTTPS URL。請求採用 input.messages 而不是 input.prompt;不傳頂層 prompt、multipart 檔案、Base64 data URI 或 metadata 包裝。
請求示例
設定MIXROUTE_API_KEY,並將參考圖佔位值替換為公網 HTTPS 圖片 URL。
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-edit",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "Change the mug to blue while preserving the background."
},
{
"image": "https://example.com/reference.png"
}
]
}
]
},
"parameters": {
"size": "1024*1024",
"n": 1,
"seed": 42
}
}'
Python
import json
import os
import requests
payload = json.loads(r'''
{
"model": "qwen-image-edit",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "Change the mug to blue while preserving the background."
},
{
"image": "https://example.com/reference.png"
}
]
}
]
},
"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
}
}