이미지 변환(이미지 편집)
BetterToken의 OpenAI-compatible API를 통해 GPT Image 2로 reference images에서 이미지를 생성하거나 편집하세요.
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를 전달하세요.권장 값
모든 request에서 다음 fields를 명시적으로 보내세요.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가 없습니다.
관련 문서
인증
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
본문
Use the GPT Image 2 model ID.
gpt-image-2 "gpt-image-2"
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."
The reference image field for a single input image.
Repeat this field for each input when sending multiple reference images.
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.
Use 1. Send separate requests when you need multiple output images.
"1"
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"
Use b64_json.
b64_json "b64_json"
Use png. Do not rely on jpeg or webp being returned directly in the selected format.
png "png"

