Skip to main content
POST
POST /v1/images/edits image-to-image endpoint는 multipart/form-data request body를 사용합니다. 하나 이상의 reference images를 업로드하고 prompt 및 parameter fields를 form fields로 제출하세요.
https://bettertoken.ai/v1을 Base URL로 사용하세요. Authorization: Bearer YOUR_API_KEY를 통해 BetterToken API Key를 전달하세요.
페이지 오른쪽의 Playground에서 form fields를 입력하고 reference images를 업로드한 다음 https://bettertoken.ai/v1/images/edits로 request를 직접 보낼 수 있습니다.
image-to-image requests에 일반 JSON body를 사용하지 마세요. text fields와 file fields는 multipart/form-data로 제출하세요.

권장 값

모든 request에서 다음 fields를 명시적으로 보내세요.
단일 reference image에는 image를 사용하세요. 여러 reference images에는 반복된 image[] fields를 사용하세요.

단일 reference image

여러 reference images

mask로 선택 영역 편집

선택한 영역을 중심으로 편집하려면 선택 사항인 mask 파일 필드를 추가하세요. 현재 BetterToken endpoint는 하나의 mask 파일만 읽습니다. mask[] 필드를 여러 번 보내지 마세요.
  • 원본 이미지와 mask는 파일 형식과 픽셀 크기가 같아야 합니다. 각 파일은 50 MB보다 작아야 합니다. 최대 호환성을 위해 두 파일 모두 Alpha channel이 있는 PNG를 사용하세요.
  • Mask에는 Alpha channel이 있어야 합니다. 완전히 투명한 픽셀(Alpha 0)은 모델이 다시 그릴 수 있는 영역을 표시합니다. 완전히 불투명한 픽셀(Alpha 255)은 해당 영역을 유지하도록 모델을 유도합니다.
  • 일반 RGB 흑백 이미지는 실제 Alpha channel을 포함하지 않으면 유효한 mask가 아닙니다.
  • 여러 image[] 필드를 보내면 mask는 첫 번째 입력 이미지에 적용됩니다.
  • Mask는 모델을 안내하지만, 투명 영역 밖의 픽셀이 완전히 동일하게 유지된다고 보장하지는 않습니다.

Python masked edit

요청 후 Python이 두 파일을 닫도록 하나의 with 문에서 파일을 여세요.

upload 전 파일 확인

이 최소 Pillow 검사는 필수 형식, 크기, Alpha channel을 확인합니다. 일반적인 local mask의 경우 Alpha channel에 완전히 투명한 영역과 완전히 불투명한 영역이 모두 없으면 경고도 표시합니다.

Python 예시

권장 sizes

size는 예상 aspect ratio와 size tier를 나타냅니다. 실제 반환 pixels는 server에 의해 mapping 또는 adjusted될 수 있습니다. output을 요청한 값으로 강제로 crop하지 말고 decoded image dimensions를 사용하세요.

이미지 저장

성공한 response는 다음 OpenAI-compatible image response shape를 따릅니다.
data[0].b64_json을 읽어 base64 image content로 저장하세요. 항상 output_format: "png"를 설정하면 decoded image를 .png로 저장할 수 있습니다.

Response flow

이 endpoint는 synchronous입니다. POST /images/edits를 보낸 후 server가 response할 때까지 현재 HTTP request를 열어 두세요. generation에 성공하면 image content가 data[0].b64_json으로 반환됩니다. endpoint는 task_id를 반환하지 않으며 별도의 status query 또는 result download 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[]