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テキストと画像ブロックを含む1つのユーザーメッセージを使用して、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つと参照画像ブロック1〜3つ。 |
qwen-image-edit-plus | テキストブロック1つと参照画像ブロック1〜3つ。 |
qwen-image-edit-max | テキストブロック1つと参照画像ブロック1〜3つ。 |
リクエストパラメーター
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | はい | 該当するモデル表に記載された完全なモデルID。 |
input | object | はい | 入力オブジェクト。 |
input.messages | array | はい | ユーザーメッセージは必ず1つです。 |
input.messages[].role | string | はい | userである必要があります。 |
input.messages[].content | array | はい | テキストブロック1つと画像ブロック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のように、width*height形式で記述した寸法。xではなくアスタリスクを使用してください。 |
parameters.n | integer | いいえ | 1回のリクエストでサポートされるのは1のみです。複数の画像には、個別のリクエストを送信してください。 |
parameters.seed | integer | いいえ | 乱数シード。同じプロンプトとシードを再利用すると似た結果が得られる場合がありますが、同一の出力を保証するものではありません。 |
parameters.watermark | boolean | いいえ | ウォーターマークを追加するかどうか。 |
parameters.negative_prompt | string | いいえ | 生成画像で避ける要素。 |
parameters.prompt_extend | boolean | いいえ | 上流サービスにプロンプトの詳細を補足させるかどうか。 |
テキストと画像は別々のcontentブロックに配置してください。参照画像には、上流サービスからアクセスできる公開HTTPS URLを使用する必要があります。input.promptではなくinput.messagesを使用してください。トップレベルのprompt、multipartファイル、Base64データ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)
レスポンス
画像URLはoutput.choices[].message.content[].imageから取得します。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
}
}