curl --request POST \
--url https://api.apiyi.com/v1/images/edits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form model=gpt-image-2-all \
--form 'prompt=Put the person from image1 into the scene of image2, using the art style of image3' \
--form 'image=<string>' \
--form image.items='@example-file'import requests
url = "https://api.apiyi.com/v1/images/edits"
files = { "image.items": ("example-file", open("example-file", "rb")) }
payload = {
"model": "gpt-image-2-all",
"prompt": "Put the person from image1 into the scene of image2, using the art style of image3",
"image": "<string>"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('model', 'gpt-image-2-all');
form.append('prompt', 'Put the person from image1 into the scene of image2, using the art style of image3');
form.append('image', '<string>');
form.append('image.items', '{
"fileName": "example-file"
}');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.apiyi.com/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.apiyi.com/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",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/edits"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.apiyi.com/v1/images/edits")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"data": [
{
"b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"created": 1778037127,
"usage": {
"input_tokens": 98,
"output_tokens": 1185,
"total_tokens": 1283
}
}画像編集 API リファレンス
gpt-image-2-all の画像編集 API リファレンスとインタラクティブなプレイグラウンド — 参照画像をアップロードし、単一画像編集または複数画像の融合のための指示を指定できます
curl --request POST \
--url https://api.apiyi.com/v1/images/edits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form model=gpt-image-2-all \
--form 'prompt=Put the person from image1 into the scene of image2, using the art style of image3' \
--form 'image=<string>' \
--form image.items='@example-file'import requests
url = "https://api.apiyi.com/v1/images/edits"
files = { "image.items": ("example-file", open("example-file", "rb")) }
payload = {
"model": "gpt-image-2-all",
"prompt": "Put the person from image1 into the scene of image2, using the art style of image3",
"image": "<string>"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('model', 'gpt-image-2-all');
form.append('prompt', 'Put the person from image1 into the scene of image2, using the art style of image3');
form.append('image', '<string>');
form.append('image.items', '{
"fileName": "example-file"
}');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.apiyi.com/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.apiyi.com/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",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/edits"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.apiyi.com/v1/images/edits")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model\"\r\n\r\ngpt-image-2-all\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nPut the person from image1 into the scene of image2, using the art style of image3\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image.items\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"data": [
{
"b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"created": 1778037127,
"usage": {
"input_tokens": 98,
"output_tokens": 1185,
"total_tokens": 1283
}
}Bearer sk-xxx)、画像を選択して、prompt と model を入力し、送信をクリックしてください。multipart/form-data を使用します。純粋なテキストから画像生成を行う場合は、テキストから画像生成エンドポイント を使用してください。response_format: "b64_json" になるため、応答には数 MB の base64 文字列が含まれ、ブラウザーのプレイグラウンドでは 请求时发生错误: unable to complete request と表示される場合があります — リクエスト自体は実際には成功しています。ブラウザーがそのように長い base64 文字列を描画できないだけです。推奨ワークフロー:- プレイグラウンドで画像を見られれば十分ですか?
"response_format": "url"を明示的に指定してください — 応答は単一の R2 リンクになり、問題なく表示されます。 - base64 が必要、または大きな参照画像をアップロードしたいですか? 下のコードサンプルをコピーしてローカルで実行してください — コードがアップロードとデコードを自動で処理します。
image フィールドは繰り返し指定でき、複数の参照画像をアップロードできます。順序によって、prompt 内の「image1/image2/image3」がどの画像として解釈されるかが決まります。 そのため、次のように明示的に参照することを推奨します。image1 の人物を image2 のシーンに配置し、image3 の画風を適用する推奨は画像 1 枚あたり ≤ 10MB、形式は
png / jpg / webp です。画像が大きすぎるとゲートウェイの制限に達する場合があります。size フィールドはこのモデルでは効果がありません(どの値を送っても黙って無視されます。サイズを厳密に固定したい場合は、gpt-image-2-vip を使用してください)。prompt が対象を指定しない場合は、モデルが自動で判断します。コード例
Python
単一画像の編集:import requests
API_KEY = "sk-your-api-key"
with open("photo.png", "rb") as f:
response = requests.post(
"https://api.apiyi.com/v1/images/edits",
headers={"Authorization": f"Bearer {API_KEY}"},
data={
"model": "gpt-image-2-all",
"prompt": "Change the background to a seaside sunset",
"response_format": "url"
},
files=[
("image", ("photo.png", f, "image/png"))
],
timeout=300 # conservative — absorbs tail latency + image upload/download time
).json()
print(response["data"][0]["url"])
import requests
with open("ref1.png", "rb") as f1, \
open("ref2.png", "rb") as f2, \
open("ref3.png", "rb") as f3:
response = requests.post(
"https://api.apiyi.com/v1/images/edits",
headers={"Authorization": "Bearer sk-your-api-key"},
data={
"model": "gpt-image-2-all",
"prompt": "Put the person from image1 into the scene of image2, using the art style of image3",
"response_format": "b64_json"
},
files=[
("image", ("ref1.png", f1, "image/png")),
("image", ("ref2.png", f2, "image/png")),
("image", ("ref3.png", f3, "image/png"))
],
timeout=300 # conservative — absorbs tail latency + image upload/download time
).json()
# Verified July 2026: b64_json is raw base64 (no data: prefix); earlier versions
# included the prefix, so a defensive check is safest
import base64
b64 = response["data"][0]["b64_json"]
if b64.startswith("data:"):
b64 = b64.split(",", 1)[1]
with open("edited.png", "wb") as f:
f.write(base64.b64decode(b64))
cURL
単一画像の編集:curl -X POST "https://api.apiyi.com/v1/images/edits" \
-H "Authorization: Bearer sk-your-api-key" \
-F "model=gpt-image-2-all" \
-F "prompt=Change the background to a seaside sunset" \
-F "response_format=url" \
-F "image=@./photo.png"
curl -X POST "https://api.apiyi.com/v1/images/edits" \
-H "Authorization: Bearer sk-your-api-key" \
-F "model=gpt-image-2-all" \
-F "prompt=Put the person from image1 into the scene of image2, using the art style of image3" \
-F "response_format=b64_json" \
-F "image=@./ref1.png" \
-F "image=@./ref2.png" \
-F "image=@./ref3.png"
Node.js(ネイティブ fetch + FormData)
import fs from 'node:fs';
const form = new FormData();
form.append('model', 'gpt-image-2-all');
form.append('prompt', 'Change the background to outer space');
form.append('response_format', 'url');
form.append(
'image',
new Blob([fs.readFileSync('./photo.png')]),
'photo.png'
);
const resp = await fetch('https://api.apiyi.com/v1/images/edits', {
method: 'POST',
headers: { 'Authorization': 'Bearer sk-your-api-key' },
body: form
});
const data = await resp.json();
console.log(data.data[0].url);
ブラウザ JavaScript(File オブジェクト)
// <input type="file" id="fileInput" multiple>
const files = document.getElementById('fileInput').files;
const form = new FormData();
form.append('model', 'gpt-image-2-all');
form.append('prompt', 'Fuse these images into one poster');
form.append('response_format', 'url');
for (const f of files) form.append('image', f);
const resp = await fetch('https://api.apiyi.com/v1/images/edits', {
method: 'POST',
headers: { 'Authorization': 'Bearer sk-your-api-key' },
body: form
});
const { data } = await resp.json();
document.getElementById('result').src = data[0].url;
パラメータ早見表
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
model | テキスト | はい | 固定: gpt-image-2-all |
prompt | テキスト | はい | 自然言語による編集/融合指示 |
image | ファイル | はい | 参照画像; 複数回指定可 |
size | テキスト | いいえ | このフィールドは効果がなく、任意の値を送信しても静かに無視されます。 出力アスペクト比は、プロンプトが編集対象として指定した参照画像に従います(マルチ画像のシナリオでは、必ずしも最初の1枚とは限りません)。厳密なサイズ固定には、gpt-image-2-vip を使用してください |
response_format | テキスト | いいえ | b64_json(デフォルト)またはurl |
image 入力として新しい指示とともに再投入し、結果を反復的に洗練します。レスポンス形式
text-to-image エンドポイントと同様に、data[0] は url または b64_json のどちらかを返し、両方は返しません(response_format に依存します)。このエンドポイントは 既定で b64_json です。
b64_json モード(既定):
{
"data": [
{
"b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"created": 1778037127,
"usage": {
"input_tokens": 98,
"output_tokens": 1185,
"total_tokens": 1283
}
}
url モード(明示的な "response_format": "url" が必要です):
{
"data": [
{
"url": "https://r2cdn.copilotbase.com/r2cdn2/0e82148a-bec0-4b42-bbca-117c6b42581b.png"
}
],
"created": 1778037331,
"usage": {
"input_tokens": 30,
"output_tokens": 2074,
"total_tokens": 2104
}
}
b64_json フィールドは data: プレフィックスのない raw base64 です。レンダリング前にデコードするか、自分でプレフィックスを付けてください。以前のバージョンではプレフィックスが含まれていました ので、両方の形に対応するには最初に startsWith('data:') を必ず確認してください。承認
API Key from the API易 Console
ボディ
Model name, fixed to gpt-image-2-all
gpt-image-2-all Edit/fusion instruction. For multi-image fusion, reference upload order as image1/image2/image3
"Put the person from image1 into the scene of image2, using the art style of image3"
Reference images. For a single image, send the field once; for multiple images, repeat the same image field (e.g., -F [email protected] -F [email protected]) — upload order maps to image1 / image2 / ... in the prompt. Recommended ≤ 10MB each, formats png / jpg / webp.
Response format. b64_json returns a base64 string already prefixed with a data URL header (default); url returns an R2 CDN link
b64_json, url レスポンス
Image successfully generated. Defaults to base64 in data[0].b64_json — url is not returned in the same response.
Image editing response. data[0] returns either url or b64_json, never both (depends on response_format; this endpoint defaults to b64_json).
このページは役に立ちましたか?