GPT Image 2 API로 이미지 생성 및 편집
GPT Image 2는 별도 image route를 사용하지만 GPT text 모델과 같은 apiToken.sale 키와 잔액을 공유합니다. prompt로 생성하거나 PNG, JPEG, WebP reference 최대 5개(각 50 MB 이하)로 편집할 수 있습니다.
·
생성 route 호출
GPT Image 2 is an image model you call over the OpenAI-compatible surface: send a prompt to /v1/images/generations with model gpt-image-2 and an Authorization: Bearer header, and you get back one PNG. No separate image plan, no second key — the same sk-pool credential and prepaid balance that cover GPT, Claude and Gemini calls settle image usage too.
공식 GPT Image 필드는 이 풀에 맞춰 변환됩니다. user, stream, moderation, style 같은 추가 키는 400이 아니라 무시됩니다. quality medium/high/auto도 풀의 low 티어로 생성됩니다. output_format jpeg 또는 webp는 네이티브 PNG를 로컬에서 트랜스코드합니다. response_format=url은 무시되고 본문은 항상 b64_json입니다. n은 1–10일 수 있으며 추가 이미지는 같은 홈에서 순차 네이티브 턴입니다. background=auto는 opaque입니다. transparent는 컷아웃 문장을 붙입니다. size는 픽셀 잠금이 아니라 비율입니다. 2048x2048과 3840x2160은 1:1과 16:9로 매핑되며 PNG는 약 1.57메가픽셀로 남고 응답 size는 실제 IHDR입니다. 편집은 같은 모델과 PNG, JPEG 또는 WebP 최대 5개(각 50 MB 이하)를 multipart/form-data로 /v1/images/edits에 보냅니다. image 또는 image[]를 쓰세요. mask는 무시됩니다.
| size | Proportion | Steer target (inspect the PNG) |
|---|---|---|
| omitted or auto | no size steer | typically ~1254×1254; not a lock |
| 1024x1024, 1:1, 2048x2048 | 1:1 | 1254×1254 |
| 1536x1024 or 3:2 | 3:2 landscape | 1536×1024 |
| 1024x1536 or 2:3 | 2:3 portrait | 1024×1536 |
| 4:3 | 4:3 | 1448×1086 |
| 16:9, 2048x1152, 3840x2160 | 16:9 | 1672×941 |
| 9:16, 2160x3840 | 9:16 | 944×1665 |
영역 inpaint와 Responses image_generation
/v1/images/edits의 mask 필드는 지원하지 않습니다. 일부만 바꾸거나 GPT 텍스트 모델에서 hosted image_generation 도구를 쓰려면 POST /v1/responses를 호출하세요(Chat Completions는 같은 hosted 도구를 Responses로 매핑). 편집 시 원본 PNG는 input_image, tools: [{type:"image_generation", …}]. 마스크는 input_image_mask.image_url(PNG data URL). 투명 픽셀이 수정 영역입니다. file_id는 Files API가 없어 실패합니다.
import base64, os
from pathlib import Path
from openai import OpenAI
client = OpenAI(
api_key=os.environ["APITOKEN_API_KEY"],
base_url="https://router.apitoken.sale/v1",
)
def png_url(path):
return "data:image/png;base64," + base64.b64encode(Path(path).read_bytes()).decode()
response = client.responses.create(
model="gpt-5.6-sol",
input=[{
"role": "user",
"content": [
{"type": "input_text", "text": "Change only the masked region."},
{"type": "input_image", "image_url": png_url("photo.png")},
],
}],
tools=[{
"type": "image_generation",
"output_format": "webp",
"partial_images": 2,
"input_image_mask": {"image_url": png_url("mask.png")},
}],
)- gpt-image-2가 아니라 GPT 텍스트 모델(예: gpt-5.6-sol)을 /v1/responses 또는 /v1/chat/completions에 보냅니다.
- Responses image_generation은 output_format jpeg|webp와 partial_images 1..=3을 전달합니다. SSE는 response.image_generation_call.partial_image를 보냅니다.
- background=transparent는 opaque로 바뀌고 input_fidelity는 제거됩니다. /v1/images/*는 여전히 PNG만 출력하며 partial을 스트리밍하지 않습니다.
이미지 요금 계산
| Leg | 공식 100만 token당 | 여기서의 가격 |
|---|---|---|
| Text input | $5 | $2.50 |
| Image input | $8 | $4 |
| Image output | $30 | $15 |
- cached text와 image input은 일반 input 가격의 25%입니다.
- gpt-image-2는 immutable snapshot gpt-image-2-2026-04-21의 alias입니다.
- image usage는 GPT, Claude, Gemini 호출과 같은 선불 잔액에서 결제됩니다.
자주 묻는 질문
GPT Image 2는 어떤 endpoint를 사용하나요?
새 이미지는 POST /v1/images/generations, reference 편집은 POST /v1/images/edits를 사용합니다.
기존 이미지를 편집할 수 있나요?
네. edits route가 multipart/form-data로 PNG, JPEG, WebP 최대 5개(각 50 MB 이하)를 받습니다. 필드 이름은 image를 반복하거나 image[]를 보내세요. multipart mask는 무시됩니다. 영역 인페인트는 Responses input_image_mask입니다.
이미지 일부만 어떻게 고치나요?
POST /v1/responses에 GPT 텍스트 모델, input_image 원본 PNG, tools: [{type:"image_generation", input_image_mask:{image_url}}]를 보냅니다. output_format jpeg|webp와 partial_images 1..=3도 설정할 수 있습니다. file_id와 Images mask는 사용하지 마세요. Chat Completions는 같은 image_generation을 Responses로 매핑합니다.
이미지 크기를 지정할 수 있나요?
비율만 지정합니다. 생략 또는 auto는 보통 약 1254×1254이지만 잠금이 아닙니다. 1024x1024/1:1, 1536x1024/3:2, 1024x1536/2:3, 4:3·16:9·9:16은 1254×1254·1536×1024·1024×1536·1448×1086·1672×941·944×1665를 목표로 합니다. PNG 헤더가 달라도 HTTP 200입니다. 2K/4K는 거부됩니다.
별도 image 키나 잔액이 필요한가요?
아니요. 다른 지원 모델과 같은 Bearer 키와 선불 잔액을 사용합니다.