GPT Image 編輯
curl --request POST \
--url https://api.mixroute.ai/v1/images/editsimport requests
url = "https://api.mixroute.ai/v1/images/edits"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.ai/v1/images/edits', 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/edits",
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/edits"
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/edits")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.ai/v1/images/edits")
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圖像系列
GPT Image 編輯
GPT Image 圖片編輯欄位、模型限制與請求示例。
GPT Image 編輯
curl --request POST \
--url https://api.mixroute.ai/v1/images/editsimport requests
url = "https://api.mixroute.ai/v1/images/edits"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.ai/v1/images/edits', 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/edits",
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/edits"
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/edits")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.ai/v1/images/edits")
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使用 OpenAI Images 編輯請求格式,通過 GPT Image 編輯一張或多張圖片。
GPT Image 2 超過 3686400 總畫素的解析度屬於實驗性範圍。此處 GPT 模型返回 Base64 圖片資料,不傳 DALL-E 專用的
區域性編輯時增加
POST https://api.mixroute.ai/v1/images/edits
支援模型
| 模型 ID | 能力與限制 |
|---|---|
gpt-image-2 | 生成與編輯,支援靈活尺寸,輸入固定高保真。 |
gpt-image-1.5 | 生成與編輯,使用標準圖片尺寸。 |
gpt-image-1 | 生成與編輯,使用標準圖片尺寸。 |
請求參數
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 使用上表完整模型 ID,顯式指定呼叫模型。 |
prompt | string | 是 | 生成或編輯指令,最多 32000 個字元。 |
image | file | file[] | 是 | PNG、JPEG 或 WebP 輸入,單張小於 50 MB,最多 16 張。通過 multipart 表單上傳,多圖可重複使用 image[]。 |
mask | file | 否 | PNG 蒙版,小於 4 MB,畫素尺寸須與第一張源圖一致。完全透明區域表示編輯區域;多圖請求只對第一張圖片應用蒙版。 |
input_fidelity | string | 否 | GPT Image 1 和 1.5 可使用 high 或 low;GPT Image 2 固定以高保真處理輸入,不傳此欄位。 |
n | integer | 否 | 輸出圖片數量,範圍 1-10,預設 1。 |
size | string | 否 | 輸出尺寸,或使用預設值 auto;具體規則見下方版本說明。 |
quality | string | 否 | low、medium、high 或預設值 auto。 |
background | string | 否 | auto(預設)、opaque 或 transparent。透明背景須使用 PNG 或 WebP;GPT Image 2 的透明背景能力處於預覽階段。 |
output_format | string | 否 | 輸出圖片編碼格式:png(預設)、jpeg 或 webp。 |
output_compression | integer | 否 | 壓縮設定,範圍 0-100,預設 100,僅用於 JPEG 或 WebP 輸出。 |
stream | boolean | 否 | true 時以 SSE 返回結果,預設 false。 |
partial_images | integer | 否 | 流式響應中的中間圖片數量,範圍 0-3;為 0 時只返回最終圖片。生成提前完成時,中間圖片可能少於指定數量。 |
user | string | 否 | 用於濫用監測的穩定終端使用者標識,避免直接提供個人資訊。 |
尺寸規則
| 模型 | 允許尺寸 |
|---|---|
| GPT Image 1 / 1.5 | auto, 1024x1024, 1536x1024, 1024x1536 |
| GPT Image 2 | auto 或 寬x高。寬高均為 16 的倍數,單邊不超過 3840 px,長短邊比例不超過 3:1,總畫素數為 655360-8294400。 |
response_format 或 style。
使用 multipart/form-data,不使用 JSON 圖片 URL 物件;由 cURL 或 SDK 設定 multipart boundary。
input_fidelity=auto/medium 和頂層 images JSON 陣列不屬於此 OpenAI 請求格式。呼叫示例
將 MixRoute Key 設定到環境變數MIXROUTE_API_KEY,通過 Authorization: Bearer ... 認證。編輯圖片前,將素材佔位值替換為可訪問的圖片或本地檔案。
curl --request POST "https://api.mixroute.ai/v1/images/edits" \
--header "Authorization: Bearer $MIXROUTE_API_KEY" \
--form "model=gpt-image-2" \
--form "image[]=@source.png" \
--form "prompt=Make the mug blue while preserving its shape, lighting, and background." \
--form "size=1024x1024" \
--form "quality=low" \
--form "output_format=png"
Python
import os
import base64
from pathlib import Path
from openai import OpenAI
client = OpenAI(api_key=os.environ["MIXROUTE_API_KEY"], base_url="https://api.mixroute.ai/v1")
with open("source.png", "rb") as source:
result = client.images.edit(
model="gpt-image-2",
image=source,
prompt="Make the mug blue while preserving its shape, lighting, and background.",
size="1024x1024",
quality="low",
output_format="png",
)
Path("edited.png").write_bytes(base64.b64decode(result.data[0].b64_json))
mask 檔案;多圖參考時增加圖片檔案,蒙版仍只作用於第一張圖。
響應
從data[].b64_json 讀取圖片,並按請求的 output_format 解碼儲存。流式響應返回中間圖片和完成事件,最終檔案應使用完成事件中的資料。
GPT Image 圖片生成