Skip to main content
POST
POST /v1/images/edits 画像から画像への変換 Endpoint では multipart/form-data のリクエスト本文を使用します。1 枚以上の参照画像をアップロードし、プロンプトとパラメーターフィールドをフォームフィールドとして送信します。
https://bettertoken.ai/v1 を Base URL として使用します。BetterToken API Key は Authorization: Bearer YOUR_API_KEY で渡します。
ページ右側の Playground でフォームフィールドを入力し、参照画像をアップロードしてから、https://bettertoken.ai/v1/images/edits に直接リクエストを送信できます。
画像から画像への変換リクエストには通常の JSON 本文を使用しないでください。テキストフィールドとファイルフィールドは multipart/form-data で送信します。

推奨値

すべてのリクエストで、次のフィールドを明示的に送信してください。
参照画像が 1 枚の場合は image を使用します。複数の参照画像には image[] フィールドを繰り返し使用します。

1 枚の参照画像

複数の参照画像

マスクで選択範囲を編集する

選択した範囲の編集を指示するには、任意の mask ファイルフィールドを追加します。現在の BetterToken エンドポイントが読み込む mask ファイルは 1 つです。mask[] フィールドを複数送信しないでください。
  • 元画像とマスクは、ファイル形式とピクセル寸法を同じにする必要があります。各ファイルは 50 MB 未満にしてください。最大限の互換性を得るには、両方のファイルに Alpha チャンネル付き PNG を使用することを推奨します。
  • マスクには Alpha チャンネルが必要です。完全に透明なピクセル(Alpha 0)は、モデルが再描画できる範囲を示します。完全に不透明なピクセル(Alpha 255)は、その範囲を保持するようモデルを誘導します。
  • 通常の RGB 白黒画像は、実際に Alpha チャンネルを含んでいない限り、有効なマスクではありません。
  • 複数の image[] フィールドを送信した場合、マスクは最初の入力画像に適用されます。
  • マスクはモデルへの指示です。透明な範囲の外側にあるピクセルが完全に同一のままになることを保証するものではありません。

Python でマスク編集する

リクエスト後に Python が両方のファイルを閉じるよう、1 つの with 文で開きます。

アップロード前にファイルを確認する

この最小限の Pillow チェックで、必須の形式、寸法、Alpha チャンネルを確認できます。一般的な局所マスクについては、Alpha チャンネルに完全に透明な領域と完全に不透明な領域の両方がない場合に警告も表示します。

Python の例

推奨サイズ

size は想定するアスペクト比とサイズ区分を表します。実際に返されるピクセルはサーバーでマッピングまたは調整される場合があります。出力を要求値に無理に切り抜くのではなく、デコードした画像の寸法を使用してください。

画像を保存する

成功時のレスポンスは、次の OpenAI 互換画像レスポンス形式に従います。
data[0].b64_json を読み取り、base64 の画像内容として保存します。常に output_format: "png" を設定すると、デコードした画像を .png として保存できます。

レスポンスの流れ

この Endpoint は同期式です。POST /images/edits を送信した後、サーバーが応答するまで現在の HTTP リクエストを開いたままにしてください。生成に成功すると、画像内容が data[0].b64_json に返されます。 この Endpoint は task_id を返さず、個別のステータス照会や結果ダウンロード用の Endpoint もありません。

関連ドキュメント

承認

Authorization
string
header
必須

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

ボディ

multipart/form-data
model
enum<string>
デフォルト:gpt-image-2
必須

Use the GPT Image 2 model ID.

利用可能なオプション:
gpt-image-2
例:

"gpt-image-2"

prompt
string
必須

Instructions for editing the image or generating from reference images.

例:

"Use this reference image to create a more polished square product hero image while preserving the main style."

image
file

The reference image field for a single input image.

image[]
file[]

Repeat this field for each input when sending multiple reference images.

mask
file

An optional single mask file. The mask and original image must have the same format and dimensions, each file must be smaller than 50 MB, and the mask must contain an Alpha channel. For maximum compatibility, use PNG with an Alpha channel for both files. With multiple image[] inputs, the mask applies to the first image.

n
デフォルト:1

Use 1. Send separate requests when you need multiple output images.

例:

"1"

size
enum<string>
デフォルト:1024x1024

The requested image size or aspect-ratio tier. The server may map or adjust the final pixel dimensions, so inspect the decoded image for its actual size.

利用可能なオプション:
auto,
1024x1024,
1536x1024,
1024x1536,
1536x1152,
1152x1536,
2048x2048,
2048x1152,
3840x2160,
2160x3840
例:

"1024x1024"

response_format
enum<string>
デフォルト:b64_json

Use b64_json.

利用可能なオプション:
b64_json
例:

"b64_json"

output_format
enum<string>
デフォルト:png

Use png. Do not rely on jpeg or webp being returned directly in the selected format.

利用可能なオプション:
png
例:

"png"

レスポンス

Image editing result.

created
integer
例:

1710000000

data
object[]